Arduino IR Remote to Control LEDs ON and OFF

I made this Arduino project that allows to turn ON and OFF LEDs using a cheap IR remote control as a preparation for the next big step: disassemble my girlfriend’s chinese LED lamp and replace its board with and Atmega Tiny microcontroller, probably ATTiny24A and change the stupid remote control with another one.

The project is pretty simple, you don’t need a lot of components. In my case I have used only 3 x 330Ω resistors, 3 leds and a TSOP4838 IR receiver module. You must check the datasheet before use the IR module to see which pins connect to the power supply and which one delivers the output voltage.

I used an available IR Arduino library so it was pretty easy to decode the signals transmitted by the infrared remote. You can download the version that I’ve used using the link below but I advice you to go to the official page and download any updated version. To install, unzip the archive, move the downloaded IRremote directory to: arduino-1.x/libraries/IRremote where arduino-1.x is your Arduino installation directory.

Video presentation of the working project

Arduino IR Remote Control Schematic

Arduino led ir remote schematic

Arduino Sketch

You'll need to change the led pins and the codes 
accordingly to your configuration and IR remote

#include <IRremote.h>

int RECV_PIN = 3; // the pin where you connect the output pin of TSOP4838
int led1 = 2;
int led2 = 4;
int led3 = 7;
int itsONled[] = {0,0,0,0};
/* the initial state of LEDs is OFF (zero) 
the first zero must remain zero but you can 
change the others to 1's if you want a certain
led to light when the board is powered */
#define code1  63495 // code received from button A
#define code2  30855 // code received from button B
#define code3  22695 // code received from button C

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
  Serial.begin(9600);   // you can comment this line
  irrecv.enableIRIn();  // Start the receiver
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);

void loop() {
  if (irrecv.decode(&results)) {
    unsigned int value = results.value;
    switch(value) {
       case code1:
         if(itsONled[1] == 1) {        // if first led is on then
            digitalWrite(led1, LOW);   // turn it off when button is pressed
            itsONled[1] = 0;           // and set its state as off
         } else {                      // else if first led is off
             digitalWrite(led1, HIGH); // turn it on when the button is pressed
             itsONled[1] = 1;          // and set its state as on
       case code2:
         if(itsONled[2] == 1) {
            digitalWrite(led2, LOW);
            itsONled[2] = 0;
         } else {
             digitalWrite(led2, HIGH);
             itsONled[2] = 1;
       case code3:
         if(itsONled[3] == 1) {
            digitalWrite(led3, LOW);
            itsONled[3] = 0;
         } else {
             digitalWrite(led3, HIGH);
             itsONled[3] = 1;
    Serial.println(value); // you can comment this line
    irrecv.resume(); // Receive the next value

Arduino ir remote control leds photo

You will have to open the serial monitor window and press the remote buttons to find out what code does each button transmitts and then update the sketch to use those codes. You can add more leds but you’ll have to change the code inside the switch() function and add more cases. For example if you want to add one more led add this code after the last break; inside the switch();

       case code4:
         if(itsONled[4] == 1) {
            digitalWrite(led4, LOW);
            itsONled[4] = 0;
         } else {
             digitalWrite(led4, HIGH);
             itsONled[4] = 1;

The array itsONled[] = {0,0,0,0} is used to set the initial state of LEDs (in our case OFF) and has number of leds + 1 more zeros, so if you add 2 more leds, then add 2 more zeros (5 leds for a total of 6 zeros).

Sorry, comments are closed!