Physical Computing with Servos and the Raspberry Pi

Giving The Raspberry Pi a Body

In this post I go over how to set up your Raspberry pi for servo based operations. When your done, you’ll have a solid, customizable platform To build a huge variety of robots and gadgets as well as the know-how To use it.


First thing you’ll need is of course, is The Raspberry Pi 3B(+) or any model will do.

My very first one, runs noticeably smoother than it's predecessor and outclasses it  in every way so far. madeh PicsArt.

The perfect building block for any DIY gadget.

Next you’ll need a servo controller. I’ve used two kinds that work the same way:

The Adafruit 16 Channel Servo Hat:

The stackable version of the Adafruit 16 channel servo hat used to add more hats of many kinds.

The Adafruit 16 Channel Servo Hat– is an easy to use expansions board for the pi and gives it the ability to efficiently control up to 16 servos, the muscles of your robot.

Assembling the Servo Hat

Unless you’ve somehow found a preassembled servo hat, you’re going to have to solder it together. Could be fun for you, could be a chore but you’d only have to do ot once. And if you dont know about soldering, I’d highly recommend it as it’s a most useful skill for mostly any aspiring tinkerers arsenal.

Same But Different

If you absolutely refuse to solder however, there is an option! an amazing alternative to Adafruits servo hat would be the SunFounder PCA9685 16 Channel 12 Bit PWM Servo Driver for Arduino and Raspberry Pi

Great alternative to Adafruits 16 channel servo hat or Bonnet

which needs no soldering, its smaller(like a pi zero) and uses the same code as the Adafruit hat.

This video does a great job explaining how to connect it to the pi:

Optional Gear

The CableDeconn USB to 5.5 mm/2.1 mm 5 Volt DC Barrel Jack Power Cable to power your servos with a regular portable USB charger.

To connect my AdaFruit servo hats DC power plug to the Anker portable USB battery


Once you’ve chosen a servo controller, you’re going to need some actual servo motors, The “muscles” of your machines body that will move all of your inventions.

1st Tier Servos
Regular 9g servos like these

Mainstay of any servo powered project

are perfect for experimenting and prototyping(it’s a terrible feeling to experiment with an high grade, expensive servo only to break it early on).

2nd Tier Servos

And when you are confident about your code and gadget set up etc, you may want to upgrade to metal geared servos.

Better for those

More expensive usually but they certainly are more durable and tend to offer better performance than your typical blue nylon servos.

3rd Tier Servos

But my small servo of choice for more finalized gizmos would have to be the AGFRC Sub-micro Servo

Perfect for final products or if your machine needs better leg support or anything like that

For machines that need to handle more weight and/or deserve peak performance, my absolute favorite. (Its designated a size 13g but is usually pretty interchangeable to the regular 9g sizes.)

Standard Sized Servos

And lest we forget The mg996r Standard sized servo:

Bigger, badder, a little on the slower side but perfect for projects requiring some more kick or just bigger projects in general.

Configuring and Testing

Now that we gave our gear all set, it’s time to configure and test our hats with the raspberry pi.

As Always update the pi Everytime you plan on doing something new:

$ sudo apt-get update
$ sudo apt-get -y upgrade
$ sudo apt-get -y dist-upgrade

Next we get the Servo Hat to accept and communicate with the raspberry pi and then test the set up by following along with the Official overview. (Remember: both recommended hats work and set up the same.)

Make sure everything’s powered and connected and your results should look like this:

Eventually I developed my own customized servo control script based on the Adafruit test scripts. Using the as a base, i can easily add servo functionality to any python program. The git also includes an EvDev program to control your servos via keyboard. Enjoy 🙂

And that’s about all there is to integrating a reliable and robust servo system into your raspberry pi effectively turning it from a regular small computer into a robot capable computing device.

What’s Next?

I found Servos to be a gateway of sorts to projects of a much higher Calibur, encouraging me to go deeper and take a cracks at, say:Building my very own homemade robot! An obvious choice for anyone looking to build a body for their pi.

..Or even my very own cybernetic prosthetic which relies on a gesture control system so cutting edge, it can even work on amputees.

And it all started with these basics.

Well That’s all for now. Stay tuned for updates. Please like, share and consider showing support with a donation if you found this post useful. Your gratitude aids and abets my obsession and helps me get more gadgets to research so i can share more knowledge with the world. Thank you for finding me. Cheers! 🙂

10 thoughts on “Physical Computing with Servos and the Raspberry Pi

  1. sir in my project i am using servo hat for controlling 16 servo motors and i and i want to attach to sensors to my project but i not getting where to attach them

      1. soldered header ex

        So the servo hat on the left is soldered with regular headers. Cant attach much to that one. The servo hat on the right is soldered with stackable headers effectively giving you what you need without compromising your imagination. I get mine from the Adafruit website.

    1. servohat + Grovepi stacked exFor example, with the stackable headers(there are multiple sizes available), you’d be able to attach something like the SeedStudio Grove pi sensor hat to be able to use grove sensors + servos. See Stacking Hats: (the sensor attached is an ultrasonic ranger for obstacle avoidance).

    2. mpu6050 + raspberry pi servohatOr if you’re using traditional sensors like an mpu6050(accelerometer/gyroscope to incorporate self balancing features) it would look something like this.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.