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!
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:
- 1 x Arduino-compatible Controller
- 1 x Power Supply/Battery
- 1 x Motor Controller
- 1 x Gyroscope/Accelerometer Module (Eg. MPU-6050)
- 2 x High Torque Gearbox Motors
- Colour-coded wires, preferably single core
- Some type of frame!
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.
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!
Updated: 23rd May 2019 – Reformatted post