#define BLYNK_TEMPLATE_ID "TMPL3YrIv5777"
#define BLYNK_TEMPLATE_NAME "read"
#define BLYNK_AUTH_TOKEN "Ojc-f_0qo8ZBiM2Fj6yiWhaU8QpZu_Ye"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
#define PIN_TRIG 12
#define PIN_ECHO 13
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define DHTPIN 15
#define DHTTYPE DHT22
#define GAS_PIN 34
#define LDR_PIN 35
DHT dht(DHTPIN, DHTTYPE);
#define VPIN_TEMP V0
#define VPIN_HUM V1
#define VPIN_ULTRA V2
#define VPIN_LDR V3
void setup() {
Serial.begin(115200);
dht.begin();
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
pinMode(PIN_TRIG, OUTPUT);
pinMode(PIN_ECHO, INPUT);
}
void loop() {
Blynk.run();
sendSensorData();
delay(2000);
}
void sendSensorData() {
// DHT readings
float temp = dht.readTemperature();
float hum = dht.readHumidity();
int ldrValue = analogRead(LDR_PIN);
// Ultrasonic reading
digitalWrite(PIN_TRIG, LOW);
delayMicroseconds(2);
digitalWrite(PIN_TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(PIN_TRIG, LOW);
long duration = pulseIn(PIN_ECHO, HIGH);
int dist = duration / 58; // cm
// Debug prints
Serial.print("Distance: "); Serial.print(dist); Serial.println(" cm");
Serial.print("Temp: "); Serial.print(temp); Serial.print(" °C ");
Serial.print("Hum: "); Serial.print(hum); Serial.println(" %");
Serial.print("LDR: "); Serial.println(ldrValue);
// Send to Blynk
Blynk.virtualWrite(VPIN_TEMP, temp);
Blynk.virtualWrite(VPIN_HUM, hum);
Blynk.virtualWrite(VPIN_LDR, ldrValue);
Blynk.virtualWrite(VPIN_ULTRA, dist);
}