Protecting USB from excessive current when using a GWS S03N STD servo

I have written a small program to control a GWS S03N STD servo (posted at bottom of message with instructions) and installed it on my Arduino. Anyway, it worked fine, but when I reconnected my Arduino to my PC USB hub after a few days the hub burned out.

Now, I dont know if the Arduino caused this or not (possible short in the motor might cause 5V to connect to ground?) but just in case, I would like to prevent the same thing happening again. I have some 500mA fast fuses, would connecting one of these between the Arduino ground pin and the motor ground cable be sufficient protection against excessive current to protect a USB hub, while still allowing the motor enough current to function?

#define SERVO 2

unsigned long startTime;
unsigned long currentTime;
char val[4];
int a = 1000;

int data =0;

void setup()
{
  Serial.begin(9600);

  pinMode(2, OUTPUT);
  
  startTime = millis();
}

void loop()
{
  
  while(Serial.available() > 0)
  {
    val[0] = Serial.read(); 
    if(val[0] == '#')
      {
        Serial.println("# received: ");
        val[0] = Serial.read();
        val[1] = Serial.read();
        val[2] = Serial.read();
        val[3] = Serial.read();
      }
    a = atoi(val);
    Serial.println(a, DEC);
  }
  
  servoPulse((unsigned int) a);

}

void servoPulse(unsigned int pulseLength) //in microseconds
{
  digitalWrite(SERVO, HIGH);
  
  delayMicroseconds(pulseLength);
  
  digitalWrite(SERVO, LOW);
  
  delayMicroseconds(3001 - pulseLength);
  
  delay(15);
  
}

To use the above code, attach the red motor cable to 5V, the black motor cable to Gnd and the white motor cable (control) to pin 2. (On reflection, it might be wiser to connect the 5V (red) and ground (black) motor cables to an external power supply - rather than relying on the arduino being able to supply enough power. In fact, a quick look at some of the other posts on this forum has persuaded me that you should DEFINITELY use an external power supply for the motor. The moments in Electronics that are accompanied by a burning smell are often the most instructive, I find.)

Use the Arduino Serial Monitor to send position messages to the Arduino. These take the form of "#xxxx" where xxxx is pulse length in microseconds to send the the servo. Example:

0700 - pulse length of 700 microseconds

1950 - pulse length of 1950 microseconds.

This device requires a 5V pulse or length ~ 700 to 2100 microsecond repeated every 18 milliseconds. I don't know how widely the devices vary, but mine goes from one endstop with a pulse of 700 microseconds (#0700) to the other with a pulse of 2300 microseconds (#2300).

To use the above code, attach the red motor cable to 5V, the black motor cable to Gnd and the white motor cable (control) to pin 2. (On reflection, it might be wiser to connect the 5V (red) and ground (black) motor cables to an external power supply - rather than relying on the arduino being able to supply enough power).

The standard arduino boards include a 500ma polyfuse (thermo type) to protect the USB port from excessive current flow, however that is not a fast acting fuse and it’s still possible to damage a USB port if one is unlucky.

Bottom line is that it’s never a good idea to power a servo from an Arduino board, no matter if using the arduino external power connector or USB power. There is just too much variation in current requirements for servos depending on model, size, mechanical load. The Arduino should just be assigned control duties no power duties for external components, esp things like motors, servos, solenoids and other higher current consuming devices. When using external power supplies for such devices be sure to remember to join the ground side of the external voltage source with a arduino ground pin.

Lefty

+1 for always running a separate power source for servos.

vinceherman: +1 for always running a separate power source for servos.

Ditto.