Skip to the content
2 layers120 × 70 mmBalancing robot pcb, the printed circuit board in 3D

ESP32 Self Balancing Remote Controleld Pendulum Bot.

Size
120 × 70 mm
Copper layers
2
Thickness
1.6 mm
Parts
48
Nets
51
Pads
167
Tracks, vias
473, 104
Pours
243
Routed
Yes
KiCad
KiCad 10.0 (file 20260206)
Created
22 Sep 2026
Updated
22 Oct 2026

Overview

Balancing robot pcb is an open-source printed circuit board by simonceglarz, from the simonceglarz/self-balancing-rc-robot repository on GitHub. It is a 2-layer board of 120 × 70 mm with 48 parts on 51 nets, routed with 473 tracks and 104 vias.

It is built around the LSM6DSOX. Its parts include 17 connectors, 8 capacitors, 8 resistors, 1 diode and 1 switch. It belongs with the robots and motor control boards and the ESP32 boards of this library.

Main components

1

README

README.md

ESP32 Self-Balancing Robot

A two-wheeled self-balancing robot built around an ESP32, an IMU, and a cascaded PID control loop — with a live WiFi tuning interface and a dedicated wireless joystick controller.

demo Full-length demo (27s, MP4)

Overview

This robot balances on two wheels using a complementary filter for orientation estimation and a two-loop (cascaded) PID controller: an inner loop holds the body upright, and an outer loop corrects for long-term drift by tracking wheel velocity from quadrature encoders. It can be driven and steered two ways — a phone/browser joystick served directly from the robot's own WiFi access point, or a dedicated physical ESP32 + analog-joystick controller communicating over ESP-NOW.

Features

  • Cascaded PID control — inner loop (angle) + outer loop (velocity/drift), tuned live rather than by reflashing
  • WiFi live-tuning webpage — the ESP32 hosts its own access point and a WebSocket-driven page with sliders for every gain, calibration constant, and per-motor floor, plus a draggable on-screen joystick for driving
  • Physical joystick controller — a second ESP32 reading an analog joystick, sending continuous steering data over ESP-NOW (no phone required, lower latency than WiFi)
  • Per-motor stiction compensation — independently tunable output floors and a proportional rescale, since the two motors' real-world behavior isn't identical
  • Hysteresis-based deadband — a Schmitt-trigger style engage/disengage threshold to suppress motor chatter at equilibrium without losing responsiveness to small corrections
  • Smoothly ramped inputs — commanded lean/steer values slew toward their target instead of stepping instantly, avoiding derivative-kick spikes
  • OLED live telemetry — angle, motor output, encoder-derived velocity, battery voltage, and a small tilt-indicator graphic

Hardware

ComponentNotes
ESP32 dev board (x2)one for the robot, one for the joystick controller
Adafruit LSM6DSOX6-axis IMU (accelerometer + gyro)
SSD1306 OLED (128x64, I2C)onboard telemetry display
2x DC motor + quadrature encodersdrive + odometry
Motor driver (dual H-bridge)AIN1/AIN2, BIN1/BIN2 control
2-axis analog joystick modulephysical controller input
LiPo battery + voltage dividerrobot power + monitoring via analogReadMilliVolts()
Buck regulator (Adafruit MPM3610, 5V)steps the 7.4V 2S LiPo down to 5V for the ESP32
Reverse-polarity protection (1N5822 Schottky)sits ahead of the buck input, ~0.35V drop

Build

Full assembled chassisInter-layer wiring detail
Assembled 3-layer 3D-printed chassis — top plate carries the LiPo battery and OLED, middle plate holds the ESP32, IMU, and perfboard wiring, bottom plate mounts the motor driver. Brass standoffs separate the layers.Rear view showing inter-layer wiring and one of the two drive wheels.

Architecture

