#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int LED_PIN = 19; // Input pin for LED
int PIR_PIN = 4; // Input pin for PIR sensor
int BUZZER_PIN = 2; // Input pin for Buzzer
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust the address based on your LCD module
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT); // Declare PIR sensor as input
pinMode(LED_PIN, OUTPUT); // Declare LED as output
pinMode(BUZZER_PIN, OUTPUT); // Declare Buzzer as output
lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
}
void loop() {
int pirValue = digitalRead(PIR_PIN); // Read input value
if (pirValue == HIGH) { // Check if the input is HIGH
digitalWrite(LED_PIN, HIGH); // Turn LED ON
Serial.println("Motion Detected");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Motion Detected!");
activateBuzzer();
delay(1000);
}
else {
digitalWrite(LED_PIN, LOW); // Turn LED OFF
Serial.println("No Motion Detected");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("No Motion Detected");
deactivateBuzzer();
delay(1000);
}
}
void activateBuzzer() {
digitalWrite(BUZZER_PIN, HIGH); // Turn the Buzzer ON
// You can add additional actions here if needed
}
void deactivateBuzzer() {
digitalWrite(BUZZER_PIN, LOW); // Turn the Buzzer OFF
// You can add additional actions here if needed
}