A remote control for our mood lantern

The lantern stands with me at home in a corner which is not to be reached so easily with the hand. Draw every time the net part plug or a counter operate around the lantern or to switch off, hence, I find a little bit laboriously. Nevertheless, this must also go differently! And, yes, it also goes differently, namely, faithful to the television model, with an Infrared remote control. Before we we, nevertheless, comfortably in the couch start can be able and switch off our little lantern with the remote control and, we must meet, as usual, some changes and preparations. The most important one what we need first, the remote control itself is first. I have decided on my televisions remote control which has a few more unused keys which I would like to use in addition. In addition, however, later more. The next what we need Hardware-sided, this is KY-022 Ir receiver module. from our FILE NUMBER Delivery shop. We need this, so that our Nano the Infrared signals conceive and can evaluate. We wire our new module as follows:

Fritzing switch plan - with IR receiver

How is to be recognised, the signals of the IR Receivers are escorted in Pin 11 of the Nanos and are evaluated by the Arduino. So that the Arduino can evaluate the infrared signals we need for our code the library IRRemote we must download and instal before in the IDE. After the installation of the library we load the following code high:

 

#include <Adafruit_NeoPixel.H>
#include <IRremote.H>

#define PIN        6  //Which pin on the Arduino is connected to the neopixel?
#define RECV_PIN 11  //define IR input pin on Arduino 
#define NUMPIXELS 12 //How many of neopixel ares attached to the Arduino?//Popularly neopixel struggle size

Adafruit_NeoPixel of pixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
IRrecv irrecv(RECV_PIN);
decode_results results; //decode_results class is defined in IRremote.h

long FirelastTime = 0;
long IRlastTime = 0;
long TimerlastTime = 0;
int interval;
long IRCode = 0;
long OLDIRCode = 0;
bool FireON = false;
bool FireOFF = false;
byte FireSequence = 0;

void set-up()
{   Serial.begin(115200);   while (!Serial);   //wait until Serial is established - required on some Platforms   irrecv.enableIRIn(); //Start the receiver   of pixel.begin(); //Of neopixel INITIALIZE   of pixel.show(); //Initialize of all pixel to 'out of vision'   interval = 400;   randomSeed(analogRead(0));
}

