#include <Wire.
h>
#include <LiquidCrystal_I2C.h>
const int SENSOR_PIN = 2; // Pin connected to the PIR sensor
const int RELAY_PIN = 4; // Pin connected to the relay
const int BUZZER_PIN = 5; // Pin connected to the buzzer
const int LED_PIN = 6; // Pin connected to the LED
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C LCD with address 0x27 and 16x2 size
void setup() {
Serial.begin(9600); // Initialize Serial Monitor
Serial.println("Sir Pa Check");
Serial.println("HC-SR501 sensor with relay, buzzer, and LED");
pinMode(SENSOR_PIN, INPUT); // Set PIR sensor pin as INPUT
pinMode(RELAY_PIN, OUTPUT); // Set relay pin as OUTPUT
pinMode(BUZZER_PIN, OUTPUT); // Set buzzer pin as OUTPUT
pinMode(LED_PIN, OUTPUT); // Set LED pin as OUTPUT
// Initialize the LCD
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("SCP-69 Motion");
lcd.setCursor(0, 1);
lcd.print(" Detector");
delay(3000);
lcd.clear();
}
void loop() {
int motion = digitalRead(SENSOR_PIN); // Read the PIR sensor
if (motion) {
Serial.println("Motion Detected");
// Activate relay, buzzer, and LED
digitalWrite(RELAY_PIN, LOW); // Turn relay ON (LOW to activate, HIGH to
deactivate)
digitalWrite(BUZZER_PIN, HIGH); // Turn buzzer ON
digitalWrite(LED_PIN, HIGH); // Turn LED ON
// Display "Motion detected" on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Motion Detected!");
} else {
Serial.println("Limbo");
// Deactivate relay, buzzer, and LED
digitalWrite(RELAY_PIN, HIGH); // Turn relay OFF
digitalWrite(BUZZER_PIN, LOW); // Turn buzzer OFF
digitalWrite(LED_PIN, LOW); // Turn LED OFF
// Display "No motion detected" on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Sir ");
lcd.setCursor(0, 1);
lcd.print(" Pa Check ");
delay(500); // Small delay to stabilize sensor readings