#include <Servo.h> //Servo library
Servo myservo; //initialize a servo object for the connected servo
int angle = 0;
void setup()
{
myservo.attach(10); // attach the signal pin of servo to pin9 of arduino
}
void loop()
{
for(angle = 0; angle < 180; angle += 1) // command to move from 0 degrees to 180 degrees
{
myservo.write(angle); //command to rotate the servo to the specified angle
delay(5);
}
for(angle =180; angle>=1; angle-=1) // command to move from 180 degrees to 0 degrees
{
myservo.write(angle); //command to rotate the servo to the specified angle
delay(5);
}
}