Using an IR Remote with LEDs

Using an IR Remote with LEDs

How to use IR to do stuff!

  • 3,617 views
  • 2 comments
  • 2 respects

Components and supplies

Apps and online services

About this project

Now i'll show you how to use an IR reciever to do different things using a remote, in this case I'm turning on/off LEDs, but you can come up with something better, and modify the code a bit

Code

IR with LEDs ManualArduino
In this code, you'll have to replace the value of the button you want to use for the "0xFD08F7" on row 29, as well as in row 32 and 35.
With this code, once you press a button, an LED will turn on, and it won't turn off until you press the same button again.
If you want them to turn off automatically after a certain amount of time, I left another code after this one.
#include <IRremote.h>  

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
 
#define led1 4 //Associates led1 al to pin 4
#define led2 5 //Associates led2 al to pin 5
#define led3 6 //Associates led3 al to pin 6
boolean led1_est = false;  //variable that stores the state of the led
boolean led2_est = false;  //variable that stores the state of the led
boolean led3_est = false;  //variable that stores the state of the led
void setup()
{
  Serial.begin(9600);  //Initializes serial port
  pinMode (led1, OUTPUT);  //Establishes led1 as an output
  pinMode (led2, OUTPUT);  //Establishes led2 as an output
  pinMode (led3, OUTPUT);  //Establishes led3 as an output

  irrecv.enableIRIn();   
}
 
void loop()
{
  if (irrecv.decode(&results))  //If it recieves data
  {
    Serial.println(results.value, HEX);  
    irrecv.resume(); //Prepares to recieve next value
    if (results.value == 0xFD08F7) led1_est = !led1_est;  //Change here for the HEX value of your button
      //If the recieved data matches the one stored, changes the state of led1
      
    if (results.value == 0xFD8877) led2_est = !led2_est;//Change here for the HEX value of your button
      //If the recieved data matches the one stored, changes the state of led2
      
    if (results.value == 0xFD48B7) led3_est = !led3_est; //Change here for the HEX value of your button
      //If the recieved data matches the one stored, changes the state of led3

    else
    {
      Serial.println ("Invalid Code");  //If it doesnt match the stored values, it prints out "Invalid code"
    }
  }
  digitalWrite(led1,led1_est);  //Asigns led1 the state of "led1_est"
  digitalWrite(led2,led2_est);  //Asigns led2 the state of "led2_est"
  digitalWrite(led3,led3_est);  //Asigns led3 the state of "led3_est"

}
IR with LEDs AutoArduino
However, with this code, once you turn on an LED by pressing the button, it will automatically go off after 2000 miliseconds (you can change this in the code in row 25, 32, 39)
#include <IRremote.h>

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

#define led1 4 //Associates led1 al to pin 4
#define led2 5 //Associates led2 al to pin 5
#define led3 6 //Associates led3 al to pin 6

void setup(){
  irrecv.enableIRIn();
  
  pinMode(led1, OUTPUT);    //Establishes led1 as an output
  pinMode(led2, OUTPUT);    //Establishes led2 as an output
  pinMode(led3, OUTPUT);    //Establishes led3 as an output
}

void loop(){
    if (irrecv.decode(&results)){

        switch(results.value){
          case 0xFD08F7: //Change here for the HEX value of your button
          digitalWrite(led1, HIGH);
          delay(2000);
          digitalWrite(led1, LOW);
          }

        switch(results.value){
          case 0xFD8877: //Change here for the HEX value of your button
          digitalWrite(led2, HIGH);
          delay(2000);
          digitalWrite(led2, LOW);
          }

        switch(results.value){
          case 0xFD48B7: //Change here for the HEX value of your button
          digitalWrite(led3, HIGH);
          delay(2000);
          digitalWrite(led3, LOW);
          }


        irrecv.resume(); 
    }
}

Schematics

Schematics
Ir with leds jgdiylggmj
ir_with_leds_I2UyZGhOzz.fzz
ir_with_leds_I2UyZGhOzz.fzz

Comments

Similar projects you might like

DIY IR Remote and IR Remote controlled LEDs

Project tutorial by Rucksikaa Raajkumar

  • 5,303 views
  • 1 comment
  • 8 respects

Turn LEDs On/Off via Remote Control

Project tutorial by ismystore

  • 15,803 views
  • 2 comments
  • 9 respects

IR - Remote Control Car

by VISHAL SIVARAMAN

  • 5,684 views
  • 0 comments
  • 7 respects

Arduino: Switching ON/OFF Appliances Using IR Remote

Project showcase by Naman Chauhan

  • 27,078 views
  • 3 comments
  • 147 respects

IR Remote Controlled Power Switch for Rapsberry Pi 3

Project tutorial by Vilém Kužel

  • 6,826 views
  • 1 comment
  • 12 respects
Add projectSign up / Login