#include <Servo.h>
Servo myservo; // Create servo object
int potPin = A0; // Analog pin connected to the potentiometer
int val; // Variable to store the potentiometer value
void setup() {
myservo.attach(9); // Attach servo to pin 9
}
void loop() {
val = analogRead(potPin); // Read the potentiometer value
val = map(val, 0, 1023, 0, 180); // Map the value to the servo angle range
myservo.write(val); // Set the servo position
delay(15); // Wait for the servo to reach the position
}