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