#define BLYNK_TEMPLATE_ID "TMPL33JBa4Nrw"
#define BLYNK_TEMPLATE_NAME "relay switch"
#define BLYNK_AUTH_TOKEN "x9l7GQB_dc1l77gR1xtCYTER8gNn_BXW"// Replace with your Blynk auth token
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "x9l7GQB_dc1l77gR1xtCYTER8gNn_BXW";
char ssid[] = "Wokwi-GUEST"; // Your WiFi SSID
char pass[] = ""; // Your WiFi Password
int relayPin = 12; // Pin where the relay is connected
void setup() {
pinMode(relayPin, OUTPUT); // Set the relay pin as output
Serial.begin(9600); // Initialize serial communication
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run(); // Run Blynk
}
BLYNK_WRITE(V0) {
int pinValue = param.asInt(); // Get the value from the Blynk app
if (pinValue == 1) {
digitalWrite(relayPin, HIGH); // Turn the relay on
Serial.println("Relay and LED are ON");
} else {
digitalWrite(relayPin, LOW); // Turn the relay off
Serial.println("Relay and LED are OFF");
}
}