int pirPin = 2; // PIR sensor output connected to digital pin 2
int ledPin = 13; // LED connected to digital pin 13
void setup() {
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int motionDetected = digitalRead(pirPin);
if (motionDetected == HIGH) {
Serial.println("Motion detected!");
digitalWrite(ledPin, HIGH); // Turn on the LED
delay(1000); // Wait for a second
} else {
Serial.println("No motion");
digitalWrite(ledPin, LOW); // Turn off the LED
}
}