#define PIR_PIN 4 // PIR sensor OUT connected to GPIO 4
#define LED_PIN 2 // LED connected to GPIO 2
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT); // Set PIR sensor as input
pinMode(LED_PIN, OUTPUT); // Set LED as output
digitalWrite(LED_PIN, LOW); // Ensure LED is off
Serial.println("Starting PIR sensor test. Waiting 30 seconds for warm-up...");
delay(30000); // Wait 30 seconds for sensor to stabilize
Serial.println("PIR sensor is warmed up. Begin motion detection.");
}
void loop() {
int sensorValue = digitalRead(PIR_PIN);
Serial.print("PIR Reading: ");
Serial.println(sensorValue);
if (sensorValue == HIGH) {
Serial.println("🚨 Motion Detected!");
digitalWrite(LED_PIN, HIGH); // Turn on LED when motion is detected
delay(1000); // Keep LED on for 1 second
digitalWrite(LED_PIN, LOW); // Turn off LED after 1 second
}
delay(500); // Short delay for stability
}