#define BLYNK_TEMPLATE_ID "TMPL6DGJ6O4uH"
#define BLYNK_TEMPLATE_NAME "ESP32 DHT22"
#define BLYNK_AUTH_TOKEN "c9NutiSq6bdQf-oiZTy2JmxT8FQ2JkHi"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define DHTPIN 5 // Mention the digital pin where you connected
#define DHTTYPE DHT22 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void setup() {
Serial.begin(115200);
Serial.println("<<<<<< ESP32 + Blynk >>>>>>");
Blynk.begin(auth, ssid, pass);
dht.begin();
timer.setInterval(2500L, sendSensor);
}
void loop() {
Blynk.run();
timer.run();
}
void sendSensor() {
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
float f = dht.readTemperature(true); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V1, h);
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V2, f);
Serial.println("==================");
Serial.print("Celcius : ");
Serial.println(t);
Serial.print("Fahrenheit : ");
Serial.println(f);
Serial.print("Humidity : ");
Serial.println(h);
//if (t > 40) {
//Blynk.email("[email protected]", "Alert", "Temperature over 40C!");
//Blynk.logEvent("temp_alert", "Temp above 40 degrees");
//}
}