#define BLYNK_TEMPLATE_ID "TMPL3aFoFtBSC"
#define BLYNK_TEMPLATE_NAME "Blynk"
#define BLYNK_AUTH_TOKEN "xfslgwAzb_6vM8p5t9gP1AErKIo_Orkf"
// 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[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
#define button1_pin 26
#define LED_Pin 13
int Led_State = 0;
//Change the virtual pins according the rooms
#define button1_vpin V1
//------------------------------------------------------------------------------
// 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);
}
//--------------------------------------------------------------------------
// 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) {
Led_State = param.asInt();
digitalWrite(LED_Pin, Led_State);
}
//--------------------------------------------------------------------------
void setup()
{
// Debug console
Serial.begin(115200);
//--------------------------------------------------------------------
pinMode(button1_pin, INPUT_PULLUP);
//--------------------------------------------------------------------
pinMode(LED_Pin, OUTPUT);
//--------------------------------------------------------------------
//During Starting all Relays should TURN OFF
digitalWrite(LED_Pin, LOW);
//--------------------------------------------------------------------
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
timer.run();
listen_push_buttons();
}
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
void listen_push_buttons(){
//--------------------------------------------------------------------------
if(digitalRead(button1_pin) == LOW){
delay(200);
control_Led(1);
Blynk.virtualWrite(button1_vpin, Led_State); //update button state
}
}
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
void control_Led(int ledvalue){
//------------------------------------------------
if(ledvalue == 1){
Led_State = !Led_State;
digitalWrite(LED_Pin, Led_State);
Serial.println(Led_State);
delay(50);
}
}
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM