Servo motor time rotation not consistent.

Hi all, i am new to arduino. Please help.

I want my servo motor to rotate 90 degree and after 3 seconds it will turn back to its original position which is -90 degree. It will turn 90 degree and turn back perfectly but not in excalty 3 seconds. Sometimes takes 5 seconds, 3, seconds, 7 seconds. Why ?? Below is my simple coding.

#include <Servo.h>

Servo myservo; // create servo object to control a servo

void setup()
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600); //begins serial communication

void loop()
int pos;
if (Serial.available()>0){; //reads the value sent from Visual Basic


myservo.write(-90); //rotates the servo 90 degrees (right)
delay (3000);


Maybe the turn command is received during the delay, when the processor is twiddling its metaphoric thumbs.

Please use code tags when posting code

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

myservo.write(position) position is 0 to 180 it tells the servo what position to got to, not how to get there.

try 90 and 0 not -90

Thanks.. Tom.. :)