#include <IRremoteESP8266.h> // - It is the external library which is used to control the functionalities of IR Remote.
#include <IRrecv.h> // - It is the external library which contains classes and functions for receiving IR signals..
#include <IRutils.h> //It is the external library which provide utility functions for working with IR signals.
# define IR_Receiver_pin 13
# define LED_PIN 12
// This variable will be used to refer to the IR receiver.
// And to give this variable the power of referring to the IR receiver we
// need to put brackets() and pass the pin number where the IR
// receiver is connected with the ESP32.
IRrecv ir_rec(IR_Receiver_pin);
// : This variable will store the decoded results (results) using classes.
decode_results results;
void setup() {
ir_rec.enableIRIn(); //enabling the IR receiver functionality
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// k if an IR signal has been received and decoded successfully
// This function is used to decode the signal value received
//by the IR Receiver to perform the given action.
if (ir_rec.decode(&results))
{
// read the current state of the LED pin, and ! is used to invert it. This results in toggling the LED from on to off or vice versa.
digitalWrite(LED_PIN,!digitalRead(LED_PIN));
delay(500);
//This method is used to prepare the IR receiver for receiving the next IR signal. It resets the internal state of the receiver, allowing it to listen for the next IR signal
ir_rec.resume();
}
}