#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potPin = A0; // analog pin used to connect the potentiometer
int potValue = 0; // variable to store the value read from the potentiometer
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
// Read the value of the potentiometer
potValue = analogRead(potPin);
// Map the potentiometer value from 0-1023 to the servo angle range (0-180)
int servoAngle = map(potValue, 0, 1023, 0, 180);
// Set the servo position based on the mapped value
myservo.write(servoAngle);
// Delay for smoother operation (adjust as needed)
delay(15);
}