#include <ESP32Servo.h>
Servo myServo; // Create a servo object
const int potPin = 13; // Analog pin connected to the potentiometer
const int servoPin = 32; // Digital pin connected to the servo motor
int potValue; // Variable to store the potentiometer reading
int servoPos; // Variable to store the calculated servo position
void setup() {
Serial.begin(9600); // Initialize serial communication for debugging (optional)
myServo.attach(servoPin); // Attach the servo to the specified pin
}
void loop() {
potValue = analogRead(potPin); // Read the analog value from the potentiometer
// Map the potentiometer value (0-4095) to a servo position (0-180 degrees)
servoPos = map(potValue, 0, 4095, 0, 180);
// Write the calculated position to the servo motor
myServo.write(servoPos);
// Optional: Print the potentiometer value and servo position for debugging
Serial.print("Potentiometer value: ");
Serial.println(potValue);
Serial.print("Servo position: ");
Serial.println(servoPos);
delay(15); // Add a small delay to avoid overwhelming the servo
}