#include <Servo.h>
Servo myservo; // create Servo object to control a servo
int potpin = A0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int pos=0;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the Servo object
}
void loop() {
for (pos =0; pos<=180; pos+=1){
myservo.write(pos);
delay(15);
}
for(pos=180; pos>=0; pos-=1){
myservo.write(pos);
delay(15);
}
}