#define BLYNK_TEMPLATE_ID "TMPL6TH6CX_vY"
#define BLYNK_TEMPLATE_NAME "DIEUKHIEN"
#define BLYNK_AUTH_TOKEN "0lzoNYMnvlAfJX1iCUs0awcySD9l6Q00"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <string.h>
#include "DHT.h"
// DHT define
#define DHTTYPE DHT22 // DHT 22
#define DHTPIN 15
DHT dht(DHTPIN, DHTTYPE);
// Define LED
#define LED 27
WidgetLED LED_ON_APP(V2);
int button;
#define LED1 2
WidgetLED LED1_ON_APP(V4);
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
int D_value;
void setup()
{
// Debug console
pinMode(LED, OUTPUT);
Serial.begin(115200);
pinMode(LED1, OUTPUT);
digitalWrite(LED1, LOW);
dht.begin();
Blynk.begin(auth, ssid, pass);
}
BLYNK_WRITE(V3) {
button = param.asInt();
if(button == 1) {
digitalWrite(LED, HIGH);
LED_ON_APP.on();
} else {
digitalWrite(LED, LOW);
LED_ON_APP.off();
}
}
void loop()
{
Blynk.run();
// Read Temp
float t = dht.readTemperature();
// Read Humi
float h = dht.readHumidity();
// Check isRead ?
if (isnan(h) || isnan(t)) {
delay(500);
Serial.println("Failed to read from DHT sensor!\n");
return;
}
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V1, h);
Serial.print("\n");
Serial.print("Humidity: " + String(h) + "%");
Serial.print("\t");
Serial.print("Temperature:" + String(t) + " C");
delay(2000);
if(h>30){
D_value = 1;
}
else D_value = 0;
if (D_value) {
digitalWrite(LED1, HIGH);
LED1_ON_APP.on();
delay(1000);
digitalWrite(LED1, LOW);
LED1_ON_APP.off();
delay(500);
}
else {
digitalWrite(LED1, LOW);
LED1_ON_APP.off();
}
}