USB connection breaks every second while using a servo

Hello,

I’m trying to use a servo with my Arduino Uno and I’m using this code:

#include <Servo.h>

Servo servo1;
void setup()
{
  servo1.attach(5); 
}

void loop()
{
  servo1.write(120);
}

The servo itself is fine because it goes to the right angle but gradually: every second it stops, and the arduino seems to loose USB connection. The ON led goes off quickly even it is difficult to see, it disappears less than 1 second in the windows panel and there is a sound as if the arduino was plugged off USB, then the ON led goes on as if nothing happened (no plug in sound from windows, maybe it’s to quick for the OS to detect it)
I have tried:

  • Google
  • Using another USB port, an other serial port (COM 3 and COM 4)
  • Another servo with other wires
  • A reboot of the computer
  • Using pin 9 an 3.
  • Using the exemple “Sweep” in the arduino library.
    All of them did nothing.
    When I upload blink while the servo plugged on the arduino the led flashes normally, this bug only occurs when I’m connecting all three wires and using the affected pin at the same time.
    It’s weird because a friend of mine is using exactly the same servo with the same arduino without problems.
    So my conclusion is that it might be a USB/windows problem, any help ?

Thanks

You are using a seperate power supply for the servo right? The arduino can NOT supply enough current to the servo, especially when the arduino is running on USB power.

Get another 6V power source ( batteries maybe) and make sure the ground from the battery (-) is connected to the GND pin on the arduino.

Hey it worked ! It's weird because my friend showed me his arduino running TWO (!!) servos with a USB connection without power supply... so I didn't try this option. I'll have my servo running with this battery but I'm wondering how it could be done without it... Thanks, it is a basic mistake I made here ^^

pasdepsedo: Hey it worked ! It's weird because my friend showed me his arduino running TWO (!!) servos with a USB connection without power supply... so I didn't try this option. I'll have my servo running with this battery but I'm wondering how it could be done without it... Thanks, it is a basic mistake I made here ^^

Running servos or motors from Arduino 5V supply risks damaging the Arduino - and if the Arduino is running from USB power the computer it is attached to is also at risk - don't take that risk! In general inductive loads should not be sharing a logic supply rail, its a recipe for frying the electronics. Adding extra decoupling can mitigate the risk though, and there are protection circuits that can help, but its easier to separate concerns.

The USB cuts out on over current, USB hosts are meant to monitor the power and disconnect automatically if overload happens, but I don't think they can handle over voltage.

[BTW USB is rated at 0.5A max, servos can take peak currents of several amps]