Button
Press one certain key (CH-) of a remote control, both the LED and attached LED will light up, then press any other key, and the LEDS will go out
hardware
- Arduino Board
- Infrared receiver Board
- Infrared remote controller
- 2-color LED board
wire
Infrared reciver
- DO 7
- VCC VCC
- GND GND
2-color LED
- GND -
- center pin 13
code
#include <IRremote.h>
const int irReceiverPin = 7; // the SIG of receiver module attach to pin 7;
const int ledPin = 13; // built-in LED
IRrecv irrecv(irReceiverPin);
decode_results results;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // enable ir receiver module
}
void loop() {
if (irrecv.decode(&results)) { // if the ir receiver module receive data
Serial.print("irCode: ");
Serial.print(results.value, HEX);
Serial.print(", bits: ");
Serial.println(results.bits);
irrecv.resume();
}
delay(600);
if (results.value == 0xFFA25D) { // CH-
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW); // turn off the LED
}
}