/* write a Program to perform the following action by using IR Remote and IR Receiver in Wokwi.
If we press any button, that button's unique code should be displayed in the console screen.
If we press the Power button, It should turn OFF the LED bulb.
If we press the Test button on the IR Remote, It should ON the LED bulb.
If we press the button one(1), the LED should blink.
If we press the Menu button, It will display the defined text on the console as what action will be performed by pressing the button.
*/
//INSTALL IRremote in library manager
#include <IRremote.h>
int LED_PIN = 3;
int PIN_RECEIVER = 2;
int button_value = 0;
IRrecv receiver(PIN_RECEIVER);//receiver is variable
void setup()
{
Serial.begin(9600); //starts sending and receiving signals between components
receiver.enableIRIn(); //for enabling the IR receiver functionality
}
void loop()
{
//to check the receiver's unique code from IR Receiver
if (receiver.decode())
{
translateIR(); // below function
receiver.resume(); //will help to continue listing the signals for the IR receiver.
}
}
int translateIR()
{
//below is variable with the unique code as per the button pressed on IR remote.
//In Student Reference Activity1 , they have given list of unique codes
button_value = receiver.decodedIRData.command;
Serial.println(button_value);
if(button_value == 162)
{
Serial.println("POWER");
digitalWrite(LED_PIN,LOW); //LED Off
}
if(button_value == 226)
{
Serial.println("MENU");
Serial.println("Press TEST to turn ON the LED");
Serial.println("Press POWER to turn OFF the LED");
Serial.println("Press One to blink the LED");
}
if(button_value == 34)
{
Serial.println("TEST ");
digitalWrite(LED_PIN, HIGH); //LED ON
}
if(button_value == 48) //for LED blink
{
Serial.println("ONE");
digitalWrite(LED_PIN, HIGH);
delay(300);
digitalWrite(LED_PIN, LOW);
delay(300);
digitalWrite(LED_PIN, HIGH);
delay(300);
digitalWrite(LED_PIN, LOW);
}
}