code
#define BLYNK_TEMPLATE_ID "TMPLxzJ5naNs"
#define BLYNK_DEVICE_NAME "Pump"
#define BLYNK_AUTH_TOKEN "BtOEe50CeVdS90-OuWlT_-F_xywnK0jl"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define relay1 33
#define relay2 25
#define relay3 26
#define relay4 27
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "TMTFACGUEST";
char pass[] = "TMTst33l@tmtwifi";
BlynkTimer timer;
BLYNK_WRITE(V0){
if (param.asInt() == 0 ){
digitalWrite(relay1 , HIGH);
}
else if(param.asInt() == 1){
digitalWrite(relay1, LOW);
}
}
BLYNK_WRITE(V1){
if (param.asInt() == 0 ){
digitalWrite(relay2 , HIGH);
}
else if(param.asInt() == 1){
digitalWrite(relay2, LOW);
}
}
BLYNK_WRITE(V2){
if (param.asInt() == 0 ){
digitalWrite(relay3 , HIGH);
}
else if(param.asInt() == 1){
digitalWrite(relay3, LOW);
}
}
BLYNK_WRITE(V3){
if (param.asInt() == 0 ){
digitalWrite(relay4 , HIGH);
}
else if(param.asInt() == 1){
digitalWrite(relay4, LOW);
}
}
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, millis() / 1000);
}
/*void ConnectWiFi(){
WiFi.begin(ssid,pass);
if (WiFi.status () !=WL_CONNECTED){
Serial.print("concnect");
}else{
Serial.print("Failed");
}
Serial.println("connected to wifi network");
delay(1000);
}*/
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
}
void loop()
{
Blynk.run();
//ConnectWiFi();
timer.run(); // Initiates BlynkTimer
}