#include <ESP32Servo.h>
#define POTENTIOMETER_PIN 36 // ESP32 pin GPIO36 (ADC0) connected to Potentiometer pin
#define SERVO_PIN 26 // ESP32 pin GPIO26 connected to Servo Motor's pin
#define ANALOG_THRESHOLD 1000
Servo servo; // create servo object to control a servo
void setup() {
// set the ADC attenuation to 11 dB (up to ~3.3V input)
analogSetAttenuation(ADC_11db);
servo.attach(SERVO_PIN); // attaches the servo on pin 9 to the servo object
servo.write(0);
}
void loop() {
int analogValue = analogRead(POTENTIOMETER_PIN); // read the input on analog pin
if (analogValue > ANALOG_THRESHOLD)
servo.write(90); // rotate servo motor to 90 degree
else
servo.write(0);} // rotate servo motor to 0 degree