#define BLYNK_TEMPLATE_ID "TMPL3dPPsnXWw"
#define BLYNK_TEMPLATE_NAME "SMART BUILDING"
#define BLYNK_AUTH_TOKEN "HHMl0LUjOzxmF93DxeqmtD0SWka9ddeO"
#define BLYNK_PRINT_Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHTesp.h"
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] ="Wokwi-GUEST";
char pass[] ="";
BlynkTimer timer;
DHTesp dhtSensor;
const int dev1 = 23;
const int dev2 = 22;
const int dev3 = 21;
const int dev4 = 19;
const int dev5 = 18;
//for DHT sensor
const int dht_pin = 15;
// for pushbuttons
const int button1 = 2;
int relay_s_dev1 = 0;
int relay_s_dev2 = 0;
int relay_s_dev3 = 0;
int relay_s_dev4 = 0;
int relay_s_dev5 = 0;
#define vpin1 V1
#define vpin2 V2
#define vpin3 V3
#define vpin4 V4
#define vpin5 V5
BLYNK_CONNECTED () {
Blynk.syncVirtual(vpin1);
Blynk.syncVirtual(vpin2);
Blynk.syncVirtual(vpin3);
Blynk.syncVirtual(vpin4);
Blynk.syncVirtual(vpin5);
}
BLYNK_WRITE(vpin1) {
relay_s_dev1 = param.asInt();
digitalWrite(dev1, relay_s_dev1 );
}
BLYNK_WRITE(vpin2) {
relay_s_dev2 = param.asInt();
digitalWrite(dev2, relay_s_dev2 );
}
BLYNK_WRITE(vpin3) {
relay_s_dev3 = param.asInt();
digitalWrite(dev3, relay_s_dev3 );
}
BLYNK_WRITE(vpin4) {
relay_s_dev4 = param.asInt();
digitalWrite(dev4, relay_s_dev4 );
}
BLYNK_WRITE(vpin5) {
relay_s_dev5 = param.asInt();
digitalWrite(dev5, relay_s_dev5 );
}
void send_dht_val() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
float temp = data.temperature;
Blynk.virtual(V8,temp);
}
void setup() {
pinMode(dev1, OUTPUT);
pinMode(dev2, OUTPUT);
pinMode(dev3, OUTPUT);
pinMode(dev4, OUTPUT);
pinMode(dev5, OUTPUT);
//for push button
pinMode(button1, INPUT_PULLUP);
// for DHT sensor
dhtSensor.setup(dht_pin, DHTesp::DHT22);
// to start serial print
Serial.begin(115200);
// this is starting check for the led
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);
Blynk.begin(auth,ssid,pass);
}
void button_status() {
Serial.println(digitalRead(button1));
if(digitalRead(button1 == LOW)) {
delay(500);
controlButton(1);
Blynk.virtualWrite(vpin1, relay_s_dev1);
}
else if (digitalRead(button2) == LOW) {
delay(500);
controlButton(2);
Blynk.virtualWrite(vpin2, relay_s_dev2);
}
void controlButton(int relayIn){
if(relayIn == 1) {
relay_s_dev1 != relay_s_dev1;
delay(100);
}
}
void loop() {
Blynk.run();
timer.run();
send_dht_val()
timer.SetInternal (2000, send_dht_val)
}