// Include necessary libraries
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#define BLYNK_TEMPLATE_ID "TMPL62r_FDX4E"
#define BLYNK_TEMPLATE_NAME "reserch sample1"
// Define relay pins
#define RELAY1_PIN 25 // Relay 1 connected to GPIO 25
#define RELAY2_PIN 26 // Relay 2 connected to GPIO 26
// Blynk authentication token
char auth[] = "z7OCzqMtu7s7DSfG6cQmB7leDK1h7Ao5"; // Replace with your Blynk authentication token
// Wi-Fi credentials
char ssid[] = "Wokwi-GUEST"; // Wokwi's guest network
char pass[] = ""; // Leave empty for Wokwi's guest Wi-Fi network
// Virtual Pins for Blynk control
#define VIRTUAL_RELAY1 V0 // Virtual pin for Relay 1 (LED 1)
#define VIRTUAL_RELAY2 V1 // Virtual pin for Relay 2 (LED 2)
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Connect to Wi-Fi and Blynk
Blynk.begin(auth, ssid, pass);
// Set relay pins as output
pinMode(RELAY1_PIN, OUTPUT);
pinMode(RELAY2_PIN, OUTPUT);
// Turn relays off initially (LEDs off)
digitalWrite(RELAY1_PIN, LOW); // Relay 1 OFF
digitalWrite(RELAY2_PIN, LOW); // Relay 2 OFF
Serial.println("Relay control initialized and connected to Blynk.");
}
// Function to control Relay 1 (LED 1)
BLYNK_WRITE(VIRTUAL_RELAY1) {
int value = param.asInt(); // Get the value from the Blynk app (0 or 1)
digitalWrite(RELAY1_PIN, value); // Set relay state based on Blynk input
Serial.println(value ? "Relay 1 ON (LED 1)" : "Relay 1 OFF (LED 1)");
}
// Function to control Relay 2 (LED 2)
BLYNK_WRITE(VIRTUAL_RELAY2) {
int value = param.asInt(); // Get the value from the Blynk app (0 or 1)
digitalWrite(RELAY2_PIN, value); // Set relay state based on Blynk input
Serial.println(value ? "Relay 2 ON (LED 2)" : "Relay 2 OFF (LED 2)");
}
void loop() {
Blynk.run(); // Keeps the Blynk connection active
}
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
relay1:VCC
relay1:GND
relay1:IN
relay1:NC
relay1:COM
relay1:NO
relay2:VCC
relay2:GND
relay2:IN
relay2:NC
relay2:COM
relay2:NO
led1:A
led1:C
led2:A
led2:C