#include <Servo.h>
Servo servo;
int potentiometerPin = A0;
int servoPin = 9;
int servoPos = 0;
void setup() {
servo.attach(servoPin);
}
void loop() {
int potValue = analogRead(potentiometerPin);
int angle = map(potValue, 0, 1023, 0, 180); // Map potentiometer value to servo angle (0-180)
servo.write(angle); // Move the servo to the new position
servoPos = angle; // Update the servo position variable
delay(50); // Delay for stability, you can adjust this value if needed
}