int pirPin = 4; // PIR sensor output connected to digital pin 4
int ledPin = 13; // LED connected to digital pin 13
void setup() {
pinMode(pirPin, INPUT); // Set PIR pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication at 9600 bps
}
void loop() {
int pirState = digitalRead(pirPin); // Read PIR sensor state
if (pirState == HIGH) { // If motion is detected
digitalWrite(ledPin, HIGH); // Turn on LED
Serial.println("Motion detected!"); // Print message to serial monitor
delay(1000); // Wait for 1 second
} else { // If no motion is detected
digitalWrite(ledPin, LOW); // Turn off LED
}
}