// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "TMPLeI_xcjtY"
#define BLYNK_DEVICE_NAME "Home Automation"
#define BLYNK_AUTH_TOKEN "VwY7rwh6yy-3GmrC1QWU8P6EjJ5u-w--"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
int mode, timer1, timer2;
//mode = 1 : auto | mode = 0 : manual
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
void loop()
{
Blynk.run();
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}
BLYNK_WRITE(V0)
{
if(param.asInt()==1)
digitalWrite(5, HIGH);
else digitalWrite(5, LOW);
}
BLYNK_WRITE(V1)
{
if(param.asInt()==1)
digitalWrite(4, HIGH);
else digitalWrite(4, LOW);
}
BLYNK_WRITE(V6)
{
if(param.asInt()==0) mode=0;
else mode=1;
}
BLYNK_WRITE(V3)
{
if(param.asInt()==0) timer1=0;
else timer1=1;
}
BLYNK_WRITE(V4)
{
if(param.asInt()==0) timer2=0;
else timer2=1;
}
BLYNK_WRITE(V2)
{
if(param.asInt()==1)
{
if(mode==0) digitalWrite(2, HIGH);
else if(mode==1 && timer1==1)
{
digitalWrite(2, HIGH);
delay(5000);
digitalWrite(2, LOW);
}
else if(mode==1 && timer2==1)
{
digitalWrite(2, HIGH);
delay(3000);
digitalWrite(2, LOW);
}
} else digitalWrite(2, LOW);
}