#include <ESP32Servo.h>
const int servoPin = 18;
Servo servo;
int pos=0;
void setup() {
Serial.begin(115200);
pinMode(4, INPUT);
servo.attach(servoPin, 500, 2400);
}
void loop() {
int a=digitalRead(4);
if (a==HIGH)
{
Serial.println("motion detected activating servo");
for (pos = 0; pos <= 180; pos += 1) {
servo.write(pos);
delay(10);
}
}
}