Electronics · Motor Control · Robotics

Two-Wheel Balancing Robot

ESP32 TB6612FNG BMI160 IMU I²C PWM LM2596 LiPo DC motors

The robot balancing on its two wheels.

ControllerESP32 dev board (ESP-WROOM-32)
Motor driverToshiba TB6612FNG dual H-bridge breakout
Motors2x brushed DC motors, one per wheel
SensorBosch BMI160 6-axis IMU on I²C (SDA / SCL)
Battery7.6 V, 4500 mAh LiPo
Power stageLM2596 adjustable buck converter, set to 5 V for the ESP32
SwitchingRocker switch between battery and the rest of the circuit

Overview

The electronics for a two-wheel self-balancing robot. An ESP32 reads the tilt of the robot from a BMI160 IMU and drives two DC motors through a TB6612FNG dual H-bridge, all powered from one 7.6 V LiPo battery.

  • The battery feeds the TB6612FNG motor supply (VM) directly and the LM2596 buck converter, both through one rocker switch.
  • The LM2596 steps the battery voltage down to 5 V for the ESP32 board.
  • The ESP32 sets speed and direction of each motor with one PWM and two direction lines per channel (PWMA, AIN1, AIN2 and PWMB, BIN1, BIN2), plus a shared STBY line.
  • The BMI160 runs from the ESP32 3.3 V pin and connects over I²C.
  • All modules share one common ground.

Schematics

Click the schematic to open it at full size.

Next steps

  • Driving capability. Let the robot drive forward, back and turn while it keeps its balance.
  • WebSocket control. Send drive commands to the ESP32 over Wi-Fi through a WebSocket connection.
  • ESP-NOW connection. Add a direct ESP-NOW link between the robot and a second ESP32 used as a remote.