How many servos on an Arduino?

Hi everyone-

So I'm coming over to Arduino from Basic Stamps, and was hoping to get an answer to a question. How many servos can an Arduino chip control, and do i need one of those "shields" for it? I'm talking about those typical hobby servos used in basic electronics. Any help would be appreciated. Thanks!

You can use as many as there are pins, I think.

As to needing the shield, no you don't.

All you need is an external power source, the arduino cannot give enough current to drive servos. Connect the positive side of the power source to the 5v wire of the servo, connect bot grounds (arduino and power) to the grounds of the servo, then connect the arduino's digital pins to the signal wires of the servo.

I successfully use 2 full-rotation servos on my driving robot with no external power, and just use the Arduino to supply power and control.

Depending on the power needs of your servos, you may be able to get away without an external power supply. The little tiny 6g servos can run from an Arduino no problem. Just plug them in and go. It all depends on your motors of course, if you are using 12v motors, then you will need external power.

I run 4 D batteries to drive the servos and the Arduino, the motors only have a 60RPM capability and they chug right along.

I'm not worried about the power supply, since i can add one on (I assume), just how many servos I want to control. I have a project i'm thinking of that would have about 12 servos, so i want to make sure its feasible.

From a control standpoint, absolutely, I think the limit is 18 with a Demi, and with a Mega it is even more (more pins). Servos are one of the easiest things to control, it is literally like 3 lines of code.

But with 12 at once you will very likely need external power, it would be better to separate the load for 12 motors from the power for the board. Much cleaner and easier.

Do a find for "Crab bot" or "walker robot" or "hexapod" all those robots with crab legs have tons of servos (one for each joint on each leg) and you can see how many people have connected successfully, and very likely see the code they used.

If you can, I would definitely try to go with a wall wart power supply, less of a hassle trying to find a battery that will drive tons of servos. I have used one that can do 2A 12v and it works well with 8 servos (with voltage regulator obviously. And if you make your own regulator circuit, definitely don't connect the power wires of the servos to the 12v supply instead of the regulator output. Erm... not like I've ever done that... :-[ )

Hmm, found something interesting...: The built-in servo library was replaced by the previously known as softwareServo library in a recent version of arduino, right? The sweep example says this:

Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created

Does this hold true? If so, does any other library extend this limit?

I

have used one that can do 2A 12v and it works well with 8 servos (with voltage regulator obviously. And if you make your own regulator circuit, definitely don't connect the power wires of the servos to the 12v supply instead of the regulator output. Erm... not like I've ever done that... )

Depending on the regulator you are using, you could well be wasting a lot of power as heat in the regulator. Most regulators have a certain "turn on" voltage; you want to try to stay as close to that as possible with your power supply. For instance the 7805 is around 7 volts; using a 12V supply with that, that extra drop of voltage goes somewhere, out the regulator as heat. Using a 9 volt supply would be better.

Also - if you are running servos, its best to use a 6 volt regulator; most servos are designed to run at a peak voltage of 6 volts to get the most torque and performance from them.

Finally - regarding using the Arduino alone to control 12 servos: Yes, this can be done, and I believe with the built-in servo library (I don't think there are any limitations with this library). The only issue is that as you add servos and other code to your system, you may run into timing issues that can cause the servos to "jitter"; periodically, or sporadically (it depends on what is going on in the code, as well as the power supply and the servos themselves). Generally, when controlling a large number of servos, it is better to use a servo controller device, which generally takes the form of a dedicated microcontroller hooked up using a serial control system. Generally, you can use the software serial library to control these boards (so only one or two i/o lines used, instead of one per servo), and the microcontroller on that board, once you pass it the commands, keeps the servos constantly updated to keep them in place - effectively off-loading the processing off the Arduino. They aren't very expensive, and they can generally be daisy-chained for more servos if needed (each board is addressable in some manner determined by the manufacturer).

I tend to favor Pololu's offerings, but there are other manufacturers as well. Generally, as I said, these boards are controlled by a built-in microcontroller that is programmed to read serial commands and control servos, nothing else. In fact, it wouldn't be too difficult to make an ATMega328-based servo controller, if you wanted to. There probably exists such a product already. However, most are controlled by PIC processors, from what I have seen.

:)

However, most are controlled by PIC processors, from what I have seen.

Not just servos ;). Before I started into microcontrollers I asked about what'd be easiest to use. As I found out I was told go to arduino and which I did. ;). There's a few tutorials somewhere I think to control many servos.

I run 18 standard hobby servos on my Mega. I did use a prototyping board to let me solder up 3 rows of male headers to use as pins for the servo plugs to plug in to.

Here is a link to a thread where I post pics and lots of information. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1265626147/6#6

Okay I looked into getting a 6v AC-DC adapter.
Here’s what I found:
http://cgi.ebay.com/NEW-6V-2500mA-2-5A-AC-DC-Power-ac-adapter-Power-supply_W0QQitemZ290372976909QQcategoryZ294QQcmdZViewItem#ht_2267wt_913

So I can run 8 5gram servos off of this directly (2500 mA is enough for the servos), no regulator?
And can I run the arduino off of this too? Through the barrel jack/VIn pin? Directly to the 5v pin?

So I can run 8 5gram servos off of this directly (2500 mA is enough for the servos), no regulator?

Not without risking damage to the servos. Unregulated supplies like that will output much higher voltage depending on the actual current draw at any specific time. The voltage can rise well above the safe maximum the servos can handle. And can I run the arduino off of this too? Through the barrel jack/VIn pin? Directly to the 5v pin?

Wiring that power module to the +5vdc pin will destroy the Arduino. Wire it only to the barrel jack or Vin pin, however that requires a voltage of greater then around 8vdc to work correctly, not 6vdc.

Lefty

I think cr0sh is right. Easiest way to control your servos, and still have free IO lines to use for other purposes, is to use a servo controller. This is one of Pololu's servo controllers that can control 24 servos, using only 2 serial line OR directly from your computer: http://www.robotsimple.com/Mini_Maestro_24_Channel_USB_Servo_Controller_Assembled there is also this one that can do 18, and one that can do 12 servos: http://www.robotsimple.com/Mini_Maestro_18_Channel_USB_Servo_Controller_Assembled http://www.robotsimple.com/Mini_Maestro_12_Channel_USB_Servo_Controller_Assembled

they are all read to go solutions, just connect power source to the terminal block, and serial line to your arduino.

I'm not worried about the power supply, since i can add one on (I assume),

I have one hobby servo that came with my starter kit.

If I power it from the arduino I have to run it in small steps, with a small pause inbetween. If I make it sweep it uses too much power and the arduino resets.

I was just re-reading my comment up there - I used the word "generally" waaaay too much...

;D

I was just re-reading my comment up there - I used the word "generally" waaaay too much...

You generally do that. :P