#define PIR_SENSOR_PIN 2 // Pin connected to the PIR sensor output
#define LED_PIN 15 // Pin connected to the LED
#define BUZZER_PIN 4 // Pin connected to the Buzzer
void setup() {
Serial.begin(115200); // Initialize serial communication
pinMode(PIR_SENSOR_PIN, INPUT); // Set PIR sensor pin as input
pinMode(LED_PIN, OUTPUT); // Set LED pin as output
pinMode(BUZZER_PIN, OUTPUT); // Set Buzzer pin as output
digitalWrite(LED_PIN, LOW); // Ensure LED is off initially
digitalWrite(BUZZER_PIN, LOW); // Ensure Buzzer is off initially
}
void loop() {
int sensorValue = digitalRead(PIR_SENSOR_PIN); // Read the PIR sensor value
if (sensorValue == HIGH) {
// Motion detected
Serial.println("Motion detected!");
// Turn on LED and buzzer
digitalWrite(LED_PIN, HIGH);
digitalWrite(BUZZER_PIN, HIGH);
delay(1000); // Keep the alarm on for 1 second
// Turn off LED and buzzer
digitalWrite(LED_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
} else {
// No motion detected
Serial.println("No motion detected");
}
delay(500); // Check the PIR sensor every 500 milliseconds
}