#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup() {
// put your setup code here, to run once:
// attaches the servo on pin 9 to the servo object
myservo.attach(9);
}
void loop() {
// put your main code here, to run repeatedly:
// reads the value of the potentiometer (value between 0 and 1023)
val = analogRead(potpin);
// scale it to use it with the servo (value between 0 and 180)
val = map(val, 0, 1023, 0, 180);
// sets the servo position according to the scaled value
myservo.write(val);
// waits for the servo to get there
delay(15);
}