void SimulateFire (bool On, int FireSq)
{   if (millis() - FirelastTime >= interval)   {     if (On)     {       FireOFF = false;       FirelastTime = millis();       byte LightValue[NUMPIXELS * 3];       byte FireColor = 60;       interval = random(150, 200);       FireColor = 60; //random (0,50);       for (int i = 0; i < NUMPIXELS; i++)       { //For each pixel...         LightValue[i * 3] = random(240, 255); // 250         LightValue[i * 3 + 1] = random(30, 60); // 50         LightValue[i * 3 + 2] = 0;       }       //Switch some lights darker       byte LightsOff  = random(0, 4);       for (int i = 0; i < LightsOff; i++)       {         byte Selected = random(NUMPIXELS);         LightValue[Selected * 3] = random(50, 60);         LightValue[Selected * 3 + 1] = random(5, 10);         LightValue[Selected * 3 + 2] = 0;       }       for (int i = 0; i < NUMPIXELS; i++)       { //For each pixel...         of pixel.setPixelColor(i, LightValue[i * 3], LightValue[i * 3 + 1], LightValue[i * 3 + 2]);       }       noInterrupts();       of pixel.show();   //Send the updated pixel colours to the hardware.       irrecv.resume();       interrupts();     }     else     {       if (!(FireOFF))       {         of pixel.clear();         noInterrupts();         of pixel.show();   //Send the updated pixel colours to the hardware.         irrecv.resume();         interrupts();         FireOFF = true;       }     }   }
}

long ReceiveIrCommand ()
{   long result = 0;   if (millis() - IRlastTime >= 200)   {     IRlastTime = millis();     if (irrecv.decode(&results))     {       result = results.value;       irrecv.resume(); //Receive the next value       return result;     }     //irrecv.resume ();//Receive the next value   }   return 0 ;
}

void IRCommandProcessor (long IrCommand)
{   if (IRCode == OLDIRCode) {     TimerlastTime = millis(); //Some stuff about debouncing IR Remote   }   if (millis() - TimerlastTime >= 400) {     OLDIRCode = 0 ; //Some stuff about debouncing IR Remote   }   if ((IRCode < -1) & (IRCode != OLDIRCode))   //IR signal Received   {     OLDIRCode = IRCode;                                           //Some stuff about debouncing IR Remote     switch (IRCode)     {       case -522164073:        //In micron case a blue Switch on micron of TV - Remote         {           FireON = !FireON;         }         break;       default:         Serial.println(IRCode);         break;     }   }
}

void loop()
{   IRCode = ReceiveIrCommand();   IRCommandProcessor(IRCode);   SimulateFire(FireON, FireSequence);
}

Before we can integrate now, however, our own remote control, we must open before first of all the terminal window with an interface speed of 115200 Baud. Now we hold our elective remote control before the sensor and press a few keys. An issue should be to be seen about as follows:

Issue terminal window: long figures with negative portent

The negative long figures with every keystroke on the remote control are indicated, correspond to the Infrared code, the respective key on the remote control. For example, the number-522145713 corresponds to the key "1" on the remote control. If we want to use the key "1" to one and switching off our lantern, we must put down this "numeric code" in our Arduino code. We do this at the following place in the code:

switch (IRCode)
{
case-522145713://Here own ascertained IR numeric code for
//put down the function / from
{
FireON =! FireON;
}

From now on the code is not indicated with activity of the well-chosen remote control key any more in the serial monitor, however, with receipt the lantern one or is switched off.
The inclined reader will probably have already recognised which about the "switch-case" structure not only remote control codes to the turning on and switch offed of the lantern let themselves use, but with it any enlargements of the functions allow to realise. In the next part of the row we look exactly this and extend the functions of our lantern by different fire simulation types. I am soon already glad you to be able to make available the next part and wishes you a lot of fun while copying. Questions are pretty welcome of course, as usual.

 

 

For arduinoProjects for advanced

8 comments

Randolf

Randolf

Ich habe das gleich Problem , jedesmal wenn ich eine Taste drücke kommt ein anderer Code raus.
Schaltung funktioniert aber eben nur wenn man die Taste mehrfach drückt kommt das Programm welches dahinter steht .
sieht so aus im Monitor , immer die gleiche Taste gedrückt .
3:53:14.848 → -1821391323
23:53:14.915 → -1
23:53:15.418 → -1
23:53:16.627 → -1
23:53:18.351 → 280931138
23:53:18.385 → -1
23:53:19.457 → -1124551177
23:53:20.157 → -781353116
23:53:20.192 → -1
23:53:20.937 → 1744117259
23:53:21.003 → -1

Dirk, der olle brummbaer

Dirk, der olle brummbaer

Moin Tobias!
Der Tip mit der geänderten Codezeile war Klasse; jetzt funzen alle in meiner Reichweite befindlichen Fernbedienungen… :D
Leider habe ich noch ein anderes Problem: obwohl die Schaltung wie gezeichnet aufgebaut wurde, bekomme ich bei mehreren Impulsen (aus der mechanisch identischen Position) entweder gar keine oder unterschiedliche Werte zurück gemeldet. Somit ist das Ein- und Ausschalten des Ringes ein reines Glücksspiel (ausprobiert habe ich es mit drei verschiedenen Folientastaturen und der von meinem Fernseher – identische Ergebnisse).

Langer Rede kurzer Sinn: Hiiiiiilfe!!

Lass’ mal von Dir lesen.

Dirk

Tobias Kuch

Tobias Kuch

Hallo Mirko,
Probiere mal bitte folgende Code Änderung aus :

if ((IRCode != 0) & (IRCode != OLDIRCode))

Damit sollten jetzt beide Fernbedienungsarten funktionieren.

Mirko Voigtländer

Mirko Voigtländer

Der verwendete Code “(IRCode < -1)” verhindert die Benutzung der Folienfernbedienungen, die in vielen Lern- und Experimentierbausätzen mit geliefert werden.
Ich habe den Code wie folgt abgeändert “(IRCode > 0)”.
Jetzt funktionieren allerdings alle anderen Fernbedienungen nicht mehr.

Markus Neumann

Markus Neumann

Hallo Bert,

das gezeigte Netzteil trägt die Bezeichnung “MB102”. Im Shop ist es zu finden unter: https://www.az-delivery.de/products/mb102-breadboard

Viele Grüße und ein schönes Wochenende!
Markus

Bert

Bert

Unter welcher Bestellnummer ist das 5 v Netzteil erhältlich ?
=> https://cdn.shopify.com/s/files/1/1509/1638/files/Teil2-Fritzing_grande.jpg?v=1566908403

Georg

Georg

Hallo Hr Frey, das ich auch ein Einsteiger bin und mit Programmieren nichts zu tun gehabt habe bin gezwungen solchen Beispielen folgen. Schritt für Schritt habe alles aufgebaut, kopiert und doch ist mir irgendwo ein Fehler unterlaufen denn ich nicht finden kann. Zu Zeit bin in der Lage denn WS2812b Ring mit Hilfe einer Fernbedienung einschalten aber das ausschalten will nicht funktionieren. Über Ratschläge möchte ich mich sehr freuen.
Es grüßt, Georg

Stefan Frey

Stefan Frey

Schönes, einfaches, aber effektvolles Projekt für Einsteiger, gut erklärt.

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN