#define BLYNK_TEMPLATE_ID "TMPL2z6KlQjR0"
#define BLYNK_TEMPLATE_NAME "we"
#define BLYNK_AUTH_TOKEN "S86Boub6h_qCWVDvtXAhQ13WNisgH4ht"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
// Wi-Fi credentials
char ssid[] = "Wokwi-GUEST"; // Replace with your Wi-Fi SSID
char pass[] = ""; // Replace with your Wi-Fi password
// DHT sensor settings
#define DHTPIN 15 // GPIO pin where the DHT22 is connected
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// Virtual Pins in the Blynk app
#define VIRTUAL_PIN_TEMP V0 // Virtual Pin for Temperature
#define VIRTUAL_PIN_HUM V1 // Virtual Pin for Humidity
void setup() {
// Start serial communication
Serial.begin(115200);
delay(100);
// Initialize the DHT sensor
dht.begin();
// Connect to Blynk
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
Serial.println("Setup complete.");
}
void loop() {
// Run Blynk
Blynk.run();
// Read data from the DHT22 sensor
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Check if the readings are valid
if (isnan(temperature) || isnan(humidity)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print values to the Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C, Humidity: ");
Serial.print(humidity);
Serial.println(" %");
// Send values to the Blynk app
Blynk.virtualWrite(VIRTUAL_PIN_TEMP, temperature);
Blynk.virtualWrite(VIRTUAL_PIN_HUM, humidity);
// Wait before the next reading
delay(2000); // Adjust the delay as needed
}