#define BLYNK_TEMPLATE_ID "TMPL6SO4vqriR"
#define BLYNK_TEMPLATE_NAME "Smoke Detection kel3"
#define BLYNK_AUTH_TOKEN "Ok9BXKEZPJj3xMopDezYak6Uhhz_qyjO"
#define BLYNK_PRINT Serial
#define buzzerPin 13
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
//Blynk Authentikasi
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST"; //nama hotspot yang digunakan
char pass[] = "asdfghjklm"; //password hotspot yang digunakan
const int smokeSensorPin = 34; // Pin analog untuk sensor asap
LiquidCrystal_I2C lcd(0x27, 16, 2); // Alamat I2C dan ukuran LCD
void setup() {
Serial.begin(115200);
delay(100);
pinMode(smokeSensorPin, INPUT);
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW); // Ensure the buzzer is off initially
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); // Mengirimkan data asap ke Virtual Pin V4
Serial.print("Smoke Level: ");
Serial.println(smokeLevel);
int threshold = 900; // Sesuaikan ambang batas sesuai kebutuhan
lcd.setCursor(0, 0);
lcd.print("Smoke Level: ");
lcd.setCursor(0, 1);
lcd.print(smokeLevel);
if (smokeLevel > threshold) {
Serial.println("Smoke Detected!");
lcd.setCursor(0, 1);
// lcd.print("Safe ");
digitalWrite(buzzerPin, HIGH); // Turn ON the buzzer
delay(1000);
} else {
lcd.setCursor(0, 1);
lcd.print("Safe !");
digitalWrite(buzzerPin, LOW); // Turn OFF the buzzer
delay(1000);
}
delay(1000); // Delay untuk menghindari pembacaan yang terlalu cepat
Blynk.run();
}