#define BLYNK_TEMPLATE_ID "TMPL3OKdUURnq"
#define BLYNK_TEMPLATE_NAME "EV Monitoring"
#define BLYNK_AUTH_TOKEN "0oaSoQ1Ou9q2--JitDXvoleOfEAoifRy"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHTesp.h"
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
const int DHT_PIN = 15;
DHTesp dhtSensor;
const int pir = 23;
// Potentiometer is connected to GPIO 34 (Analog ADC1_CH6)
const int potPin = 34;
// variable for storing the potentiometer value
int potValue = 0;
BlynkTimer timer;
void setup() {
Serial.begin(115200);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
pinMode(pir, INPUT);
timer.setInterval(1000L, sendData); // Send sensor data every 1 second
Serial.println("Hello, ESP32!");
}
void sendData() {
// Read temperature
float t = dhtSensor.getTemperature();
if (isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
} else {
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" °C");
Blynk.virtualWrite(V2, t); // Send temperature data to Blynk
}
// Read PIR sensor
int motionDetected = digitalRead(pir);
Serial.print("Motion Detected: ");
Serial.println(motionDetected);
Blynk.virtualWrite(V1, motionDetected); // Send PIR sensor data to Blynk
// Read potentiometer
potValue = analogRead(potPin);
float volts = (potValue / 4096.0)*100;
Serial.print("Battery Health: ");
Serial.println(volts);
Blynk.virtualWrite(V0, volts); // Send potentiometer data to Blynk
}
void loop() {
Blynk.run();
timer.run();
}