#include <WiFi.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "Ekd3Cdd-aTT2wlHBSf4XNXE_wTsfnVT1";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
BlynkTimer timer;
#define relay2 18
#define relay3 19
#define relay4 23
int SW_relay = 0;
bool relay2Status = false;
bool relay3Status = false;
bool relay4Status = false;
BLYNK_WRITE(V0)
{
int relayState = param.asInt();
digitalWrite(relay2, relayState);
relay2Status = relayState;
}
BLYNK_WRITE(V1)
{
int relayState = param.asInt();
digitalWrite(relay3, relayState);
relay3Status = relayState;
}
BLYNK_WRITE(V2)
{
int relayState = param.asInt();
digitalWrite(relay4, relayState);
relay4Status = relayState;
}
void updateLCD() {
LCD.setCursor(0, 2);
LCD.print(relay2Status ? "ON " : "OFF");
LCD.setCursor(4, 2 );
LCD.print(relay3Status ? "ON " : "OFF");
LCD.setCursor(8, 2);
LCD.print(relay4Status ? "ON " : "OFF");
}
void setup() {
Serial.begin(115200);
LCD.init();
LCD.backlight();
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("R1");
LCD.setCursor(4, 0);
LCD.print("R2");
LCD.setCursor(8, 0);
LCD.print("R3");
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, updateLCD); // Update LCD every 1 second
}
void loop() {
delay(250);
Blynk.run();
timer.run();
}