#define PIR_SENSOR_PIN 15 // Pin connected to the PIR sensor output
#define BUZZER_PIN 5 // Pin connected to the buzzer
void setup() {
// Initialize serial communication for debugging
Serial.begin(115200);
// Set up PIR sensor as input
pinMode(PIR_SENSOR_PIN, INPUT);
// Set up buzzer as output
pinMode(BUZZER_PIN, OUTPUT);
// Start with the buzzer off
digitalWrite(BUZZER_PIN, LOW);
Serial.println("PIR Motion Detection System Initialized");
}
void loop() {
// Read the PIR sensor's output
int motionDetected = digitalRead(PIR_SENSOR_PIN);
if (motionDetected == HIGH) {
// If motion is detected, activate the buzzer
Serial.println("Motion detected!");
digitalWrite(BUZZER_PIN, HIGH); // Turn buzzer on
delay(1000); // Keep the buzzer on for 1 second
digitalWrite(BUZZER_PIN, LOW); // Turn buzzer off
} else {
// If no motion, keep buzzer off
digitalWrite(BUZZER_PIN, LOW);
}
delay(200); // Small delay to debounce the sensor
}