#include <Servo.h>
Servo servo;//create servo object toControl a servo
int pos =0; //variable to store the Servo position
void setup() {
servo.attach(9);//attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos=0;pos<=180;pos+=1){//rotate from 0 dgrees
// in steps of 1 dgrees
servo.write(pos); //tell servo to go to postion in variable 'pos'
delay(10); //waits 10ms for the servo to reach to reach the position
}
for (pos=180;pos>=0;pos-=1){// rote from 180 degree to 0 degrees
servo.write(pos); //tellservo to go to position in variable 'pos'}
delay(10); //waits10ms for the servo to reach the postio
}
}