Servo and Serial control

While using serial control for servos it stop working after 2 or 3 instructions send Please help me out below is the code

#include <Servo.h>

Servo servoLeft; // Define left servo
Servo servoRight; // Define right servo

void setup() {
servoLeft.attach(10); // Set left servo to digital pin 10
servoRight.attach(9); // Set right servo to digital pin 9
Serial.begin(9600);
}

void loop() {
if(Serial.available())
{

char x=Serial.read();
if(x=='s')
{
forward(); // Example: move forward
delay(2000);

} // Wait 2000 milliseconds (2 seconds)
/* reverse();
delay(2000);
turnRight();
delay(2000);
turnLeft();
delay(2000);*/
if(x=='p')
{
stopRobot();
delay(2000);

}

}
}

We need to see all of the code...

Just a guess at this stage but If 'forward()' drives the servo to it's limit then it'll be at it's limit...

Also, if you want your system to be responsive you will need to get rid of all the delay()s and use millis() to manage timing as illustrated in several things at a time.

...R

here is the complete code.
If a single servo is connected it works but after connecting two it stops working after 2 or 3 commands

#include <Servo.h>

Servo servoLeft; // Define left servo
Servo servoRight; // Define right servo

void setup() {
servoLeft.attach(10); // Set left servo to digital pin 10
servoRight.attach(9); // Set right servo to digital pin 9
Serial.begin(9600);
}

void loop() {
if(Serial.available())
{

char x=Serial.read();
if(x=='s')
{
forward(); // Example: move forward
delay(2000);

} // Wait 2000 milliseconds (2 seconds)
/* reverse();
delay(2000);
turnRight();
delay(2000);
turnLeft();
delay(2000);*/
if(x=='p')
{
stopRobot();
delay(2000);

}

}
}

// Motion routines for forward, reverse, turns, and stop
void forward() {
servoLeft.write(60);
servoRight.write(120);
}

/*void reverse() {
servoLeft.write(180);
servoRight.write(0);
}

void turnRight() {
servoLeft.write(180);
servoRight.write(180);
}
void turnLeft() {
servoLeft.write(0);
servoRight.write(0);
}*/

void stopRobot() {
servoLeft.write(90);
servoRight.write(90);
}

If a single servo is connected it works but after connecting two it stops working after 2 or 3 commands

Read #7 below about how to post your code. How are you powering your servos? Powering them from the arduino will not work if that is what you are doing.

http://forum.arduino.cc/index.php/topic,148850.0.html

OK thanks