#define BLYNK_TEMPLATE_ID "TMPL6uAP8ts9n"
#define BLYNK_TEMPLATE_NAME "Smoke Detection"
#define BLYNK_AUTH_TOKEN "GOVyc9u85uASCe-dKVrnxnUmo2ulO26g"
#define BLYNK_PRINT Serial
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Blynk Authentication
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST"; // Hotspot name
char pass[] = ""; // Hotspot password
const int smokeSensorPin = 34; // Analog pin for the smoke sensor
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address and LCD size
void setup() {
Serial.begin(115200);
delay(100);
pinMode(smokeSensorPin, INPUT);
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Smoke Detector");
delay(2000);
lcd.clear();
}
void loop() {
int smokeLevel = analogRead(smokeSensorPin);
Blynk.virtualWrite(V4, smokeLevel); // Send smoke data to Virtual Pin V4
Serial.print("Smoke Level: ");
Serial.println(smokeLevel);
int threshold = 500; // Adjust threshold as needed
lcd.setCursor(0, 0);
lcd.print("Smoke Level: ");
lcd.setCursor(12, 0);
lcd.print(smokeLevel); // Print the smoke level value at a specific position
lcd.setCursor(0, 1);
if (smokeLevel > threshold) {
Serial.println("Smoke Detected!");
lcd.print("Smoke Detected! ");
} else {
lcd.print("Safe ");
}
delay(1000); // Delay to avoid too rapid readings
Blynk.run();
}