// Pin definitions
const int pirPin = 8; // PIR sensor output pin
const int ledPin = 9; // LED pin
void setup() {
pinMode(pirPin, INPUT); // Set PIR sensor pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
int motionState = digitalRead(pirPin); // Read the state of PIR sensor
if (motionState == HIGH) { // If motion is detected
digitalWrite(ledPin, HIGH); // Turn on the LED
Serial.println("Motion detected!");
delay(1000); // Delay for stability (optional)
} else { // If no motion is detected
digitalWrite(ledPin, LOW); // Turn off the LED
Serial.println("No motion detected");
delay(500); // Delay for stability (optional)
}
}