program does not run correctly after USB cable is un-plugged.

The following program runs correctly after it is downloaded. However, after I unplug the USB cable, the program just executes the “fwd();” part of the loop.
Thanks in advance for any assistance.
Ed

// Robot_Motion_2
#include <Servo.h>

Servo rightservo;
Servo leftservo;

void setup()
{
rightservo.attach(9);
rightservo.write(90);
leftservo.attach(10);
leftservo.write(90);
delay(20);
}

void loop()
{
fwd();
rev();
right();
left();
}

void fwd()
{
rightservo.write(0);
leftservo.write(180);
delay(1000);
rightservo.write(90);
leftservo.write(90);
delay(1000);
}

void rev()
{
rightservo.write(180);
leftservo.write(0);
delay(1000);
rightservo.write(90);
leftservo.write(90);
delay(1000);
}

void right()
{
rightservo.write(180);
leftservo.write(180);
delay(400);
rightservo.write(90);
leftservo.write(90);
delay(1000);
}

void left()
{
rightservo.write(0);
leftservo.write(0);
delay(400);
rightservo.write(90);
leftservo.write(90);
delay(1000);
}

How are things wired? What is the voltage on 5V pin when the USB is unplugged?

The voltage on the 5V pin is 5.0V. When the USB is un-plugged, the servos run exactly the same, except for only responding to the first statement in the loop, which it does over and over again until I switch off the batteries. Ed

  • Show us an image of your setup.
  • The servos should be powered by an external powersupply