#define BLYNK_TEMPLATE_ID "TMPL3Y7pXgOxa"
#define BLYNK_TEMPLATE_NAME "dht sensor"
#define BLYNK_AUTH_TOKEN "mbm543mSznjxlycZOuWzayB9AVFsCpzm"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#define TEMP V0
#define Hum V1
float h;
float t;
int threshold=50;
bool tempAlertSent = false;
void setup() {
Serial.begin(115200);
dht.begin();
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop() {
Blynk.run();
h = dht.readHumidity();
t = dht.readTemperature();
Blynk.virtualWrite(TEMP,t);
Blynk.virtualWrite(Hum,h);
if(t>50 && !tempAlertSent)
{
Serial.println("Temperature is high");
Blynk.logEvent("temperature_alert");
tempAlertSent= true;
}
else if(t<50)
{
Serial.println("Temperature is low");
tempAlertSent= false;
}
Serial.print("Temperature :");
Serial.println(t);
Serial.print("||");
Serial.print("Humidity: ");
Serial.println(h);
delay(1000);
}