text
IMU (accel + gyro) ──► complementary filter ──► angle estimate
                                                     │
                          ┌──────────────────────────┘
                          ▼
              inner loop: PID(Kp, Ki, Kd) on angle error
                          │
              outer loop: velocity/drift correction
              (encoder-derived velocity → Kp_vel/Ki_vel → shifts
               the angle setpoint to correct long-term drift)
                          │
                          ▼
        per-motor floor rescale + hysteresis deadband
                          │
                          ▼
                   motorA() / motorB() (PWM)

Input arrives from either the WebSocket ('J:x:y' from the webpage joystick, or discrete gain/calibration updates from the tuning sliders) or ESP-NOW (the physical joystick controller) — both write into the same targetAngleTrim/steerBias variables, so the control loop doesn't care which source is driving it.

Power Architecture

2S LiPo (7.4V nominal, 8.4V full) │ ▼ 1N5822 Schottky diode (reverse-polarity protection, ~0.35V drop) │ ▼ power node ──┬── DRV8833 VM (motors run off the unregulated battery rail) ├── 2× 1000µF bulk caps + 100nF ceramic → GND └── MPM3610 buck regulator (Vin) │ ▼ 5V out → ESP32 5V pin │ ▼ ESP32 internal LDO → 3.3V rail │ ┌───────────┼───────────┐ ▼ ▼ ▼ IMU + OLED Encoder VCC DRV8833 SLP (I2C) (must be held high or driver sleeps)

Motors draw directly off the unregulated battery rail (through the protection diode) since they don't need clean power; logic and sensors run off the regulated 5V → 3.3V chain, which does.

Bench-verified (multimeter):

Measurement pointReading
Diode cathode (post-protection)8.05 V
MPM3610 output5.00 V
ESP32 3.3V pin3.32 V
Battery rail under full motor load7.77 V (no sag — bulk caps holding)

Custom PCB (rev 1)

The perfboard is being replaced by a 2-layer KiCad PCB (120 \C3\97 70 mm) that carries the ESP32, motor driver and buck converter on sockets.

PCB render

  • Separate I2C bus for the IMU, so OLED refreshes (~23 ms) can't delay the 100 Hz control loop
  • 8 GPIOs remapped so motor and encoder traces route without crossings; selected in firmware with #define PCB_REV1
  • Trace widths sized by current (1.5 mm battery, 1.0 mm motor, 0.5 mm 5 V)
  • 20-pin expansion header for v2 add-ons: servos, I2S speaker, UART and extra I2C sensors
  • Debug headers for motor PWM and encoder signals that sit under the modules

Status: ordered from JLCPCB, bring-up in progress. Full write-up, pinouts and design notes: pcb/README.md

Setup

Each firmware is its own PlatformIO project.

Robot (robot/):

  1. pio run --target upload from within robot/
  2. Power on, open the serial monitor (115200 baud) — it prints the WiFi AP IP and its ESP-NOW MAC address
  3. Connect a phone/laptop to the BalanceBot AP and open http://<AP IP>/ for the tuning page

Controller (controller/):

  1. Wire the joystick module: VRx→GPIO34, VRy→GPIO35, SW→GPIO32, VCC→3.3V, GND→GND
  2. Set robotMac[] in controller/src/main.cpp to the robot's printed AP MAC address
  3. Confirm WIFI_CHANNEL matches between both projects
  4. pio run --target upload from within controller/

Both projects are pinned to the same platform version (see each platformio.ini) — this matters, since ESP-NOW callback signatures changed between core versions and mismatched cores between the two boards can cause hard-to-diagnose link failures.

