Turn LEDs ON/OFF with an IR Sensor and a TV remote

LEDs turn ON/OFF with an IR Sensor and a TV remote

Supplies:

1 – Breadboard 830 Points
1 – Arduino Nano
1 – Infrared Sensor (vs1838b)
3 – LEDs
3 – 220 Ohm Resistors

Arduino Code:

#include <IRremote.h>

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
const int redPin = 10;
const int greenPin = 11;
const int yellowPin = 12;

void setup() {
  
  Serial.begin(9600);
  irrecv.enableIRIn();
  irrecv.blink13(true);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);

}

void loop() {
  
  if (irrecv.decode(&results)){
  Serial.println(results.value, HEX);

  switch(results.value){
  case 0x36113D: //Keypad button "1"
  digitalWrite(redPin, HIGH);
  delay(100);
  digitalWrite(redPin, LOW);

}

  switch(results.value) {
  case 0x37111D: //Keypad button "2"
  digitalWrite(greenPin, HIGH);
  delay(100);
  digitalWrite(greenPin, LOW);
  
}

  switch(results.value){
  case 0x36912D: //Keypad button "3"
  digitalWrite(yellowPin, HIGH);
  delay(100);
  digitalWrite(yellowPin, LOW);
  
}

irrecv.resume();

}
}

Leave a Comment

+ 21 = 29