#include <Servo.h>
// Define the analog pin for the potentiometer
const int potentiometer = A0;
// create servo object to control a servo
Servo myServo;
void setup() {
// attaches the servo on pin 9 to the servo object
myServo.attach(9);
}
void loop()
{
// reads the value of the potentiometer (value between 0 and 1023)
int analogValue = analogRead(potentiometer);
// scales it to use it with the servo (value between 0 and 180)
int angle = map(analogValue, 0, 1023, 0, 180);
// sets the servo position according to the scaled value
myServo.write(angle);
// waits for the servo to reach the position
delay(100);
}