const int pirPin = 2; // PIR sensor pin
const int ledPin = 13; // LED pin
const int buzzerPin = 8; // Piezo buzzer pin
void setup() {
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int motion = digitalRead(pirPin); // Read PIR sensor
if (motion == HIGH) { // If motion is detected
digitalWrite(ledPin, HIGH); // Turn on the LED
tone(buzzerPin, 1000, 500); // Play a 1000Hz tone for 0.5 seconds
Serial.println("Motion detected!"); // Print message to serial monitor
} else { // If no motion is detected
digitalWrite(ledPin, LOW); // Turn off the LED
}
delay(100); // Delay for stability
}