Let's Make Robots!

Ten Servos From Two Pins - Not New But Heres My Take, Sketch and Library

Allows control of upto 10 servos using only two Arduino Pin to drive a decade counter

   This not a newly discovered technique, its been around for decades, but here is my explanation of how it works, a test sketch and also a ready made library for you to try -

Ten Servos From Two Pins

Duane B


Comment viewing options

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

might I suggest a minor change in your code?

Rather than hard coding the pins you use, allow the user to specify which hardware PWM and which pin they will use for the Master Reset. I mention this mainly because, most often pins 9 and 10 are used for motor control. Or, you could set up a pair of Constructors. One could take no arguments and use the pins you have chosen, and, the other could allow a user to make their own pin choices.

Actually, if you use the Arduino Servo library, you CAN'T use the pins 9 and 10 for motor control... So the (Arduino based) robots that use servos will use a different timer for motor control. That being said, he's fine with the hardcoded pin. 

I am using OCR1A which would disable PWM on pin 9, thats the main reason for hard coding the pin.

Anyway, lets see if anyone uses the library, if people find it useful I will extend it to 20 Servos and add a bit more flexibility.

Duane B

DIYEngineering tweeted  your post this morning. ; j

Pretty need. I will look into this in the future. Very nice way to gain some more Servo controls. :) Thanks.

Thats great, I don't think I have ever been tweeted before.

Duane B


That was my thinking, if the library reduces the function of a pin, it makes sense to use that pin if you can extend its functionality in another way.

I have now updated the library for 20 Servos from four pins. I will do some testing and post the new version on my blog, probably monday.

I have one other major tweak in mind which I will try to get done for Monday.

Duane B

How hard would it be to do something like this on the raspberry pi? Also, how responsive ar the servos when controlled through this?

servos can be very responsive controlled this way. If you tell the library I provided that it only has four servos to control it will be able to pulse them at between 125 and 250hz which is far more responsive than the standard servo library at 50hz. I have a variation of the library specifically for high frequency servo signals which I might manage to publish this week. As for RasPi I think you have answers alredy on other threads. Duane B