#include<ESP32Servo.h>
#include<PIRSensor.h>
#define pirPIN 14
PIRSensor pir(pirPIN);
Servo myservo;
int ledpin=5;
void setup() {
myservo.attach(22);
pinMode(ledpin, OUTPUT);
pinMode(pirPIN, INPUT); // Set PIR pin as input
}
void loop() {
int motionDetected = digitalRead(pirPIN); // Read PIR sensor output
if (motionDetected == HIGH) {
// If motion is detected, activate the garage door opener
myservo.write(180);
delay(1000); // Keep servo activated for 1 second
digitalWrite(ledpin, HIGH);
delay(1000);
digitalWrite(ledpin, LOW);
delay(1000);
}
}