#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define PIR_SENSOR_PIN 2
#define LED_PIN 5 // Alert LED
#define BUZZER_PIN 4 // Buzzer
#define CAMERA_LED_PIN 14 // Simulated Camera LED
// Set the LCD address to 0x27 for a 16 chars and 2-line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
pinMode(PIR_SENSOR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(CAMERA_LED_PIN, OUTPUT);
// Initialize the LCD
lcd.init(); // Corrected this from lcd.begin() to lcd.init()
lcd.backlight(); // Turn on the backlight
Serial.begin(115200);
// Display initial message
lcd.setCursor(0, 0);
lcd.print("System Armed");
lcd.setCursor(0, 1);
lcd.print("Awaiting Motion");
}
void loop() {
int motionDetected = digitalRead(PIR_SENSOR_PIN);
if (motionDetected == HIGH) {
digitalWrite(LED_PIN, HIGH); // Alert LED ON
digitalWrite(BUZZER_PIN, HIGH); // Buzzer ON
Serial.println("Motion Detected! Alert Sent.");
// Update LCD message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Motion Detected");
lcd.setCursor(0, 1);
lcd.print("Sending Alert...");
// Simulate camera action with LED
digitalWrite(CAMERA_LED_PIN, HIGH);
Serial.println("Simulated Picture Taken.");
delay(2000); // Keep camera LED on for 2 seconds
digitalWrite(CAMERA_LED_PIN, LOW); // Turn off simulated camera LED
// After capturing, show a different message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pic Captured!");
lcd.setCursor(0, 1);
lcd.print("Owner Notified.");
} else {
digitalWrite(LED_PIN, LOW); // Alert LED OFF
digitalWrite(BUZZER_PIN, LOW); // Buzzer OFF
// Return to default message when no motion is detected
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("System Armed");
lcd.setCursor(0, 1);
lcd.print("Awaiting Motion");
}
delay(1000);
}