Control LED Using IR Remote : Simple

9.6K328

Intro: Control LED Using IR Remote : Simple

Hello everyone, In this Instructables, we will control LED using IR remote.

STEP 1: Gather the Parts

  1. A breadboard
  2. A LED
  3. A 220ohm resistor
  4. An Arduino UNO
  5. A TSOP382 IR receiver
  6. Some jumper or hookup wires

STEP 2: Wiring

Hookup all the components according to the circuit diagram shown above.

STEP 3: Receive the IR Signals From the Remote

Download Ken Shirriffs IR library from Github then add the library to "Arduino installation location\libraries\"

Upload the following code to your Arduino:

#include <IRremote.h>

int IR_Recv = 2; //IR Receiver Pin 2
IRrecv irrecv(IR_Recv);
decode_results results;

void setup(){
  pinMode(13, OUTPUT);
  Serial.begin(9600); //starts serial communication
  irrecv.enableIRIn(); // Starts the receiver
}

void loop(){
  if (irrecv.decode(&results))
  {
    long int decCode = results.value;
    Serial.println(decCode);
    irrecv.resume();
  }
}

Then open the serial monitor on your Arduino IDE and receive IR decimal signals by pressing buttons on your remote for this project we'll need two IR decimal signals.
For me, the IR decimal values are "3733801123" and "403429887" for Select and Power button respectively.

STEP 4: The Final Code

Upload the following code to your Arduino after replacing 3733801123 and 403429887 with your IR remote decimal code:

#include <IRremote.h>

int IR_Recv = 2; //IR Receiver Pin 2
IRrecv irrecv(IR_Recv);
decode_results results;

void setup(){
  pinMode(13, OUTPUT);
  Serial.begin(9600); //starts serial communication
  irrecv.enableIRIn(); // Starts the receiver
}

void loop(){
  if (irrecv.decode(&results)){
    long int decCode = results.value;
    Serial.println(decCode);
    if (results.value == 3733801123) //Select button
    {
      digitalWrite(13, HIGH);
      Serial.println("LED turned ON");
    }
    if (results.value == 403429887) //Power button
    {
      digitalWrite(13, LOW);
      Serial.println("LED turned OFF");
    }
    irrecv.resume();
  }
}

STEP 5: Done

Now just press the button of the remote whose code you assigned to your Arduino to see your LED turning on and off.

Thanks for viewing.

Please write your questions or suggestions below.

6 Comments

Not sure what i'm doing wrong, but all i'm getting is -1 in the monitor window and no switching of LED.
Anybody help with this?
Hey, it's me again, so i try that code you given me, and somehow it's doesn't work, the problem is i don't know wire the PIN11 to what LED's leg ( + or - ), also i wanna ask is it ok if you can show me how to blink the led?
Wow, really like your work. Can you do me a favor pls, write a code to blink LED and adjust LED's brightness, please?
Here's the arduino sketch file
Do this:
Wire the LED to PIN 11
Go to step 3 and get two more button value
One for brightness + and other for brightness -
Then use those values for brightness+ and brightness- in the below code:

#include <IRremote.h>
#define LED_PIN 11
//For controlling brightness use Arduino's analog PINS
// ON UNO PINS: 3,5,6,9,10,11
int IR_Recv = 2; //IR Receiver Pin 2
IRrecv irrecv(IR_Recv);
decode_results results;
uint8_t brightnessValue = 127;
uint8_t changeBrightnessBY = 10;
void setup(){
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600); //starts serial communication
irrecv.enableIRIn(); // Starts the receiver
}
void loop(){
if (irrecv.decode(&results)){
long int decCode = results.value;
Serial.println(decCode);
if (results.value == 3733801123) //Select button
{
analogWrite(LED_PIN, brightnessValue);
Serial.println("LED turned ON");
}
if (results.value == 403429887) //Power button
{
analogWrite(LED_PIN, 0);
Serial.println("LED turned OFF");
}
if (results.value == 422111111) //Brightness UP KEY
{
if(brightnessValue+changeBrightnessBY<255){
brightnessValue+=changeBrightnessBY;
}
analogWrite(LED_PIN, brightnessValue);
Serial.println("Brightness UP");
}
if (results.value == 523473811) //Brightness DOWN KEY
{
if(brightnessValue-changeBrightnessBY>0){
brightnessValue-=changeBrightnessBY;
}
analogWrite(LED_PIN, brightnessValue);
Serial.println("Brightness DOWN");
}
irrecv.resume();
}
}