#include <LiquidCrystal.h>
LiquidCrystal lcd(5, 4 , 6, 7, 8, 9);
const uint PIR_PIN = 15;
const uint BUZZER_PIN = 28;
const uint LED_PIN = 27;
void setup() {
// Initialize the PIR sensor pin
pinMode(PIR_PIN, INPUT);
// Initialize the buzzer pin
pinMode(BUZZER_PIN, OUTPUT);
// Initialize the LED pin
pinMode(LED_PIN, OUTPUT);
// Initialize the LCD
lcd.begin(16, 2);
lcd.print("System Ready");
// Initialize serial communication
Serial.begin(9600);
}
void loop() {
// Read the PIR sensor
bool motionDetected = digitalRead(PIR_PIN);
if (motionDetected) {
// Motion detected
digitalWrite(BUZZER_PIN, HIGH); // Turn on buzzer
digitalWrite(LED_PIN, HIGH); // Turn on LED
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Motion detected");
Serial.println("Motion detected");
} else {
// No motion detected
digitalWrite(BUZZER_PIN, LOW); // Turn off buzzer
digitalWrite(LED_PIN, LOW); // Turn off LED
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("No motion");
Serial.println("No motion detected");
}
delay(200); // Small delay for stability
}
int main() {
setup();
while (true) {
loop();
}
}