Debugging notes / what I actually learned building this

  • Output floor destroyed proportionality. A flat "snap any nonzero output up to the motor's stiction floor" made the controller bang-bang, not proportional, for the entire range under a few degrees of error — the majority of actual operating time. Fixed by rescaling the output range onto [MIN_OUTPUT, MAX_OUTPUT] per motor instead of snapping.
  • Encoder velocity math is a real kinematics problem, not an arbitrary sign choice. Diagnosing whether avgVelocity should combine the two encoders by addition or subtraction meant understanding what each raw sign actually meant physically (translation vs. yaw), not just trying both and picking whichever "looked less bad." Verified empirically with a manual push test (motors disabled, print raw deltas) rather than guessing.
  • A control loop can have the wrong sign of an otherwise-correct formula. Reversing the encoder combination made the outer loop feed real motion back into itself as positive feedback instead of negative — the difference between correcting drift and amplifying it into a runaway, from one flipped sign.
  • Deadbands need hysteresis, not a single threshold. A flat deadband still has exactly one crossing point, and standing-still equilibrium sits right on top of it — sensor noise flickering across that single threshold was the actual jitter, not "too much" or "too little" deadband. A two-threshold (engage/disengage) hysteresis fixed it structurally instead of by tuning a magic number.
  • A hard on/off switch in a control loop creates a real discontinuity. Suppressing the outer loop during a turn (to stop it reacting to a turn-induced phantom velocity reading) fixed the turn-tipping, but re-enabling it instantly the moment steering stopped caused a visible jerk — full-strength correction plus whatever stale value existed applied in a single tick. Replaced with a ramped suppression factor.

