Let's Make Robots!

Driving up to 48 servos with a Spider controller

Controls more servos than you can fit on one robot :p
_48_servos_array.zip850 bytes

This tip/walkthrough will work with all Arduino Mega PCBs and their clones. I have found the instructions for the servo command to be a little vague so in this tip I will share my research.

The Spider controller is an Arduino Mega compatible PCB. Unlike the Arduino Mega the Spider controller was designed specifically to drive a large number servos. This made it ideal for this tip/walkthrough.

The Arduino servo library is capable of driving up to 48 servos. After a bit of experimenting I found that the servos can be assigned to any of the digital pins from D0 to D63. For those thinking that the digital pins only go to D53, analog pins A0 - A9 are digital pins D54 - D63.

For those who have never used the servo command before I will start at the beginning using the attached code as my example. The first line of the code "#include <Servo.h>" means that the instructions needed to generate the servo control signals will be included in the code to be uploaded to the microcontroller.

Before the setup() function you must define your servos same as you define your global variables. I've simply called my servos s00 to s47. You should name your servos with descriptive names to make your program easier to read.

The Servo command uses a timer for each 12 servos used starting with Timer 5. As these timers are also used for commands like PWM you need to plan your pin assignments to avoid conflicts.

1   to 12 servos use timer   5          disabling PWM on pins 44,45 and 46.
13 to 24 servos use timers 1&5       disabling PWM on pins 11,12,44,45 and 46.
25 to 36 servos use timers 1,4&5    disabling PWM on pins  6,7,8,11,12,44,45 and 46.
37 to 48 servos use timers 1,3,4&5 disabling PWM on pins 2,3,5,6,7,8,11,12,44,45 and 46.

Once you have defined your servos you need to attach them to the physical pins of the controller. In the setup() function you can attach your servos to any of your digital outputs. In my sample I have avoided digital pins 0 and 1 as they are used for serial communications. At this point even thought the servos have been attached to a pin they are not receiving any signals.

The first time you write to a servo using either the servo write() or writeMicrosecond() command the pin will be initialised and the servo will receive a control signal. depending on your application you may need to initialise the servos in the setup() function. In my example I initialise the servos in the loop() function.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Any word when this will be available from the distributors? 

We have just got our first batch of Red Backs in!

The Red Back Spider is version 3 of the Spider controller with an improved 3A switchmode supply. I tested this today and it delivered  5V at 3A with an input voltage as low as 7V.

This Controller will be available very soon.

I have a question, I get that the servos are powered by the switching power supply, but can they be powered directly from the battery if needed? Say one wants to build a 24 servos biped with 12kg-cm torque servos (they need about 1.5 amps at stall, 6V), is there a way to power them using for example several power connectors plugged in the servo power bus (from the same battery, so the amps are spread over several pins)?

It is true that with this version of the PCB all servo power is 5V from the switchmode regulator which is not ideal for larger servos that run on 6V or higher. I did consider having a jumper to isolate at least part of the 5V rail but this was not practical.

At this point a Sheild PCB is the best option. All your I/O pins can then break out onto the sheild but with a different voltage (or voltages) for the more powerful servos.

This type of shield should be very easy to make using prototype board. We will probably produce a shield like this in the near future.

If I would get this board, I would cut the Vcc trace close to the Analog pins, desolder the Vcc and GND pins at the SCL and SDA and cut the Vcc trace there too. Then I would use a jumper wire to transfer Vcc from one Vcc pin from the Analog pins group to the other side of the board, in another free Vcc pin. A jumper wire can transfer enough current for any electronics I might use on the left side of the board (considering the bottom of the board is where the USB and power connectors are). At the top of the board, I would drill 2 holes on each side of the 16 digital pins, one on the Vcc trace and one on the ground plane to install 2 screw terminal connectors on both sides of the top 16 digital pins. I would connect the servo power to those 2 screw terminals. This way I could have at least 24 larger servos (from D22 up to D45) and perhaps some more micro servos plugged in the connectors on the left side of the board. I would use a 2S LiPo to power the board and one uBec for each servo power connector I installed on the board.


In a future version of this board, can you incorporate some solder jumpers and holes for screw connectors like I described? The solder jumper on the left side of the board can be in place of the 2 power pins from the SCL and SDA pins. On the right side, just place it above the Analog pins group. And there is enough room to add the screw connectors near the top digital pins group on both sides. This way, one can use the board as is, or desolder the jumpers and solder screw terminals to power bigger servos. 


The PCB design uses the power rail to take Vcc to some parts of the board. The only place you can cut the Vcc track would give you digital pins 0-29 as high powered servos. This is not a very good idea.

This board will happily run most servos used for hobby robotics, not just the miniature servos.

A sheild will provide far greater flexibility when high powered servos are being used.


Nice!!! But you will need a beefier battery in a real robot. Look how thin is the battery wire, not much current will go through if the servos will try to lift a load. I know OddBot knows this, I'm just saying for other people to be aware why it works for OddBot and not for their robot!

Yes this is true. Unloaded the 48 servos drew about 1amp. When all of them were stalling due to a mistake in my original code the current spiked in excess of 6A. I used normal jumper wires for this quick demonstration but automotive wiring could be needed in some cases.

If you assume a humanoid or hexapod using about 24 micro servos and all servos having at least some load on them then the current draw on the battery could easily be 2A or 3A continuous. Bigger servos would need to be powered directly from the battery.



Do you think 48 servos could lift me, possibly my wife?

As you have not mentioned the weight of you or your wife (probably a good idea) we will choose a nice round number of 100Kg (220lb) as the load to be carried.

divide that by 50 servos (I rounded up to keep the math simple) that would work out to 2Kg per servo.

If you made a centipede style walker and assumed half the legs are off the ground at any one time then you would have to allow about 4Kg per servo.

If you used 10Kg/cm torque servos and had legs only 2cm long then you could carry 100Kg with a safety margin of about 20%.