
2 Wheel Balance Robot
2 Wheel Balance Robot
✔️ Introduction
This project describes a 2 wheel balance robot system. There are several designs available online, but we will be creating the design from scratch. We will be designing the chassis using OnShape, a PCB board with the motors driver, IMU, encoders, and a capability to control the robot over WiFi. Later to “spice” things a bit, we will add an additional challenge to the balancing system.
✔️ Design Stage
As always we start with the block diagram of the system that we are designing. The minimum systems has two motors, a driver to control the motors (TB6612), one IMU (MPU6050), one magnetic encoder (MT6701), one RGB LED (WS2811), and one communication module (ESP8266).

The ESP8266 is used to adjust the PID controller gains and steer the robot in real time. The user connects to the ESP8266 own network over WiFi and the device used gets assigned an IP address. The user opens a browser and it has access to the GUI to interact with the robot. The ESP8266 uses UART to communicate with the main microcontroller.

The microcontroller used in this project is an STM32F401RBT6 with 64 pins and an LQFP package.
The pins were selected so we could interface all the required peripherals using timers, PWMs, encoders, I2C and UART features.

The code diagram is presented below. It is an attempt to show how the code will be structured later to control the robot using the peripherals selected with the STM32CubeMX.

✔️ Prototype Stage
Since I needed to design and find a way to attach the magnet and the encoder to the motor, that setup was tested separately first.

Next, since I don’t have an STM32F401 development board, I used the STM32F407 discovery board to test all peripherals and components and made sure that the code diagram presented in the previous section was working as intended.

The last test was done using an ESP32 (with WiFi integrated), develop the PID controller code and make sure that I was able to tune, steer and balance the robot.

✔️ Assemble Stage
The boards were manufactured by PCBWay.
This time I ordered a stencil and as always a stellar service.

The quality of the stencil is very good and I really like how they made it small and easy to use.




Assembled in house.






Components place by hand:

After reflowing the solder paste:

I needed to fix a couple of solder bridges, and then I flashed a blink LED program to make sure that everything got soldered properly.
🔧 Testing Stage
soon…
✔️ GitHub Repository
- KiCad 10.0 Files
- STL/Step Files
✔️ References
N/A
Sponsor





