#define BLYNK_PRINT Serial // Enable serial debug prints
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
// Define the pin and sensor type
#define DHTPIN 4 // GPIO 4 (D4) where the DHT22 is connected
#define DHTTYPE DHT22 // DHT22 sensor (use DHT11 if you have that)
// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE);
// Replace with your Blynk Auth Token
char auth[] = "S4E9I-mKVWyZsrH5s5Rp3qg7A6hq7jua";
#define BLYNK_TEMPLATE_ID "TMPL6Y5UQlUVw"
#define BLYNK_TEMPLATE_NAME "Smart Dry Cabinet"
#define BLYNK_AUTH_TOKEN "S4E9I-mKVWyZsrH5s5Rp3qg7A6hq7jua"
// Replace with your Wi-Fi credentials
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
void setup() {
// Start serial communication
Serial.begin(115200);
// Initialize the DHT sensor
dht.begin();
// Connect to Wi-Fi and Blynk
Blynk.begin(auth, ssid, pass);
}
void loop() {
// Run Blynk
Blynk.run();
// Read temperature and humidity
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check if any reads failed
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the results to the Serial Monitor
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
// Send data to Blynk
Blynk.virtualWrite(V0, temperature); // Send temperature to virtual pin V0
Blynk.virtualWrite(V1, humidity); // Send humidity to virtual pin V1
// Wait a few seconds before the next reading
delay(2000);
}