#include <IRremote.h>
#include <LiquidCrystal_I2C.h>
int ir_pin_receiver = 2; // IR Receiver pin connected to pin 2
int button_value = 0;
IRrecv receiver(ir_pin_receiver); // Initialize the IR Receiver
LiquidCrystal_I2C lcd(0x27, 20, 4); // Initialize the LCD with address 0x27, 20 columns, and 4 rows
void setup() {
receiver.enableIRIn(); // Enable IR Receiver
lcd.init(); // Initialize LCD
lcd.backlight(); // Turn on LCD backlight
Serial.begin(9600); // Initialize Serial communication with LCD
lcd.begin(20, 4); // Initialize LCD dimensions
lcd.setCursor(0, 1); // Set the cursor to the first column of the second row
lcd.print("IR Sensor & Remote:");
}
void loop() {
if (receiver.decode()) {
translateIR();
receiver.resume(); // Resume IR Receiver
}
}
void translateIR() {
button_value = receiver.decodedIRData.command;
Serial.println(button_value);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Button Press:");
// Check which button was pressed and display its name
if (button_value == 162) {
lcd.setCursor(0, 2);
lcd.print("POWER");
}
else if (button_value == 2) {
lcd.setCursor(0, 2);
lcd.print("VOL+");
}
else if (button_value == 226) {
lcd.setCursor(0, 2);
lcd.print("FUNC/STOP");
}
else if (button_value == 168) {
lcd.setCursor(0, 2);
lcd.print("PAUSE");
}
else if (button_value == 194) {
lcd.setCursor(0, 2);
lcd.print("REWIND");
}
else if (button_value == 224) {
lcd.setCursor(0, 2);
lcd.print("PREV");
}
else if (button_value == 144) {
lcd.setCursor(0, 2);
lcd.print("NEXT");
}
// Add conditions for other buttons here
}