// 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
}
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module