#define BLYNK_TEMPLATE_ID "TMPL3PiOwaDrx"
#define BLYNK_TEMPLATE_NAME "Annal D"
#define BLYNK_AUTH_TOKEN "vS3AtpEVY1no4YBsZwMB5XFRb5hXXxAT"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include<WiFiClient>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <NewPing.h>
#include <BlynkSimpleEsp32.h>
#include <TinyGPS++.h>
// Blynk Auth Token
char auth[] = "vS3AtpEVY1no4YBsZwMB5XFRb5hXXxAT";
// Your WiFi credentials.
char ssid[] = "Wokwi-Guest";
char pass[] = "";
// OLED display settings
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Ultrasonic sensor settings
#define TRIGGER_PIN 5
#define ECHO_PIN 18
#define MAX_DISTANCE 400
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
// NTC temperature sensor pin
#define TEMP_PIN 34
const int Buzzer = 15;
float temperature = 0;
// GPS module
TinyGPSPlus gps;
HardwareSerial gpsSerial(2);
// Blynk virtual pins
#define V_DISTANCE V1
#define V_TEMPERATURE V2
#define V_LATITUDE V3
#define V_LONGITUDE V4
void setup() {
Serial.begin(115200);
gpsSerial.begin(9600, SERIAL_8N1, 16, 17); // RX=16, TX=17
Blynk.begin(auth, ssid, pass);
// Initialize the OLED display
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display();
delay(2000);
display.clearDisplay();
pinMode(Buzzer, OUTPUT);
}
void loop() {
Blynk.run();
while (gpsSerial.available() > 0) {
gps.encode(gpsSerial.read());
}
// Measure distance using the ultrasonic sensor
unsigned int distance = sonar.ping_cm();
Blynk.virtualWrite(V_DISTANCE, distance);
// Measure temperature using the NTC sensor
int sensorValue = analogRead(TEMP_PIN);
float voltage = sensorValue * (3.3 / 4095.0);
temperature = (voltage - 0.5) * 100; // Convert to Celsius
Blynk.virtualWrite(V_TEMPERATURE, temperature);
// Check if temperature exceeds a threshold
if (temperature > 50) { // Example threshold for overcharge detection
digitalWrite(Buzzer, HIGH); // Turn on the buzzer
} else {
digitalWrite(Buzzer, LOW); // Turn off the buzzer
}
// Display data on the OLED screen
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Distance: ");
display.print(distance);
display.println(" cm");
display.print("Temp: ");
display.print(temperature);
display.println(" C");
if (gps.location.isValid()) {
float latitude = gps.location.lat();
float longitude = gps.location.lng();
Blynk.virtualWrite(V_LATITUDE, latitude);
Blynk.virtualWrite(V_LONGITUDE, longitude);
display.print("Lat: ");
display.print(latitude, 6);
display.println();