Skip to content

ESP32 Encoder-Motor Self-Balancing Robot

A two-wheeled inverted pendulum robot based on an ESP32 that uses PID control and sensor fusion to stay balanced.

  • Other
  • Open source
  • arduino
  • 3D printable

Suggested by Robotheca, created by @sharon082200 (opens in a new tab), from github.com/sharon082200/ESP32-Self-Balancing-Robot (opens in a new tab). Pinned to commit 95178b7 (opens in a new tab).

Photo and 3D model

This repository has no photo of the robot yet.

3D preview converted from github.com/sharon082200/ESP32-Self-Balancing-Robot at 95178b7, under MIT. View the original files from GitHub (697 KB) (opens in a new tab)

Power
7.4 V

What it can do

Written by Robotheca from the project's documents.

  • Balances as a two-wheeled inverted pendulum using real-time PID control running at about 200Hz loop time.
  • Fuses accelerometer and gyroscope data with a complementary filter for stable tilt estimation.
  • Shuts off automatically when tilted more than 35 degrees.
  • Monitors battery voltage and gives LED and buzzer warnings when voltage drops below 5.6V.
  • Integral windup is limited by clamping the Ki term and integrating only when error is small.

Bill of materials

This repository has no parts list Robotheca can read yet.

Build guide

The guide appears here as you scroll.

Guide by @sharon082200 (README.md), under MIT.

Wiring and electronics

Notes written by Robotheca from the project's documents.

Main parts

  • ESP32 DevKit V1 microcontroller (dual core, 240MHz).
  • MPU6050 6-axis gyroscope and accelerometer IMU.
  • L298N dual H-bridge motor driver.
  • 12V DC gear motors with encoders.
  • Two 18650 Li-Ion batteries providing 7.4V to 8.4V.
  • Voltage divider of 33kΩ and 10kΩ feeding the ESP32 ADC for battery monitoring.
  • LED indicator and buzzer for low-battery warnings.

Connections

  • A complete wiring schematic is provided as Schematic.png and Hardware/Schematic.pdf.
  • The battery voltage divider output connects to an ESP32 ADC input.
  • The motor driver, IMU and microcontroller are connected as shown in the schematic.