Skip to the content
2 layers63.5 × 63.5 mmInverted Pendulum, the printed circuit board in 3D

Self-balancing two-wheeled robot built as the final project for the Control Theory course at the Universidade de Santiago de Compostela (2023/2024).

Size
63.5 × 63.5 mm
Copper layers
2
Thickness
1.6 mm
Parts
9
Nets
45
Pads
75
Tracks, vias
69, 0
Pours
1
Routed
Yes
KiCad
KiCad 7 (file 20221018)
Created
22 Oct 2026
Updated
22 Oct 2026

Overview

Inverted Pendulum is an open-source printed circuit board by MarcosFontenlos, from the MarcosFontenlos/Inverted_Pendulum repository on GitHub. It is a 2-layer board of 63.5 × 63.5 mm with 9 parts on 45 nets, routed with 69 tracks and 0 vias.

It is built around the ESP32-DEVKITC-VE and ROB-14450. Its parts include 4 ICs, 3 connectors and 2 capacitors. It belongs with the ESP32 boards of this library.

Main components

2

README

README.md

Inverted Pendulum

Self-balancing two-wheeled robot built as the final project for the Control Theory course at the Universidade de Santiago de Compostela (2023/2024).

The robot keeps itself upright on two wheels by reading its tilt with an IMU and driving the motors through a PID controller. It also exposes a small Wi-Fi web interface that can be used to move it around or switch the controller on and off.

How it works

  1. Sensing - A MPU6050 IMU is read over I2C. The accelerometer gives an absolute (but noisy) tilt angle, while the gyroscope gives a fast (but drifting) angular rate.
  2. Angle estimation - Both measurements are fused with a complementary filter: angle = 0.98 * (angle + gyro_rate * dt) + 0.02 * accelerometer_angle This yields a smooth and stable estimate of the tilt around the X axis.
  3. PID control - The error is the difference between the desired angle (upright, 0 deg) and the measured angle. The output is: u = Kp * error + Ki * integral + Kd * derivative and is saturated to the PWM range (-255..255).
  4. Actuation - The control signal is applied to both DC motors through a TB6612FNG driver. When the robot leans forward the wheels drive forward, and vice versa, producing the correction torque that brings it back to the vertical position.
  5. Tuning - Gains are adjusted in the classic order: first Kp, then Ki, and finally Kd (in this build Kd was left at 0 because it did not improve the response).

The PID loop runs as fast as possible (small delay), since a high sampling rate is essential for balancing.

Repository contents

PathDescription
Base_FreeCAD/FreeCAD models and STL files for the 3D-printed chassis.
PCB/KiCad project (schematic, board layout, custom symbols/footprints), Gerber files and fabrication backups.
Memoria/LaTeX report (Memoria.tex / Memoria.pdf) documenting the design, hardware and software.
Programas/PID/Arduino sketches for the balancing controller: basic PID, low-pass filtered PID, IIR-filtered PID and PID with Wi-Fi position control.
Programas/Programas_auxiliares/Helper sketches for motor testing, IMU measurements and sensor calibration.
Prueba_esp32/Minimal sketch used to verify that the ESP32 board and toolchain work.
Guion_proyecto.txtShort project log with the first hardware tests.

Hardware

  • ESP32 DevKit-C (main microcontroller, 5 V logic, built-in Wi-Fi).
  • MPU6050 (GY-521) accelerometer + gyroscope, I2C.
  • TB6612FNG dual H-bridge motor driver.
  • 2x DC gear motors with wheels (ROB-14450).
  • 2x 4xAA battery holders in series (12 V for the motors) and an LM7805 linear regulator (5 V for the ESP32).
  • Custom PCB designed in KiCad and a 3D-printed base designed in FreeCAD.

Note: the LM7805 needs at least ~7 V at its input, which is why the two 6 V battery packs are connected in series. The motors receive the full 12 V while the ESP32 is fed with regulated 5 V.

Building and running

