#include <ESP32Servo.h>
Servo servoMotor;
int targetPosition = 90; // Change this to your desired position (0-180)
void setup() {
servoMotor.attach(12); // Attach the servo to pin 9
}
void loop() {
// Calculate pulse width for target position
int pulseWidth = map(targetPosition, 0, 180, 500, 2500);
servoMotor.writeMicroseconds(pulseWidth);
// Wait for servo to reach position (optional)
delay(20);
}