#define BLYNK_TEMPLATE_ID "TMPL348uMXXPu"
#define BLYNK_TEMPLATE_NAME "HOME AUTOMATION"
#define BLYNK_AUTH_TOKEN "x2emnAn3YeSfmPhSYT6W_GHfPdlo4-PP"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "x2emnAn3YeSfmPhSYT6W_GHfPdlo4-PP"; // Replace with your Blynk Auth Token
char ssid[] = "WOKWI-GUEST"; // Replace with your WiFi SSID
char pass[] = ""; // Replace with your WiFi password
// Relay pin connections
int relay1 = 4;
int relay2 = 5;
int relay3 = 18;
// LED pin (onboard LED or external)
int ledPin = 2;
BLYNK_WRITE(V0) {
int value = param.asInt(); // Get button state for relay 1
digitalWrite(relay1, value); // Control relay 1
}
BLYNK_WRITE(V1) {
int value = param.asInt(); // Get button state for relay 2
digitalWrite(relay2, value); // Control relay 2
}
BLYNK_WRITE(V2) {
int value = param.asInt(); // Get button state for relay 3
digitalWrite(relay3, value); // Control relay 3
}
BLYNK_WRITE(V3) {
int value = param.asInt(); // Get button state for the onboard LED
digitalWrite(ledPin, value); // Control onboard LED (or external LED)
}
void setup() {
Serial.begin(115200);
// Set relay pins as output
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
// Set LED pin as output
pinMode(ledPin, OUTPUT);
// Connect to WiFi
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi!");
// Initialize Blynk
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run(); // Handle Blynk app communication
}