#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Some LCDs use 0x3F
const byte gasPin = A0;
const byte buzzerPin = 8;
const int alertThreshold = 400; // Example only; tune safely
void setup() {
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW);
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(“Fire/Smoke Demo”);
lcd.setCursor(0, 1);
lcd.print(“Sensor warming”);
delay(2000);
}
void loop() {
int gasValue = analogRead(gasPin);
bool alert = gasValue >= alertThreshold;
Serial.println(gasValue);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(alert ? “ALERT: CHECK AIR” : “Status: NORMAL”);
lcd.setCursor(0, 1);
lcd.print(“Sensor: “);
lcd.print(gasValue);
digitalWrite(buzzerPin, alert ? HIGH : LOW);
delay(500);
}
Leave a Reply