December 22, 2024

A simple program to read the code that is received by any Infrared remote control.

#include <IRremote.h>

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

void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
}

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

A simple modification on this code with a if statement and sending digitalWrite high can control a LED to be turned on or off. example

if (results.value == “0789E”)

{

digitalWrite(LEDPIN, HIGH);

}

Obviously for this to work we need the LED to be added to the circuit and the LEDPIN declared (use the first two lessons for the LED addition and the LEDPIN variable declaration.