const int PIR_PIN = 27; // PIR sensor pin (digital pin 2)
const int LED_PIN = 0; // LED pin (digital pin 0)
void setup() {
pinMode(PIR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW); // Turn off LED initially
Serial.begin(9600);
}
void loop() {
if (digitalRead(PIR_PIN)) { // PIR sensor detects motion
digitalWrite(LED_PIN, HIGH); // Turn on the LED
Serial.println("Motion detected!");
delay(1000); // LED remains on for 1 second
digitalWrite(LED_PIN, LOW); // Turn off the LED
}
delay(1000); // Wait between readings
}