ARDUINO

Arduino – Control LEDs with IR Remote Control

In this project you’ll use an infrared (IR) receiver and an Arduino to control 3 LEDs with a remote control. This is useful to re-use old remote controls or give some functionally to some of your remote’s buttons.

Updated 17 December 2024

This project is divided into two parts:

  1. You’ll decode the IR signals transmitted by your remote control
  2. You’ll use that info to perform a task with your Arduino (control 3 LEDs)

Parts required

To follow this project you need the following parts:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

header-200.png?w=828&quality=100&strip=all&ssl=1

Introducing the Infrared (IR) Receiver

The infrared receiver is the component shown in the figure below. This is the TSOP4838.

IR receiver labels

Infrared receiver pins:

  • First pin: Vout
  • Second pin: GND
  • Third pin: Vcc

When you press your remote control, it sends infrared modulated signals. These signals contain information that your receiver collects.

Each button sends specific information. So, we can assign that information to a specific button.

Decode the IR signals

In this part of the project you need to decode the IR signals associated with each button.

Schematics

Connect the IR receiver accordingly to the schematics below.

Code

To control the IR receiver, you need to install the IRremote Library  in the Arduino IDE.

Installing the IRremote library

  1. Go to Sketch Include Library > Manage Libraries.
  2. The Library Manager should open at the left sidebar of the IDE. Search for IRremote.
  3. Install the library by shirriff. We’re using version 4.4.1.
Install IR Remote Library Arduino IDE

Copy the following code to your Arduino IDE, and upload it to your Arduino board. Make sure that you have the right board and COM port selected.

#include <IRremote.h>

const int RECV_PIN = 11;

void setup() {
  Serial.begin(9600);
  IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK); // Initialize the receiver
}

void loop() {
  if (IrReceiver.decode()) { // Check if data is received
    // Filter out unknown protocols
    if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
      IrReceiver.resume(); // Resume receiving for the next signal
      return; // Skip this loop iteration
    }

    // Print only valid data
    IrReceiver.printIRResultShort(&Serial); // Print complete received data in one line

    IrReceiver.resume(); // Resume receiving for the next signal
  }
  delay(100);
}

View raw code

Open the serial monitor at a baud rate of 9600.

In this project you want to control 3 LEDs. Choose 6 keys on the remote control for the following tasks:

  1. LED1 – ON
  2. LED1 – OFF
  3. LED2 – ON
  4. LED2 – OFF
  5. LED3 – ON
  6. LED3 – OFF

Press, for example, the button number 1 of your remote control. You should get some information about that key in the Serial Monitor. Save the “command” value for that key.

Arduino IDE IRRemote Key command

Do the same for the other buttons.

Write down the code associated with each button, because you’ll need that information later.

Building the final circuit

In this part, you’ll build the circuit with three LEDs that will be controlled using your remote.

Schematics

Assemble all the parts by following the schematics below.

Code

Now, grab the command values you captured in the previous step for each button. You’ll need to insert them on the following code.

/*
 * Modified by Rui Santos, http://randomnerdtutorialscom
 * based on IRremote Library - Ken Shirriff
*/
 
#include <IRremote.h>

const int RECV_PIN = 11;

const int bluePin = 10;
const int greenPin = 9;
const int yellowPin = 8;

void setup() {
  Serial.begin(9600); // Start serial communication
  IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK); // Start the receiver

  pinMode(bluePin, OUTPUT);    // Set the pins as output
  pinMode(greenPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
}

void loop() {
  // Decode the infrared input
  if (IrReceiver.decode()) {
    if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
      IrReceiver.resume(); // Resume receiving for the next signal
      return; // Skip this loop iteration
    }

    // Print the received command for debugging
    IrReceiver.printIRResultShort(&Serial);

    switch (IrReceiver.decodedIRData.command) {
      case 0x01: // Command to turn ON the blue LED
        digitalWrite(bluePin, HIGH);
        Serial.println("Blue LED ON");
        break;

      case 0x02: // Command to turn ON the green LED
        digitalWrite(greenPin, HIGH);
        Serial.println("Green LED OFF");
        break;

      case 0x03: // Command to turn ON the yellow LED
        digitalWrite(yellowPin, HIGH);
        Serial.println("Yellow LED ON");
        break;

      case 0x04: // Command to turn OFF the blue LED
        digitalWrite(bluePin, LOW);
        Serial.println("Blue LED OFF");
        break;

      case 0x05: // Command to turn OFF the green LED
        digitalWrite(greenPin, LOW);
        Serial.println("Green LED OFF");
        break;

      case 0x06: // Command to turn OFF the yellow LED
        digitalWrite(yellowPin, LOW);
        Serial.println("Yellow LED OFF");
        break;

      default: // Unknown command
        Serial.println("Unknown Command");
        break;
    }

    IrReceiver.resume(); // Receive the next value
  }
  delay(10);
}

View raw code

After adding the commands for each key in the previous code, you can upload it to your Arduino IDE.

Demonstration

In the end, you can control each LED individually using the buttons of your remote control.

Watch the video demonstration

Upcoming Course
Upcoming Course
Learn More
Instructor Tips
Instructor Tips
View Tips
Join Community
Join Community
Join Now