Servo trouble

Hi,
I'm trying to control 5 servos (maybe will add more later) with Arduino UNO. The servos are TowerPro SG90, really small 5v servos. They are all connected to the Arduino 5V supply and directly to digital pins of Arduino.
When I run the program, they start twitching in all directions and my computer makes a sound as if the Arduino board has been disconnected. This goes on in a loop. Well, sometimes it works, but it's not reliable. XD
Is 5 servos too much for Arduino UNO? However, I've tried doing it with an external power source and it didn't go much better.
Here's the code:

#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
 
void setup(){
  Serial.begin(9600);
     servo1.attach(9);
     servo2.attach(10);
     servo3.attach(11);
     servo4.attach(5);
     servo5.attach(6);     
}

void demo()
{
  servo1.write(170);  
  servo2.write(120);
  servo3.write(180);
  servo4.write(10);  
  servo5.write(10);

}
        
void loop()
{
  demo ();  
}

You cannot power servos from the Uno 5V supply. The servos will pull the power down to the point that the Uno resets, repeatedly. Use a 4 AA cell pack or some other 5-6 volt supply for the servos.

and my computer makes a sound as if the Arduino board has been disconnected.

That's probably because it has.

However, I've tried doing it with an external power source and it didn't go much better.

Did you connect the grounds together?

How big was the external power supply?

Try starting with just one servo, get this working then move up one servo at a time. Remember that the amount of power required by the servo increases with the load on the servo.

Mark

duje:
Is 5 servos too much for Arduino UNO? However, I've tried doing it with an external power source and it didn't go much better.

You certainly cannot power servos - not even one - from the Arduino 5V supply. If you have a sufficiently well regulated 5V supply to power the servos, you could power the Arduino from that via its Vcc terminal.

I think you had better explain just what this "external power source" that you used, was also?

JimboZA:
Did you connect the grounds together?

Yes, I did, still only twitching...

Paul__B:
You certainly cannot power servos - not even one - from the Arduino 5V supply. If you have a sufficiently well regulated 5V supply to power the servos, you could power the Arduino from that via its Vcc terminal.

I think you had better explain just what this "external power source" that you used, was also?

Well, in this example servo is powered directly by Arduino: http://arduino.cc/en/Tutorial/Knob

The external power supply I used was a simple AC-DC adaptor which gave me around 7V.

A good rule of thumb is that if more than one servo is to be moving at once, budget 1 ampere of current per straining servo. An AA battery pack with fresh alkaline batteries can supply only about 2 amperes before the voltage begins to drop significantly.

Moral: get a good 5-6 V regulated power supply for your servos.

duje:
Well, in this example servo is powered directly by Arduino: http://arduino.cc/en/Tutorial/Knob

And this sadly, like many of the "Tutorials" or "Examples" in the Arduino references, is disturbingly incomplete and misleading insofar as it allows beginners to believe that they can or should use the techniques described for more practical purposes.

In the example given, the 5V is supplied (directly) from the USB port whose capability to supply current depends greatly on whether it is a desktop or laptop, hub or powered hub. It may in many cases just be able to power a single unloaded servo for demonstration purposes only. Just.

duje:
The external power supply I used was a simple AC-DC adaptor which gave me around 7V.

If you fed that to the Arduino as Vin, then the regulator in the Arduino is as I recall, less capable of providing current than the USB input. If you powered the servos alone, directly from it then theoretically, you were providing them with too much voltage - though they would likely survive. And - what does "around 7V" mean? Do you mean it was an unregulated power supply? What current was it rated for?

Paul__B:
If you fed that to the Arduino as Vin, then the regulator in the Arduino is as I recall, less capable of providing current than the USB input. If you powered the servos alone, directly from it then theoretically, you were providing them with too much voltage - though they would likely survive. And - what does "around 7V" mean? Do you mean it was an unregulated power supply? What current was it rated for?

I fed the external power directly to the servos, not to Arduinos Vin. I read the voltage on the power supply with a multimeter and it said 7.2V DC. There are no voltage regulators connected to this. As for the current, on the adaptor it is written:
CURRENT 500mA6VA(max) - so whatever that means :~
the adaptor looks like this: helmut-singer.de has been registered

Should I put a voltage regulator somewhere in there? Or is it simply lacking power?

CURRENT 500mA6VA(max)

I read that as 500mA and 6VA.
That is seriously under-powered for more than a single servo.