#define DECODE_NEC
#include <IRremote.hpp>
/*
* Press 0 to turn the LED on
*/
constexpr uint8_t IR_RECV_PIN {3};
constexpr uint8_t RELAY_PIN {2};
constexpr uint16_t TOGGLE_BTN = 0x68; // IR command to toggle LED via relay
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW); // Relay OFF
IrReceiver.begin(IR_RECV_PIN);
Serial.println("IR Receiver ready");
}
void loop() {
if (IrReceiver.decode()) {
IrReceiver.printIRResultShort(&Serial);
if (IrReceiver.decodedIRData.protocol == NEC ||
IrReceiver.decodedIRData.protocol == NEC2) {
uint16_t cmd = IrReceiver.decodedIRData.command;
if (cmd == TOGGLE_BTN) {
digitalWrite(RELAY_PIN, !digitalRead(RELAY_PIN)); // Toggle relay
Serial.println("LED via relay toggled!");
}
}
IrReceiver.resume();
}
}