#include <LiquidCrystal_I2C.h>
const int relay = 18; // Relay control pin on ESP32
int r2=5;
byte b1=26;
byte b2=14;
LiquidCrystal_I2C lcd(0X27,20,2);
void setup() {
Serial.begin(115200); // Start serial communication
pinMode(relay, OUTPUT); // Set relay pin as output
pinMode(b1, INPUT_PULLUP);
pinMode(b2, INPUT_PULLUP);
lcd.init();
lcd.backlight();
}
void loop() {
// Turn on the relay (LED turns ON if using Normally Open configuration)
lcd.clear();
if(digitalRead(b1)==0)
{
lcd.setCursor(0,0);
digitalWrite(relay, LOW);
digitalWrite(r2, LOW);
lcd.println("LED off");
lcd.setCursor(0,1);
lcd.println("Buzz off");
delay(5000);
// Keep the LED ON for 5 seconds
}
// Turn off the relay (LED turns OFF if using Normally Open configuration)
if(digitalRead(b2)==0)
{
lcd.setCursor(0,0);
digitalWrite(relay, HIGH);
digitalWrite(r2,LOW);
lcd.println("LED on");
lcd.setCursor(0,1);
lcd.println("Buzz on");
delay(5000);
// Keep the LED OFF for 5 seconds
}
}