#include <ESP32Servo.h>
Servo servo; // create servo object to control a servo
int potpin = 34; // analog pin used to connect the potentiometer
int angle; // variable to read the value from the analog pin
int analog_value;
void setup() {
servo.attach(13); // attaches the servo on pin 9 to the servo object
}
void loop() {
analog_value = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
angle = map(analog_value, 0, 4095, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo.write(angle);
Serial.print("Analog: ");
Serial.print(analog_value);
Serial.print(angle);
delay(100); // sets the servo position according to the scaled value
// waits for the servo to get there
}