#define BLYNK_TEMPLATE_ID "TMPL3JzvEaN7u"
#define BLYNK_TEMPLATE_NAME "SmartBuilding"
#define BLYNK_AUTH_TOKEN "3eGYO0sA8KZ5NBSQ6kL4Mz6g5EJGG7ph"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHTesp.h>
char auth[] =BLYNK_AUTH_TOKEN;
char ssid[] = "wokwi GUEST";
const char pass[] =''
BlynkTimer timer:
DHTesp dhtSensor:
const int dev1=18;
const int dev2=19; //BUZER1
const int dev3=21;
const int dev4=22;//BUZZER2
const int dev5=23;
const int dev6=15; // DHT sensor
const int dev7=2; // pushbtn
int rs_dev1=0;
int rs_dev2=0;
int rs_dev3=0;
int rs_dev4=0;
int rs_dev5=0;
// virtual pin from blynk
#define vp1=v1
#define vp2=v2
#define vp3=v3
#define vp4=v4
#define vp5=v5
// blynk connect
blynk_conected()
{
Blynk.syncVirtual(vp1);
Blynk.syncVirtual(vp2);
Blynk.syncVirtual(vp3);
Blynk.syncVirtual(vp4);
Blynk.syncVirtual(vp5);
}
BLYNK_WRITE(vp1)
{
rs_dev1= param.asint();
digitalWrite(dev1,rs_dev1);
}
BLYNK_WRITE(vp2)
{
rs_dev2= param.asint();
digitalWrite(dev2,rs_dev2);
}
BLYNK_WRITE(vp3)
{
rs_dev3= param.asint();
digitalWrite(dev3,rs_dev3);
}
BLYNK_WRITE(vp4)
{
rs_dev4= param.asint();
digitalWrite(dev4,rs_dev4);
}
BLYNK_WRITE(vp5)
{
rs_dev5= param.asint();
digitalWrite(dev5,rs_dev5);
}
void send_dht_val()
{
data = dht.getTempAndHumidity();
float temp=data.temperature;
float humi=data.humidity;
Blynk.virtualWrite(V6,temp);
Blynk.virtualWrite(V7,humi);
}
void setup()
{
pinMode(dev1, OUTPUT);
pinMode(dev2, OUTPUT);
pinMode(dev3, OUTPUT);
pinMode(dev4, OUTPUT);
pinMode(dev5, OUTPUT);
dht.setup(dev6,DHTesp::DHT22);
digitalWrite(dev1.HIGH);
digitalWrite(dev2.HIGH);
digitalWrite(dev3.HIGH);
digitalWrite(dev4.HIGH);
digitalWrite(dev5.HIGH);
delay(1000);
digitalWrite(dev1.LOW);
digitalWrite(dev2.LOW);
digitalWrite(dev3.LOW);
digitalWrite(dev4.LOW);
digitalWrite(dev5.LOW);
delay(1000);
Serial.begin(115200);
Blynk.begin(auth,ssid,pass);
}
void loop()
{
Blynk.run();
timer.run();
timer.setInterval(2000,send_dht_val);
}