Getting a robot to stand on two wheels without tipping over involves a challenging dance with the laws of physics. Self-balancing robots are a great way to get into control systems, sensor fusion, and embedded programming. This build by [mircemk] shows how to make one with just a few common components, an Arduino, and a bit of patience fine-tuning the PID controller.
At the heart of the bot is the MPU6050 – a combo accelerometer/gyroscope sensor that keeps track of tilt and movement. An Arduino Uno takes this data, runs it through a PID loop, and commands an L298N motor driver to adjust the speed and direction of two DC motors. The power comes from two Li-ion batteries feeding everything with enough juice to keep it upright. The rest of the magic lies in the tuning.
PID (Proportional-Integral-Derivative) control is what makes the robot stay balanced. Kp (proportional gain) determines how aggressively the motors respond to tilting. Kd (derivative gain) dampens oscillations, and Ki (integral gain) helps correct slow drifts. Set them wrong, and your bot either wobbles like a confused penguin or falls flat on its face. A good trick is to start with only Kp, then slowly add Kd and Ki until it stabilizes. Then don’t forget to calibrate your MPU6050; each sensor has unique offsets that need to be compensated in the code.
Once dialed in, the result is a robot that looks like it defies gravity. Whether you’re hacking it for fun, turning it into a segway-like ride, or using it as a learning tool, a balancing bot is a great way to sharpen your control system skills. For more inspiration, check out this earlier attempt from 2022, or these self-balancing robots (one with a little work) from a year before that. You can read up on [mircemk]’s project details here.
But why this lame PID instead of something like LQR?
Ardurobots with PID were exciting… in 2010.
Because it’s a high school graduation project. It’s basically “color by numbers” as engineering goes.
It’s still cool. You can always make one with lqr and submit it.
Looking at the other links and comments also, cookie cutter or been done before is fine, but until someone goes all the way through the project from start to working properly it is new to them and a learning experience. My first projects I did from start to delivery were very painful, but turned out to be very beneficial as I worked on more complex systems. So hats off to the person/team that put this one together and got it to running.
PS: I have seen articles showing two wheeled robots done without a micro computer (or any computer) –
This article reminded me of the tragic fate of Jimi Heselden.
https://www.bbc.com/news/uk-england-leeds-11416654
I saw Segway Scooters used for tour groups, they could move easily/quickly from one point to another – and also easy to see if someone in the group was lagging behind
I built one one once. It was a ‘kit’ though and had some ‘sample’ software to download to it. So not from the ground up, but you could certainly fine tune it or rewrite or whatever to not only balance but to travel as well. Add an RPI for smarts if desired. Still have it.
We designed and built a balancing robot as a teaching experiment at university once. The surprising part to us: Stabilizing it nicely was more difficult than we assumed. First we were fighting with the backlash from the DC motor gear play which we could not get stable with a simple PD controller.
After having solved this, the robot kept itself upright – but it would simply drive away. So we had to control the robot position as well. All in all not as simple as I had anticipated.
Of course. You control a segway by leaning backwards or forwards, shifting your center of mass over the wheel axle.
The balancing algorithm just keeps it “upright” as defined by the angle setpoint, but if “upright” doesn’t put the center of mass of the robot perfectly on the wheel axle, then it has to keep accelerating to keep from tipping over. That’s just how the physics of the situation is – the motor torque must equal the distance the mass is offset from being perfectly centered above the wheels. We also did the same exercise in a university mechanical dynamics course, and this point came up in the initial analysis of the case.
What you have to do is adjust the “up” angle setpoint with another PID loop that tries to keep the wheel speed at zero (or some other value). Position works too.
Self balancing robots are just fun to build and magical to watch. I have built many, without encoders because I wanted to see how well I could get them to balance and control. One great find was to use Index of about 10x P to keep robot from running away on a smooth surface. Another is that timing of all processes must be within a 5 to 10 millisecond loop (depending on processor) to keep oscillations consistent and clocklike – no delay statements in Arduino code and must do everything using either timers or milliecsond loop for timing. I still play with them because there is always something new to learn and self balancing is just cool.
Integral, not index.
Would limit the acceleration or jerk action of the controller output prevent slippage of the wheels? Sounds like an output limit is better than re-tuning the regulator. As the dynamics hardly change and it’s some nonlinear effect.