Code to move the servo motor

Try the following test sketch; where the shaft moves by 2 degrees in every second.

#include <Servo.h>
Servo myservo;
byte n = 0;

void setup()
{
  myservo.attach(9); //signal line of Servi is with DPin-9
  myservo.write(0);  //initial position of Servo at 0 degrees.
}

void loop()
{
  unsigned long prMillis = millis();
  while(millis() - prMillis<1000UL)
  {
    ;
  }
  n = n+2;  //1-sec has elapsed; turn servo by 2 degrees
  myservo.write(n);
  if(n == 180)    //Servo has reached at 180 degrees position; reset to 0 position
  {
    myservo.write(0);
    n = 0;
  }
}