Self-balancing Part 1

Why should you build a self-balancing robot?

That is a very good question, with an even better answer! Self-balancing systems can be seen in many places and they are essential for the smooth running of numerous types of machines. Some of the obvious include Segways, bipedal robots and space rockets (A few rockets have been lost due to a faulty balancing system).

But what many people don’t realise is that these systems use the same controllers that can be seen in servo-motors, air-conditioning units, and even thermostats. Of course rockets use significantly more complex controllers than air-conditioners, but the underlying principle is still the same: how to adjust the system in order to get as close to the desired outcome as possible. That is why building a self-balancing robot is so educational; you can use the same control methods over and over again for other projects. And please don’t forget, a self-balancing robot is a very fun toy to have! Here is a video of my self-balancing in action:

 

 

A Brief Overview

It takes a number of steps to build a self-balancing robot. The easiest part is the hardware, so that is always a good place to start. The robot requires two motors, a motor controller, a gyroscope, a micro-controller and some type of frame. Surprisingly enough due to the inertia of an inverted pendulum, the robot actually finds it easier to stabilise if the frame is very tall with a lot of weight on top, instead of a small frame with a low centre of gravity!

Once all of the physical components have been assembled, we can proceed to the tricky stuff; the software. As the system is inherently unstable, the micro-controller needs to continuously refresh itself and be as fast and efficient as possible in order to retain its balance. Therefore the loop time should be as short as you can make (but still remain regular). For my robot I used a standard loop time of 10ms. Therefore the the controller recalculates its response 100 times per second!

Title Slider 2
The motors of my self-balancing robot

 

Required Components

Before we dive into how to make a self-balancing robot, we need to get our hardware together. Here is a list of the required component, with some links as reference:

The links above are for reference only! I recommend that you look around at a number of companies before you buy anything.

I decided to use the Intel Galileo Gen2 Development Board for my micro-controller as I had a couple lying around, and it is compatible with the Arduino environment. In reality you could use any board (Eg. Uno, Mega, Red-board) to make your self-balancing robot. In all of my robots I used the MPU-6050 sensor, which contains both a gyroscope and an accelerometer. The benefit of using both of the sensors together is that their data can be fused, giving us much stabler and accurate readings.

To create my frame I designed all of the components on the computer using SketchUp, and then sent them to be 3D printed. I have to admit that this is quite expensive, so an alternative would be to build your own frame out of scrap parts! I built my first self-balancing robot prototype out of lollipop sticks and glue, and I was surprised how well it worked! A common frame design is to use a couple of plastic/wood rectangles as platforms, and to connect these using a long threaded bolt and some nuts.


In Part 2: How to use the Accelerometer/Gyroscope in order to get the current angle of the robot. View Part 2

Please leave a comment below if you have any questions or suggestions. Like this tutorial? The please consider subscribing to get notifications of my latest posts and projects!

This Post Has 9 Comments

  1. Hi, may I have a question about your robot? I am wondering how did you get these motors. This guy seems to not ship to Ireland. I was looking for any similar ones but it’s really difficult to find any with relatively high torque and about 120-300 rpm. I could find only ones from Hong-kong but there is a very long delivery time (about 30 days)…

    1. Yes, I also found it difficult to find a suitable supplier for gearbox motors. For my first robot I simply looked around on Amazon until I found one that ships to Ireland. For my second robot, I bought these motors here: http://www.active-robots.com/30-1-metal-gearmotor-37dx52l-mm. They are rather expensive, but they do work well, and they can be delivered to Ireland.

      Simon B.

  2. Thank you again for your help.
    Regards,
    D

  3. May I just use a L293D as a motor driver?

    1. From the info I can find on the internet, the L293D seems to be just a simple H-bridge. For a self-balancing robot you will need to be able to control the output speed of the motors, and the L293D on its own cannot do this. Here is a tutorial I found of how you can use the L293D and and Arduino in order to achieve bi-directional motor and speed control: http://letsmakerobots.com/files/MotorDriverL293Dnet.pdf

      Hope this helps!
      Simon B.

    2. What could I use instead of arduino motor shield? Thank you so much for your help 🙂

    3. You could use any motor shield which supports motor speed control. In reality you could use a H-bridge such as the L293D, but it just requires a number of extra steps to get working. It really depends on your experience of hobby electronics, and the type of micro-controller that you are using. If you are a beginner, I would recommend buying a motor controller shield, such as the Arduino Motor Shield, the Adafruit Motor Shield or the Ardumoto shield.

      Simon B.

  4. Hi, your project is really interesting. I would like to make something like this. I look forward for the next steps because I am still the begginer. Thank you 🙂

    1. Hello Angela,
      Thanks for your comment! 🙂 I am currently writing up the second post for this series, so hopefully that shall be ready soon. Making a self-balancing robot is really a fun way to learn the basics (and some of the advanced parts) of electronics and control theory…

      Simon B.

Leave a Reply

eighteen − 16 =