Electronics Champ
Published © GPL3+

Remote Controlled LEDs with IR Receiver and Arduino

Control two LEDs with IR Remote, IR Receiver and Arduino.

BeginnerFull instructions provided760
Remote Controlled LEDs with IR Receiver and Arduino

Things used in this project

Story

Read more

Code

Code

Arduino
/*
 
  This sketch reads the value from an IR Remote, decodes it and turns
  on or off two LEDs accordingly.
 
  This program is made by Shreyas for Electronics Champ YouTube Channel.
  Please subscribe to this channel. Thank You.
 
*/
 
// Including the library
#include <IRremote.h>
 
// Define IR Receiver's output pin
IRrecv irrecv(3);
 
// Decoded results are saved in 'data' variable
decode_results data;
 
bool state1 = 0;
bool state2 = 0;
int led1 = 8;
int led2 = 9;
 
// Assign the HEX number obtained from your IR Remote here
#define btn1 0x0
#define btn2 0x0
 
void setup() {
 
  // Define the pins as output
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
 
  //Start Serial Communication
  Serial.begin(9600);
 
  // Configure the timer and the state machine for IR reception
  irrecv.enableIRIn();
}
 
void loop() {
 
  if (irrecv.decode(&data)) {  //If the sensor detects a signal
 
    //Prints a decoded value (This value is different for each button on the remote)
    Serial.print("0x");
    Serial.println(data.value, HEX);
    delay(1000);
    irrecv.resume();
 
    if (data.value == btn1) {
 
      //Toggles the boolean value
      state1 = !state1;
      digitalWrite(led1, state1);
 
      /*
        These lines prevent the receiver
        from reading the same value twice
      */
      irrecv.disableIRIn();
      delay(500);
      irrecv.enableIRIn();
 
    }
 
    else if (data.value == btn2) {
 
      //Toggles the boolean value
      state2 = !state2;
      digitalWrite(led2, state2);
      
      /*
        These lines prevent the receiver
        from reading the same value twice
      */
      irrecv.disableIRIn();
      delay(500);
      irrecv.enableIRIn();
 
    }
  }
}

Credits

Electronics Champ

Electronics Champ

3 projects • 9 followers
Projects based on breadboard electronics and Arduino with clear step-by-step instructions, circuit diagrams, schematics, and source code.

Comments