#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <IRremote.h> // Include the IRremote library
// Define pins
const int irReceiverPin = 9;
const int pirSensorPin = 12;
const int ldrPin = A0;
const int buzzerPin = 10;
// Set up the LCD address and dimensions
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Create an instance of IRremote library
IRrecv irrecv(irReceiverPin);
decode_results results;
void setup() {
// Initialize pins
pinMode(pirSensorPin, INPUT);
pinMode(ldrPin, INPUT);
pinMode(buzzerPin, OUTPUT);
// Initialize LCD
lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" ");
// Initialize IR receiver
irrecv.enableIRIn(); // Start the IR receiver
// Initialize Serial Monitor
Serial.begin(9600);
}
void loop() {
int pirValue = digitalRead(pirSensorPin);
int ldrValue = analogRead(ldrPin);
float ldrVoltage = ldrValue * (5.0 / 1023.0);
// Check if IR remote command is received
if (irrecv.decode(&results)) {
// Print the received command to Serial Monitor
Serial.println("Fire detected ");
//Serial.println(results.value, HEX);
// Example: If specific IR code (replace with your remote's code) is received, take action
if (results.value == 0xFFFFFFFF) { // Example IR code, replace with your remote's code
lcd.setCursor(0, 1);
lcd.println("Fire detected");
delay(2000);
lcd.clear();
}
irrecv.resume(); // Receive the next value
}
// Detect motion based on PIR sensor
bool motionDetected = (pirValue == HIGH);
bool fireDetected = (irReceiverPin == HIGH);
// Detect smoke based on LDR (Photoresistor)
bool smokeDetected = (ldrVoltage < 2.0); // Assuming low light levels due to smoke
// Display messages on LCD and activate buzzer based on sensor readings
if (motionDetected || smokeDetected) {
digitalWrite(buzzerPin, HIGH);
lcd.setCursor(0, 0);
lcd.print("Attention-smoke ");
Serial.println("Smoke Detected!");
if (motionDetected) {
Serial.println("Motion Detected!");
}
if (smokeDetected) {
Serial.println("Smoke Detected!");
}
if (fireDetected){
Serial.println("Fire Detected");
delay(100);
digitalWrite(buzzerPin, HIGH);
}
} else {
digitalWrite(buzzerPin, LOW);
lcd.setCursor(0, 0);
lcd.print("All Safe ");
Serial.println("All Safe");
}
delay(1500);
}