BreadboardBot

Self-balancing with MPU-6050 and Bluetooth serial

Making a self-balancing two-wheeled robot is a classical fun introductory robotics exercise.

As the BreadboardBot was not built with the intention of balancing on two wheels, this exercise can be a bit more challenging than for a more typical self-balancing platform, and the result is much more fragile. Unlike most other examples here, just wiring your robot and copying the example code most probably will not suffice and you will need to tune the parameters to match your own robot. This, however, provides a particularly valuable and insightful learning experience.

Let us first review the reasons that make the BreadboardBot challenging to balance:

  1. The used servo motors are not too precise. For example, at throttle value 0.03 your left motor might not yet start moving yet at -0.01 it already would, and for the right motor these values would be different. You might need to tune the motors.drive function a bit to use a suitable offset for each motor, however that offset seems to be sensitive to the battery voltage, so there is a limit to how much these calibration efforts will help. In addition, when a motor starts moving at some threshold, it might do so with a tiny jerk, which negatively affects stabilization.

    These are probably the reasons you will not find too many self-balancing robots built with servo motors. Indeed, balancing the BreadboardBot on DC motors can be notably simpler.

  2. The motors we use are rather weak. You will certainly need 4xAAA batteries, because three just do not seem to provide enough power. Moreover, when I used four rechargeable AAA batteries, they were only good for a short while after recharging: as the total voltage dropped below 5.3V or so, the robot would struggle to maintain balance no matter how much I tuned the PID coefficients. Non-rechargeable alkaline batteries are a bit more convenient here as they keep their total voltage high enough for longer.

  3. The robot has a low center of mass. The lower the center of mass, the harder it is to balance an inverted pendulum in general. When combined with the weakness of the motors, this leaves a rather small range of tilt angles, from which the robot is able to recover balance in principle. A few accidental jerks due to (1) can easily take it out of this range.

  4. The robot is asymmetric and seems to accelerate faster when falling towards the back rather than towards the front. Probably because of that, equal jerking of the wheels back and forth seems to tend to gradually destabilize it towards the back.

  5. As the MPU-6050 is plugged into the breadboard right next to the wheels, it picks up all of the the wheel-caused acceleration signal, which makes it nearly impossible to use the pure accelerometer signal for balancing (which is often a viable easy solution in robots where the MPU is positioned higher up or close to the center of mass).

With those observations in mind, let us none the less proceed.