Known limitations / open items

  • ANGLE_TRIM_DEG (the sensor-to-mechanical zero offset) drifts somewhat run-to-run; auto-calibration was considered but not implemented.
  • Turning still relies on suppressing the outer loop rather than a from-first-principles kinematic decoupling of translation and rotation.
  • No IMU cross-axis leakage compensation (untested whether it's actually present on this build).

Parts

48
QtyValueFootprintReferences
4100Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR1, R2, R3, R4
4MountingHoleMountingHole:MountingHole_3.2mm_M3H1, H2, H3, H4
310nFCapacitor_THT:C_Disc_D3.0mm_W2.0mm_P2.50mmC5, C6, C7
3GNDTestPoint:TestPoint_THTPad_D2.0mm_Drill1.0mmTP6, TP7, TP8
21000uFCapacitor_THT:CP_Radial_D10.0mm_P5.00mmC1, C2
2100nFCapacitor_THT:C_Disc_D3.0mm_W2.0mm_P2.50mmC3, C8
24.7kResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR8, R9
1100kResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR5
110nCapacitor_THT:C_Disc_D3.0mm_W2.0mm_P2.50mmC4
11N5822Diode_THT:D_DO-201AD_P15.24mm_HorizontalD1
13V3TestPoint:TestPoint_THTPad_D2.0mm_Drill1.0mmTP3
147kResistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR6
15VTestPoint:TestPoint_THTPad_D2.0mm_Drill1.0mmTP2
1<- USB ESP32_LeftConnector_PinSocket_2.54mm:PinSocket_1x19_P2.54mm_VerticalJ3
1<-USB ESP32_RightConnector_PinSocket_2.54mm:PinSocket_1x19_P2.54mm_VerticalJ4
1DRV8833_BreakoutConnector_PinSocket_2.54mm:PinSocket_1x08_P2.54mm_VerticalJ5
1DRV_OutputsConnector_PinSocket_2.54mm:PinSocket_1x06_P2.54mm_VerticalJ6
1EXPANSIONConnector_PinSocket_2.54mm:PinSocket_2x10_P2.54mm_VerticalJ15
1Enc_DebugConnector_PinSocket_2.54mm:PinSocket_1x06_P2.54mm_VerticalJ16
1Encoder_AConnector_JST:JST_XH_B4B-XH-A_1x04_P2.50mm_VerticalJ9
1Encoder_BConnector_JST:JST_XH_B4B-XH-A_1x04_P2.50mm_VerticalJ10
1I2C_B_1Connector_PinSocket_2.54mm:PinSocket_1x04_P2.54mm_VerticalJ13
1I2C_B_2Connector_PinSocket_2.54mm:PinSocket_1x04_P2.54mm_VerticalJ14
1LSM6DSOXConnector_PinSocket_2.54mm:PinSocket_1x05_P2.54mm_VerticalJ7
1MPM3610_BreakoutConnector_PinSocket_2.54mm:PinSocket_1x04_P2.54mm_VerticalJ2
1Motor_AConnector_JST:JST_XH_B2B-XH-A_1x02_P2.50mm_VerticalJ11
1Motor_BConnector_JST:JST_XH_B2B-XH-A_1x02_P2.50mm_VerticalJ12
1Motor_DebugConnector_PinSocket_2.54mm:PinSocket_1x05_P2.54mm_VerticalJ17
1PWR_SWbalancing_robot_pcb:SW_MTS102_SPDT_3PinSW1
1QR_LinkedIn_14.8mmQR_Logos:QR_LinkedIn_14.8mmLOGO**
1SCLTestPoint:TestPoint_THTPad_D2.0mm_Drill1.0mmTP5
1SDATestPoint:TestPoint_THTPad_D2.0mm_Drill1.0mmTP4
1SSD1306Connector_PinSocket_2.54mm:PinSocket_1x04_P2.54mm_VerticalJ8
1VBATTestPoint:TestPoint_THTPad_D2.0mm_Drill1.0mmTP1
1XT60_BatteryConnector_AMASS:AMASS_XT60-M_1x02_P7.20mm_VerticalJ1

Similar boards

  • 2 layers33 × 58.8 mmFusion, the printed circuit board in 3D

    Fusion

    chungyu710/Fusion

    Capstone Design Project

    36 parts4
  • 2 layers56 × 6.2 mmRing pcb, the printed circuit board in 3D

    Ring pcb

    dezash123/ring-pcb

    60 parts2
  • 6 layersSentinel HYDRA, the printed circuit board in 3D

    Sentinel HYDRA

    dhruv1859/CARVantaBAC

    🧬 CARVanta Next-Generation Precision Oncology & AI CAR-T Cell Platform Interactive 3D Biological Digital Twin • 3D Neural Bridge • Sentinel HYDRA Biosensor

    135 parts1Apache-2.0
  • 4 layers62.9 × 42.5 mmPCB Design PFE, the printed circuit board in 3D

    PCB Design PFE

    khawlahhouki/fatigue-detection-edge-ai

    Real-time physical fatigue detection using Edge AI on STM32H7 with FreeRTOS, biosignal acquisition (PPG, EMG, IMU) and TFLite INT8 inference

    64 parts1
  • 2 layers23 × 83 mmL Smart Baton, the printed circuit board in 3D

    L Smart Baton

    yuanf2004/smart-baton-kicad

    54 parts1
  • 4 layers41 × 41 mmPulser3, the printed circuit board in 3D

    Pulser3

    aaritkoundinya/Pulse

    After creation, open KiCad and work in boards/ /.

    72 parts
  • 2 layers27.6 × 30.5 mmMotionRecognitionWatch, the printed circuit board in 3D

    MotionRecognitionWatch

    AidenBTTU/Gesture-Capture-Watch

    A wristband-mounted gesture recognition system built around an STM32F411, IMU, and OLED display, with USB-C battery charging and ESD-protected I/O.

    46 parts
  • 4 layers20 × 20 mmCansat sensor board, the printed circuit board in 3D

    Cansat sensor board

    AnmolS-EE/TMU-CanSat-Electrical-Onboarding-2026

    17 partsMIT

Questions

How big is the Balancing robot pcb PCB?

It measures 120 × 70 mm and has 2 copper layers, 1.6 mm thick.

What parts does the Balancing robot pcb use?

48 parts, built around the LSM6DSOX. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the Balancing robot pcb KiCad files?

From the simonceglarz/self-balancing-rc-robot repository on GitHub, at the commit this page was made from: the board is pcb/kicad/balancing_robot_pcb.kicad_pcb and its schematic pcb/kicad/balancing_robot_pcb.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the Balancing robot pcb design in my own project?

Its repository states no licence, so its author keeps all rights: ask simonceglarz before reusing the design.