#include <Servo.h> //Include library to work with Servo motor
//Create Servo object, used to control a Servo (access functions, etc)
Servo myServo; //12 Servo objects can be created on most boards
//Define variable to store the Servo position, to rotate Servo in loop()
int pos = 0;
//setup code, to run once:
void setup() {//setup
//Establish a serial connection between Arduino and another device
//In this case, this means the serial port can transfer up to 9600 bits/sec
Serial.begin(9600); //Typically used with a USB cable, also known as a
//...Universal *Serial* Bus cable.
//The baud rate (the rate at which signals can change)
//...is set to 9600 pulses/sec, and it must be the same
//...rate as set on the receiving device
//Attach the Servo on pin 9 to the Servo object
myServo.attach(9);
}//setup
//main code, to run repeatedly:
void loop() {//loop
//Rotate the geared motor (Servo) from 0 to 180 degrees, in
//...steps of 1 degree each iteration
for(pos = 0; pos <= 180; pos += 1) {//for
myServo.write(pos); //Tell Servo to go to the position in variable "pos"
delay(15); //Then wait 15ms for Servo to reach the above position
}//for
//Rotate Servo from 180 degrees back to 0 degrees
for(pos = 180; pos >= 0; pos -= 1) {//for
myServo.write(pos);
delay(15);
}//for
}//loop