#include <LiquidCrystal.h>
// Pin configuration for the IR flame sensor
const int irSensorPin = 2; // Connect the IR sensor to digital pin 2
const int thresholdValue = 800; // Adjust this value to set the sensitivity of the sensor
// Pin configuration for the LCD
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // RS, EN, D4, D5, D6, D7
// Pin for the speaker or piezo element
const int speakerPin = 10; // Connect the speaker or piezo to digital pin 10
void setup() {
// Initialize the LCD
lcd.begin(16, 2);
// Initialize the IR sensor pin
pinMode(irSensorPin, INPUT);
// Set up the speaker pin
pinMode(speakerPin, OUTPUT);
// Set up the initial display message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Fire Detection");
}
void loop() {
// Read the value from the IR sensor
int irValue = analogRead(irSensorPin);
// Check if the IR sensor reading is above the threshold
if (irValue < thresholdValue) {
// Clear the LCD and print the "Fire detected" message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Fire detected");
// Generate a tone to create a sound
tone(speakerPin, 1000); // You can adjust the frequency as needed
// You can add additional actions here, like sending a notification.
} else {
// Clear the LCD and display a standby message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Standby");
// Turn off the tone
noTone(speakerPin);
}
// Delay for a moment to avoid rapid display updates
delay(1000);
}
#include <iostream>
#include <unistd.h>
int main() {
while (true) {
// Turn on the LED
std::cout << "LED ON\n";
// Activate the buzzer
std::cout << "Buzzer ON\n";
// Delay for 1 second
sleep(1);
// Turn off the LED
std::cout << "LED OFF\n";
// Deactivate the buzzer
std::cout << "Buzzer OFF\n";
// Delay for 1 second
sleep(1);
}
return 0;
}