#define BLYNK_TEMPLATE_ID "TMPL4qLFzD6i4"
#define BLYNK_TEMPLATE_NAME "Smart Home Automation"
#define BLYNK_AUTH_TOKEN "PJ_D0CyUH9bCWqEcYqbKWGFANWXEtZr9"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST"; // Your WiFi SSID
char pass[] = ""; // Your WiFi Password
#define RELAY1_PIN 2 // GPIO pin for Relay 1
#define RELAY2_PIN 5 // GPIO pin for Relay 2
void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud
pinMode(RELAY1_PIN, OUTPUT); // Set Relay 1 pin as output
pinMode(RELAY2_PIN, OUTPUT); // Set Relay 2 pin as output
digitalWrite(RELAY1_PIN, LOW); // Initialize Relay 1 to OFF
digitalWrite(RELAY2_PIN, LOW); // Initialize Relay 2 to OFF
Blynk.begin(auth, ssid, pass); // Connect to Blynk
}
BLYNK_WRITE(V0) { // Control for Relay 1
int lightState = param.asInt(); // Get state from Blynk app
digitalWrite(RELAY1_PIN, lightState);
Serial.println(String("Relay 1 State: ") + lightState);
}
BLYNK_WRITE(V1) { // Control for Relay 2
int lightState = param.asInt(); // Get state from Blynk app
digitalWrite(RELAY2_PIN, lightState);
Serial.println(String("Relay 2 State: ") + lightState);
}
void loop() {
Blynk.run(); // Run Blynk
}
// #define BLYNK_TEMPLATE_ID "TMPL4qLFzD6i4"
// #define BLYNK_TEMPLATE_NAME "Smart Home Automation"
// #define BLYNK_AUTH_TOKEN "PJ_D0CyUH9bCWqEcYqbKWGFANWXEtZr9"
// #define BLYNK_PRINT Serial
// #include <WiFi.h>
// #include <WiFiClient.h>
// #include <BlynkSimpleEsp32.h>
// char auth[] = BLYNK_AUTH_TOKEN;
// char ssid[] = "Wokwi-GUEST";
// char pass[] = "";
// #define Light1 2
// #define Light2 5
// // Function to handle the V0 virtual pin (Light1)
// BLYNK_WRITE(V0) {
// int lightState = param.asInt(); // Get the state from the Blynk app
// digitalWrite(Light1, lightState);
// Serial.println(String("V0 Data: ") + lightState);
// }
// // Function to handle the V1 virtual pin (Light2)
// BLYNK_WRITE(V1) {
// int lightState = param.asInt(); // Get the state from the Blynk app
// digitalWrite(Light2, lightState);
// Serial.println(String("V1 Data: ") + lightState);
// }
// void setup() {
// Serial.begin(9600); // Start the serial output at 9600 baud
// pinMode(Light1, OUTPUT);
// pinMode(Light2, OUTPUT);
// digitalWrite(Light1, LOW); // Initialize Light1 to OFF
// digitalWrite(Light2, LOW); // Initialize Light2 to OFF
// Blynk.begin(auth, ssid, pass); // Connect to Blynk
// }
// void loop() {
// Blynk.run(); // Run Blynk
// }
// #define BLYNK_TEMPLATE_ID "TMPL4qLFzD6i4"
// #define BLYNK_TEMPLATE_NAME "Smart Home Automation"
// #define BLYNK_AUTH_TOKEN "PJ_D0CyUH9bCWqEcYqbKWGFANWXEtZr9"
// #define BLYNK_PRINT Serial
// #include <WiFi.h>
// #include <WiFiClient.h>
// #include <BlynkSimpleEsp32.h>
// char auth[] = BLYNK_AUTH_TOKEN;
// char ssid[] = "Wokwi-GUEST";
// char pass[] = "";
// #define Light1 2
// #define Light2 5
// BLYNK_WRITE(V0)
// {
// digitalWrite(Light1, param.asInt());
// Serial.println(String("V0 Data: ") + param.asInt());
// delay(10);
// }
// BLYNK_WRITE(V1)
// {
// digitalWrite(Light2, param.asInt());
// Serial.println(String("V1 Data: ") + param.asInt());
// delay(10);
// }
// void setup()
// {
// Serial.begin(9600); //Start the serial output at 9600 baud
// pinMode(Light1, OUTPUT);
// pinMode(Light2, OUTPUT);
// digitalWrite(Light1, LOW);
// digitalWrite(Light2, LOW);
// Blynk.begin(auth, ssid, pass);//Splash screen delay
// delay(2000);
// }
// void loop() //Loop function
// {
// Blynk.run();
// }