Software

  1. Install the Arduino IDE and add ESP32 board support through the Boards Manager.
  2. Install the MPU6050 and I2Cdev libraries.
  3. Open one of the sketches in Programas/ and select the ESP32 Dev Module board and the correct COM port.
  4. Upload the sketch.

Recommended order for a first run:

  1. Prueba_esp32/ - check the board and serial connection.
  2. Programas/Programas_auxiliares/Programa_calibracion_sensor/ - calibrate the IMU offsets with the robot perfectly still.
  3. Programas/Programas_auxiliares/Marcha_motores/ - verify motor direction and wiring.
  4. Programas/PID/Control_PID/ - test and tune the PID.
  5. Programas/PID/PID_posicion/ - final version with Wi-Fi control.

Wi-Fi control

PID_posicion.ino starts the ESP32 as a Wi-Fi access point. Connect to the network shown in the serial monitor and open the IP address (192.168.4.1 by default) in a browser. The page provides forward/backward/left/right buttons, a stop button and buttons to enable or disable the PID.

The AP credentials are defined at the top of the sketch; change them before publishing or deploying the robot.

Authors

  • Marcos Fontenlos Ferreiro

Parts

9
QtyValueFootprintReferences
3Conn_01x02Connector_PinSocket_2.54mm:PinSocket_1x02_P2.54mm_VerticalJ1, J2, J3
10.1 uFCapacitor_THT:C_Axial_L3.8mm_D2.6mm_P7.50mm_HorizontalC2
10.33 uFCapacitor_THT:C_Axial_L3.8mm_D2.6mm_P7.50mm_HorizontalC1
1ESP32-DEVKITCLibreria_personal:MODULE_ESP32-DEVKITCU4
1GY-521Libreria_personal:GY-521U1
1LM7805_TO220Package_TO_SOT_THT:TO-220-3_VerticalU5
1ROB-14450Libreria_personal:MODULE_ROB-14450U2

Similar boards

  • 2 layers94 × 71.1 mmMiPendulo, the printed circuit board in 3D

    MiPendulo

    IznF/Pendulo-Invertido

    Repositorio correspondiente al proyecto del pendulo invertido de Izán Fernández Moreno

    13 parts
  • 2 layers83.8 × 57.8 mmPlaca esp32, the printed circuit board in 3D

    Placa esp32

    walteraguirre/Robot-futbol-LNR

    Robot de futbol para la Liga Nacional de Robótica

    10 parts
  • 2 layers120 × 100 mmRoot, the printed circuit board in 3D

    Root

    GonzaCerv/noah-hardware

    This repo contains all the hardware description for the Noah project. Here lies 3D models, electronics PCB and Firmware software of the robot.

    127 parts28MIT
  • 2 layers102.6 × 82 mmFun, the printed circuit board in 3D

    Fun

    bonavirak/Line-Follower-Robot-Using-STM32F103C8T6-with-TCRT-5000

    Line Follower Robot powered by STM32F103C8T6 microcontroller, using TCRT5000 5-way sensors for line detection, HC-05 for Bluetooth communication, TB6612FNG motor driver, and N20 motors (1000 RPM).

    38 parts11MIT
  • 2 layers42 × 42 mmControllerBoardSingle v1, the printed circuit board in 3D

    ControllerBoardSingle v1

    0x23/BallJointEmbossingMachine

    A motorized linear embossing machine designed to precisely press ball joints. It was designed to automate the production of balljoint linkages for the Open-Micro-Manipulator.

    20 parts9MIT
  • 2 layers90 × 102 mmPL Toon, the printed circuit board in 3D

    PL Toon

    pl-toon/pl-toon-codes

    PL-TOON material

    39 parts7

Questions

How big is the Inverted Pendulum PCB?

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

What parts does the Inverted Pendulum use?

9 parts, built around the ESP32-DEVKITC-VE and ROB-14450. 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 Inverted Pendulum KiCad files?

From the MarcosFontenlos/Inverted_Pendulum repository on GitHub, at the commit this page was made from: the board is PCB/PCB.kicad_pcb and its schematic PCB/PCB.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the Inverted Pendulum design in my own project?

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