Loading the 3D lab…
Self-Balancing Robot Assembly: Build a Balancing Robot Part by Part in 3D
Build a two-wheeled self-balancing robot in a full-screen 3D maker lab from 20 named parts: plates, standoffs, motor brackets, geared motors with encoders, wheels, motor driver, regulator, microcontroller, IMU, battery and display, then watch its PID loop balance it and recover from a push.
Key relation: 20 parts · 14 operations
Aim
To build a two-wheeled self-balancing robot from its parts, learning what each part does and how it is fastened, and to watch its PID control loop keep it upright and recover from a push.
Apparatus
Apparatus: A build stand with two arms, a push tester, a set of hex keys and screwdrivers, a torque screwdriver (0.3 to 1 N·m), thread-locking compound, a multimeter, and a laptop with a USB cable to load the firmware.
The parts and what they do
Chassis · Three acrylic plates, standoffs and motor brackets
Three laser-cut 3 mm acrylic plates held 60 mm apart by brass standoffs, and two folded steel L brackets under the bottom plate.
It holds everything in place and sets where the weight is: low motors, electronics in the middle, the battery on top.
Motors and wheels · Two geared DC motors with encoders, hubs and wheels
Two 12 V DC motors with 30 : 1 gearboxes and magnetic Hall encoders, clamping hubs on their 6 mm shafts, and 85 mm rubber-tyred wheels.
They drive the wheels under the robot’s centre of mass to stop it falling; the encoders tell the controller how far and how fast it has rolled.
Controller and driver · Microcontroller and dual motor driver
A 240 MHz microcontroller board with Wi-Fi, and a dual H-bridge motor driver with its heatsink.
The controller runs the PID loop 200 times a second and sets each motor’s PWM duty; the driver switches the battery’s voltage to the motors to match, in either direction.
IMU and display · Gyroscope and accelerometer, and the OLED screen
A six-axis MEMS IMU (three gyroscopes, three accelerometers) on the middle plate, and a small OLED screen on the top plate’s front edge.
The IMU gives the tilt angle and how fast it is changing; the screen shows the tilt and the battery’s voltage.
Power · Battery pack, regulator and switch
Three 18650 lithium-ion cells in series (11.1 V, 2,600 mAh), a buck converter to 5 V, and a rocker switch with a light.
The battery feeds the motors through the driver and, through the regulator, the controller and the sensors.
How it is built
- Chassis: The plates are laser cut, the bottom one goes on a stand, and the motor brackets bolt under it.
- Drive: The motors go into their brackets, the hubs onto the shafts with their grub screws on the flats, and the wheels onto the hubs.
- Electronics: The driver and the regulator (set to 5.0 V first) on the bottom plate, standoffs, the middle plate with the controller and the IMU square to it.
- Top and power: The top plate, the battery strapped on high, the switch and the display; then the firmware is loaded.
- Tuning: With the wheels free on the stand the motors’ directions and the IMU’s axes are checked; then P is raised until it oscillates, D added to damp it, and a little I to remove a steady lean.
- Test: Lowered onto its wheels it balances by itself; pushed, it runs to catch itself and comes back.
Precautions
- Set the regulator to 5.0 V with a multimeter before connecting the controller to it.
- Check each motor’s direction and the IMU’s axes with the wheels off the bench: a sign the wrong way round makes the robot drive into its fall.
- Put thread-locking compound on the hubs’ grub screws: a slipping hub makes the robot fall.
- Charge lithium-ion cells only in a balance charger, and never leave them charging unattended.
- Keep fingers clear of the wheels when it is switched on.
- Test it on a clear bench with a soft mat, and catch it if it falls.
About this lab
The robot is a typical maker-lab balancing robot, drawn to scale: 235 mm wide, 230 mm tall, 1.07 kg, with 85 mm wheels, 12 V geared motors with encoders and a 3-cell lithium-ion battery. It is not a model of any one kit.
The balancing in the last step is simulated: the robot is a body tilting on rolling wheels, driven by motors whose torque falls with speed, and the controller is a PID loop on the tilt run 200 times a second, with an outer loop that leans it to bring it back to where it started. The scope over the robot plots the real numbers of that simulation.
Wires are left out so that the parts they join can be seen; on a real robot they are run and tied as each part goes on.
Each step is done when you press its button; the part travels from where it lies to its place. Open the Parts panel to read about any part and have the camera go to it.