#define PIR_PIN 2 // Pin where the PIR sensor is connected
#define BUZZER_PIN 3 // Pin where the buzzer is connected
#define LED_PIN 4 // Pin where the LED is connected
void setup() {
pinMode(PIR_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int motionDetected = digitalRead(PIR_PIN);
if (motionDetected == HIGH) {
digitalWrite(BUZZER_PIN, HIGH); // Sound the alarm
digitalWrite(LED_PIN, HIGH); // Turn on the LED
Serial.println("Motion detected!");
} else {
digitalWrite(BUZZER_PIN, LOW); // Turn off the alarm
digitalWrite(LED_PIN, LOW); // Turn off the LED
Serial.println("No motion.");
}
delay(500); // Delay for half a second
}