void setup() {
pinMode(8, INPUT); // Set the PIR pin as an input
pinMode(13, OUTPUT); // Set the LED pin as an output
pinMode(3, OUTPUT); // Set the Buzzer pin as an output
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
int val = digitalRead(8); // Read PIR sensor value
if (val == HIGH) { // Check if motion is detected
digitalWrite(13, HIGH); // Turn on the LED
tone(3, 1000);
Serial.println("Motion detected!"); // Print message to the serial monitor
} else {
digitalWrite(13, LOW); // Turn off the LED
Serial.println("No Motion detected!"); // Print message to the serial monitor
noTone(3);
}
delay(1000);
}