// Define the pin connections
const int pirPin = 12; // PIR sensor output pin
const int ledPin = 13; // LED pin
void setup() {
pinMode(pirPin, INPUT); // Set PIR pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
digitalWrite(ledPin, LOW); // Turn off LED initially
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
int pirState = digitalRead(pirPin); // Read PIR sensor state
if (pirState == HIGH) { // If motion detected
digitalWrite(ledPin, HIGH); // Turn on LED
Serial.println("Motion detected!");
delay(1000); // Wait for a second to avoid multiple detections
} else {
digitalWrite(ledPin, LOW); // Turn off LED
}
}