Issues with continuous rotation servos

I’m trying to control 4 continuous rotation servos (spring rc sm-s3317SR) with arduino. i have simple code to make them all turn in a sequence for actuating something. for some reason, the system fails halfway through the code, and the arduino shuts off and then turns back on again, restarting the code, only to fail once more. im powering it from my computer, so I hear the tell-tale sound of the usb connection being lost every time this occurs.

The code is as follows:
#include <Servo.h>

Servo two;
Servo three;
Servo four;
Servo five;

int d = 200;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);

two.attach(2);
three.attach(3);
four.attach(4);
five.attach(5);

two.write(90);
three.write(90);
four.write(90);
five.write(90);

spin();
}

void spin() {
two.write(120);
delay(d);
two.write(60);
three.write(120);
delay(d);
two.write(90);
three.write(60);
four.write(120);
delay(d);
three.write(90);
four.write(60);
five.write(120);
delay(d);
four.write(90);
five.write(60);
delay(d);
five.write(90);
}

I’d like to think there’s nothing wrong with the code and that there’s some sort of powering issue with the servos (i’m powering them all from the 5V output of the arduino). Is this correct?

Thanks

(i'm powering them all from the 5V output of the arduino). Is this correct?

No. You will damage your Arduino.

LarryD:

(i'm powering them all from the 5V output of the arduino). Is this correct?

No. You will damage your Arduino.

In this case the limiting factor is probably the USB port. USB 2.0 specifies 500ma maximum (USB 3.0 900ma). But even if the USB port did supply enough power it would be probable to see glitches; the Arduino just isn't designed to handle the load you're putting on it. The SOT223 linear regulator is 800ma max (Uno R3).

Chances are you have destroyed part or all of your Arduino. If you are using servos connect them like this…

servo-wire.jpg

The servos should be perfectly happy with 6v instead of 5, meaning 4 AA batteries can be a convenient external power supply.

The issue you were having was the arduino browning out; the motors drew too much current, starving the chip, and causing it to reset.