Back to Projects

BrickPi3 Project

BrickPi3 BalanceBot

A self-balancing Segway robot built with LEGO EV3 parts, BrickPi3, and a Raspberry Pi. Uses the EV3 gyroscope to stay upright and is controlled via the LEGO remote.

Python EV3 Gyroscope Self-Balancing LEGO EV3 Open Source
All the parts needed to build a Raspberry Pi LEGO BalanceBot

Watch It in Action

Overview

The BrickPi3 BalanceBot is a two-wheeled self-balancing robot — a Segway in LEGO form. It uses the EV3 Gyro Sensor to measure its tilt angle and continuously adjusts motor speed to stay upright. The full build uses parts from the LEGO Mindstorms EV3 kit and is controlled wirelessly using the LEGO Remote Control.

All software is written in Python and runs directly on the Raspberry Pi. The BrickPi3 reads the gyroscope over its sensor ports and drives the two EV3 motors through its motor ports — no additional hardware required.

Parts Required

  • BrickPi3 (Base Kit or Core Kit)
  • Raspberry Pi (Pi 3 or Pi 4 recommended)
  • LEGO Mindstorms EV3 Kit (31313) — all structural parts included
  • EV3 Gyro Sensor (included in EV3 kit)
  • LEGO Remote Control
  • microSD card with Raspberry Pi OS Trixie for BrickPi3
  • 12 V battery pack for BrickPi3

Build Instructions

Full building instructions are available in LEGO Digital Designer (LDD) format — download them from the GitHub repository:

All structural parts are included in the standard LEGO Mindstorms EV3 kit. Assemble the chassis following the LDD file, attach the BrickPi3 to the Raspberry Pi, and connect the motors and gyro sensor to the appropriate ports.

Connect the hardware as follows:

  • Left motor → Motor Port A
  • Right motor → Motor Port D
  • EV3 Gyro Sensor → Sensor Port 1
BrickPi3 BalanceBot assembled

Running the Software

All software is free and open source on GitHub:

Quick Start

git clone https://github.com/DexterInd/BrickPi3.git
cd BrickPi3/Software/Python/Projects/BalanceBot
sudo python BalanceBot.py

On-screen instructions will guide you through the setup and calibration steps. Place the robot upright before running — it will calibrate the gyro on startup and begin balancing automatically.

How It Works

The Python program reads the EV3 Gyro Sensor angle once per control loop. A PID (Proportional–Integral–Derivative) controller calculates the motor output needed to keep the tilt angle at zero. The BrickPi3 sends that output to the two EV3 motors. At the same time, the program reads the LEGO IR Remote Control for forward/backward/turn commands, which it adds as an offset to the balance setpoint.

BrickPi3 BalanceBot side view

Build Your Own

All source code, build files and documentation are free on GitHub.