#define PIR_PIN 25
#define LED_PIN 17
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(PIR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
Serial.println("Motion Detector");
}
void loop() {
// Check whether motion is detected or not
bool motionDetected = digitalRead(PIR_PIN);
if (motionDetected) {
Serial.println("Motion Detected");
// After detecting the motion trun on the LED and after 5 seconds trun off the LED
digitalWrite(LED_PIN, HIGH);
Serial.println("LED ON");
delay(5000);
Serial.println("LED OFF");
digitalWrite(LED_PIN, LOW);
delay(1000);
}
}