0
0
AutocadHow-ToBeginner · 4 min read

Arduino IR Remote Controlled LED Project Guide

Use an IR receiver module connected to Arduino to read signals from an IR remote. Write code using the IRremote library to detect button presses and turn an LED on or off accordingly.
📐

Syntax

This project uses the IRremote library to read IR signals. The main parts are:

  • IRrecv irrecv(pin); - sets up the IR receiver on a digital pin.
  • decode_results results; - stores the decoded IR signal.
  • irrecv.enableIRIn(); - starts the IR receiver.
  • if (irrecv.decode(&results)) - checks if a button is pressed.
  • results.value - holds the button code to identify which button was pressed.
  • irrecv.resume(); - prepares to receive the next signal.
arduino
#include <IRremote.h>

const int RECV_PIN = 11; // IR receiver pin
const int LED_PIN = 13;  // LED pin

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  pinMode(LED_PIN, OUTPUT);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    // Use results.value to check button
    irrecv.resume(); // Receive next value
  }
}
💻

Example

This example turns the LED on when the "Power" button on the remote is pressed and off when the "Volume Down" button is pressed. Replace the button codes with your remote's codes.

arduino
#include <IRremote.h>

const int RECV_PIN = 11;
const int LED_PIN = 13;

IRrecv irrecv(RECV_PIN);
decode_results results;

// Replace these with your remote's button codes
const unsigned long POWER_BUTTON = 0xFFA25D;
const unsigned long VOLUME_DOWN_BUTTON = 0xFF629D;

void setup() {
  pinMode(LED_PIN, OUTPUT);
  irrecv.enableIRIn();
  Serial.begin(9600); // For debugging
}

void loop() {
  if (irrecv.decode(&results)) {
    unsigned long value = results.value;
    Serial.println(value, HEX); // Print code for reference

    if (value == POWER_BUTTON) {
      digitalWrite(LED_PIN, HIGH); // LED ON
    } else if (value == VOLUME_DOWN_BUTTON) {
      digitalWrite(LED_PIN, LOW); // LED OFF
    }
    irrecv.resume();
  }
}
Output
When pressing the Power button, the LED turns ON. When pressing the Volume Down button, the LED turns OFF. Serial monitor shows the button codes in HEX.
⚠️

Common Pitfalls

Wrong IR receiver pin: Make sure the IR receiver data pin is connected to the correct Arduino pin defined in the code.

Incorrect button codes: Button codes vary by remote. Use the serial monitor to find your remote's codes before using them.

Missing library: Install the IRremote library via Arduino Library Manager.

Power issues: Ensure the IR receiver and LED have proper power and ground connections.

arduino
// Wrong way: Using wrong pin or no library
// No IRremote library included
const int RECV_PIN = 2; // Wrong pin

void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  // No IR code to read remote
  digitalWrite(13, HIGH); // LED always ON
}

// Right way: Include library and correct pin
#include <IRremote.h>
const int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  pinMode(13, OUTPUT);
  irrecv.enableIRIn();
}

void loop() {
  if (irrecv.decode(&results)) {
    // handle button
    irrecv.resume();
  }
}
📊

Quick Reference

IR Remote Controlled LED Cheat Sheet:

ConceptDescription
IR Receiver PinConnect to Arduino digital pin (e.g., 11)
LED PinConnect LED to digital pin (e.g., 13) with resistor
LibraryUse IRremote library for decoding signals
Button CodesUse serial monitor to find your remote's button codes
Enable Receiverirrecv.enableIRIn(); starts IR reading
Decode Signalirrecv.decode(&results) checks for button press
Resume Receiverirrecv.resume(); prepares for next signal

Key Takeaways

Use the IRremote library to read signals from an IR remote on Arduino.
Connect the IR receiver to the correct digital pin and power it properly.
Find your remote's button codes using the serial monitor before coding actions.
Use button codes to control the LED by turning it on or off in your code.
Always call irrecv.resume() after reading a signal to keep receiving inputs.