Servo stops suddenly?

I’m trying to convert my parallax Boe Bot into a Arduino Due version. Unfortunately I’m running into something I cannot explain. The servos start to rotate as expected, but after a few seconds the right servo just stops while the other one keeps running. I cannot find a reason for this, even the ‘’ tells me it’s running at full speed. What could be the cause of this? I’ve unplugged the USB connection and connected it to a wall outlet but the results are the same.

#include <Servo.h>

Servo pingServo;
Servo leftServo;
Servo rightServo;

int pos = 90;    // variable to store the servo position 
boolean countUpwards = true;

unsigned long currentTime;
unsigned long loopTime;

const int PIN_PING_SERVO = 8;
const int PIN_LEFT_SERVO = 10;
const int PIN_RIGHT_SERVO = 9;
const int PIN_PING = 31;
const int PIN_PUSH_BUTTON = 53;

int distancesByAngle[] = {};
int distance = 999;
int oldButtonState = 0;

boolean buttonPressed = false;
boolean programActive = false;

void setup() 




void loop() 
  int buttonState = digitalRead(PIN_PUSH_BUTTON);
  currentTime = millis();
  if(currentTime >= (loopTime + 500)){  
      pos = pos + 20;

        countUpwards = false;
      pos = pos - 20;

        countUpwards = true;

    distance = checkDistance();
    distancesByAngle[pos] = distance;

    loopTime = currentTime;  // Updates loopTime
  oldButtonState = buttonState;

long checkDistance(){
  // establish variables for duration of the ping, 
  // and the distance result in inches and centimeters:
  long duration, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(PIN_PING, OUTPUT);
  digitalWrite(PIN_PING, LOW);
  digitalWrite(PIN_PING, HIGH);
  digitalWrite(PIN_PING, LOW);

  pinMode(PIN_PING, INPUT);
  duration = pulseIn(PIN_PING, HIGH);

  cm = microsecondsToCentimeters(duration);

  //Serial.print("cm on pos: ");
  return cm;

void fullStop(){
  //Serial.println("FULL STOP"); 

void moveForward(){
  Serial.print("rightServo: ");
  Serial.print(", leftServo: ");

void moveRight(){

long microsecondsToCentimeters(long microseconds)
  return microseconds / 29 / 2;

from your description and picture I cannot see thatnyou have a separate power source for the servos, if not try this as a solution - check th btwo links in my signature for more details.

Duane B

You probably need decoupling on the supply. It sounds like the interference from the motor is screwing with the code.

Ah now it's starting to make sense, I thought the the external power connector on the board would be the decoupled power source, but obviously it's not. So if I set my wall wart to 5V and connect it to my breadboard and power the servo's from there it should work right?

check th btwo links in my signature for more details.

Since I followed your servo tutorial link Duane, in the last two days I've pointed 2-3 members there. It explains stuff really clearly, thanks.

Motors tend to need more decoupling than most other components:-