#define BLYNK_TEMPLATE_ID "TMPL3x9H7-Sit"
#define BLYNK_TEMPLATE_NAME "PROJECT"
#define BLYNK_AUTH_TOKEN "3nS7CxKkAiAkUSbnozj19mlehFfel2wI"
#include <WiFi.h>
#include <WiFiClient.h>
#include <Wire.h>
#include <BlynkSimpleEsp32.h>
#include <LiquidCrystal_I2C.h>
#include <NewPing.h>
// Blynk credentials
char auth[] = "3nS7CxKkAiAkUSbnozj19mlehFfel2wI"; // Replace with your Blynk auth token
char ssid[] = "Wokwi-GUEST"; // Replace with your WiFi SSID
char pass[] = ""; // Replace with your WiFi password
// LCD configuration
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust address if needed
// Ultrasonic sensor configuration
#define TRIGGER_PIN 17
#define ECHO_PIN 18
#define MAX_DISTANCE 400
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
// Temperature sensor and voltage divider configuration
#define TEMP_PIN 34
#define VOLTAGE_PIN 32
const int Buzzer = 19;
float temperature = 0;
float batteryVoltage = 0;
// Virtual pins for Blynk
#define V_DISTANCE V1
#define V_TEMPERATURE V2
#define V_VOLTAGE V3
void setup() {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass); // Initialize Blynk
// Initialize the LCD
lcd.begin(16, 2);
lcd.init();
lcd.backlight();
lcd.clear();
pinMode(Buzzer, OUTPUT);
}
void loop() {
Blynk.run(); // Run Blynk
// Get distance from the ultrasonic sensor
unsigned int distance = sonar.ping_cm();
Blynk.virtualWrite(V1, distance);
// Get temperature from the analog sensor
int tempSensorValue = analogRead(TEMP_PIN);
float tempVoltage = tempSensorValue * (3.3 / 4095.0);
temperature = (tempVoltage - 0.5) * 100; // Convert to Celsius
Blynk.virtualWrite(V2, temperature);
// Get battery voltage from the voltage divider
int voltageSensorValue = analogRead(VOLTAGE_PIN);
batteryVoltage = voltageSensorValue * (3.3 / 4095.0) * 2; // Adjust the factor according to the voltage divider
Blynk.virtualWrite(V3, batteryVoltage);
// Check for overcharge condition
if (temperature > 50) {
while(temperature>50){
digitalWrite(Buzzer, HIGH);
delay(2000);}
digitalWrite(Buzzer,LOW);
delay(200);
} else {
digitalWrite(Buzzer, LOW);
}
// Display data on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Dist: ");
lcd.print(distance);
lcd.print(" cm");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
lcd.setCursor(8, 1);
lcd.print("Volt: ");
lcd.print(batteryVoltage);
lcd.print(" V");
delay(1000);
}