#include // see http://arduino.cc/en/Reference/Servo Servo servo1; int angle[4]; void setup() { Serial.begin(9600); servo1.attach(9, 500, 2200); angle[0]=30; angle[1]=45; angle[2]=90; angle[3]=0; } int count=0; int count2=0; // we change the angle of the motor every second void loop() { count++; int w=500; if(count==50){ // every second, because we sleep 20 ms every loop count=0; count2++; if(count2==4) count2=0; Serial.print(count2); Serial.print(" "); Serial.println(angle[count2]); } servo1.write(angle[count2]); delay(20); }