#define BLYNK_TEMPLATE_ID "TMPL3KMaH7Hb0"
#define BLYNK_TEMPLATE_NAME "ESP32 Home Automation"
#define BLYNK_AUTH_TOKEN "OhMoTKVHl5wrkxlfIRpB8OEijQox89x_"
// 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;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "realme XT";
char pass[] = "92094426"
BlynkTimer timer;
#define button1_pin 26
#define button2_pin 25
#define button3_pin 33
#define button4_pin 32
#define relay1_pin 13
#define relay2_pin 12
#define relay3_pin 14
#define relay4_pin 27
int relay1_state = 0;
int relay2_state = 0;
int relay3_state = 0;
int relay4_state = 0;
//Change the virtual pins according the rooms
#define button1_vpin V1
#define button2_vpin V2
#define button3_vpin V3
#define button4_vpin V4
//-------------------------------------------------------------------------
// This function is called every time the device is connected to the Blynk.Cloud
// Request the latest state from the server
BLYNK_CONNECTED() {
Blynk.syncVirtual(button1_vpin);
Blynk.syncVirtual(button2_vpin);
Blynk.syncVirtual(button3_vpin);
Blynk.syncVirtual(button4_vpin);
}
//-------------------------------------------------------------------------
// This function is called every time the Virtual Pin state change
//i.e when web push switch from Blynk App or Web Dashboard
BLYNK_WRITE(button1_vpin) {
relay1_state = param.asInt();
digitalWrite(relay1_pin, relay1_state);
}
//--------------------------------------------------------------------------
BLYNK_WRITE(button_2vpin) {
relay2_state = param.asInt();
digitalWrite(relay1_pin, relay2_state);
}
//--------------------------------------------------------------------------
BLYNK_WRITE(button_3vpin) {
relay3_state = param.asInt();
digitalWrite(relay1_pin, relay3_state);
}
//--------------------------------------------------------------------------
BLYNK_WRITE(button_4vpin) {
relay4_state = param.asInt();
digitalWrite(relay1_pin, relay4_state);
}
//---------------------------------------------------------------------------
void setup()
{
// Debug consol
Serial.begin(115200);
//------------------------------------------------------------------------------
pinMode(button1_pin, INPUT_PULLUP);
pinMode(button2_pin, INPUT_PULLUP);
pinMode(button3_pin, INPUT_PULLUP);
pinMode(button4_pin, INPUT_PULLUP);
//-----------------------------------------------------------------------------
pinMode(relay1_pin, OUTPUT);
pinMode(relay2_pin, OUTPUT);
pinMode(relay3_pin, OUTPUT);
pinMode(relay4_pin, OUTPUT);
//----------------------------------------------------------------------------
//During Starting all Relays should Turn OFF
digitalWrite(relay1_pin, HIGH);
digitalWrite(relay2_pin, HIGH);
digitalWrite(relay3_pin, HIGH);
digitalWrite(relay4_pin, HIGH);
//------------------------------------------------------------------------------
Blynk.virtualWrite(button_vpin, relay1_state);
Blynk.virtualWrite(button_vpin, relay2_state);
Blynk.virtualWrite(button_vpin, relay3_state):
Blynk.virtualWrite(button_vpin, relay4_state);
//-----------------------------------------------------------------------------
}
void loop()
{
Blynk.run()
timer.run()
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communiction with Blynk. Remember
// to avoid delay() function
listen_push_buttons();
}
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM