// Include necessary libraries
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

// Define relay pins
#define RELAY1_PIN 25  // Relay 1 connected to GPIO 25
#define RELAY2_PIN 26  // Relay 2 connected to GPIO 26
#define BLYNK_TEMPLATE_ID "TMPL62r_FDX4E"
#define BLYNK_TEMPLATE_NAME "reserch sample1"

// 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:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK
NOCOMNCVCCGNDINLED1PWRRelay Module
relay2:VCC
relay2:GND
relay2:IN
relay2:NC
relay2:COM
relay2:NO
NOCOMNCVCCGNDINLED1PWRRelay Module
relay1:VCC
relay1:GND
relay1:IN
relay1:NC
relay1:COM
relay1:NO
led1:A
led1:C
r1:1
r1:2
r2:1
r2:2
led2:A
led2:C