#include <LiquidCrystal_I2C.h>
// Pin configuration
const int flameSensorPin = 2; // Connect the flame sensor to digital pin 2
const int ledPin = 13; // Connect the LED to digital pin 13
const int analogPin = A0; // Connect the flame sensor analog output to analog pin A0
// LCD configuration
LiquidCrystal_I2C lcd(0x27, 16, 2); // Address 0x27, 16 columns, 2 rows
void setup() {
pinMode(flameSensorPin, INPUT);
pinMode(ledPin, OUTPUT);
lcd.begin(16, 2);
lcd.print("Flame Detector");
delay(2000);
lcd.clear();
}
void loop() {
// Read the flame sensor value
int flameSensorValue = digitalRead(flameSensorPin);
int analogValue = analogRead(analogPin);
// Display flame status on LCD
lcd.setCursor(0, 0);
lcd.print("Flame: ");
lcd.print(flameSensorValue == LOW ? "Detected" : "Not Detected");
// Display analog value on LCD
lcd.setCursor(0, 1);
lcd.print("Voltage: ");
lcd.print(analogValue);
// Check if fire is detected (flame sensor value is LOW when fire is detected)
if (flameSensorValue == LOW) {
Serial.println("Fire detected! Turning on the LED.");
digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
Serial.println("No fire detected. Turning off the LED.");
digitalWrite(ledPin, LOW); // Turn off the LED
}
delay(1000); // Add a small delay to avoid rapid LCD updates
lcd.clear(); // Clear the LCD for the next iteration
}