#include <Wire.h> // Include the Wire library for I2C
#include <LiquidCrystal_I2C.h> // Include the LCD library
LiquidCrystal_I2C lcd(0x27, 16, 2); // Initialize the LCD with I2C address 0x27, 16 columns, and 2 rows
void setup() {
pinMode(9, INPUT); // Set pin 13 as input for the fire sensor
pinMode(8, OUTPUT); // Set pin 25 as output for the alarm
Serial.begin(9600); // Initialize serial communication at 9600 baud
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
lcd.setCursor(0, 0); // Set cursor to column 0, row 0
lcd.print("Fire detection");
lcd.setCursor(3, 1); // Set cursor to column 3, row 1
lcd.print("projects");
delay(2000); // Wait for 2 seconds
}
void loop() {
lcd.clear(); // Clear the LCD display
int val = digitalRead(8); // Read the value from pin 13
Serial.println(val); // Print the value to the serial monitor
if (val == 0) {
Serial.println("Fire detected"); // Print to serial monitor if fire is detected
digitalWrite(8, HIGH); // Turn on the alarm
lcd.setCursor(5, 0); // Set cursor to column 5, row 0
lcd.print("Alert");
lcd.setCursor(2, 1); // Set cursor to column 2, row 1
lcd.print("Fire Detected");
} else {
Serial.println("No Fire"); // Print to serial monitor if no fire is detected
digitalWrite(8, LOW); // Turn off the alarm
lcd.setCursor(5, 0); // Set cursor to column 5, row 0
lcd.print("Safe");
lcd.setCursor(0, 1); // Set cursor to column 0, row 1
lcd.print("No Fire Detected");
}
delay(1000); // Wait for 1 second
}