Skip to main content
Version: FILS English

Ball Balancing Platform

A real-time embedded system that keeps a ball balanced in the center of a moving platform.

info

Author: Dmytro Chumakov
GitHub Project Link: https://github.com/UPB-PMRust-Students/fils-project-2026-cchumak

Description

This project represents a ball balancing platform capable of maintaining a small ball in a stable position by continuously adjusting the angle of the platform.

The platform uses two HC-SR04 ultrasonic sensors to detect the ball position on two axes. Based on the measured distance values, the STM32F407 microcontroller calculates the error between the current position and the desired position of the ball.

After calculating the error, the system applies a PID control algorithm that determines how much the platform needs to tilt in order to bring the ball back to the center.

Servo motors are responsible for physically moving the platform. They receive PWM signals generated by the microcontroller and adjust the angle accordingly.

The project combines embedded programming, real-time processing, control systems, and mechanical design into a single functional prototype.


Motivation

I wanted to build something that combines both software and hardware in a practical way.

During the semester I became interested in embedded systems because I liked the idea of writing code that directly controls physical components.

A ball balancing platform seemed like a challenging but interesting project because it involves multiple engineering areas at the same time. It requires sensors for position detection, motors for movement, mathematical control algorithms, and embedded software that must react quickly.

Another reason I chose this project is because it demonstrates how a relatively simple microcontroller can solve a complex real-time control problem.

I also wanted to challenge myself by implementing the project in Rust, since it provides memory safety while still being suitable for embedded systems.


Architecture

The system is divided into three main subsystems.

The sensing subsystem is responsible for detecting the current position of the ball. Two HC-SR04 ultrasonic sensors measure the distance between the ball and the platform boundaries.

The processing subsystem is represented by the STM32F407 microcontroller. It reads sensor data, processes measurements, calculates the position error, and executes the PID algorithm.

The actuation subsystem consists of servo motors that physically move the platform by changing its angle on different axes.

The complete flow of the system looks like this:

HC-SR04 Sensors → STM32F407 → PID Controller → Servo Motors → Platform Movement

The process repeats continuously in real time until the ball reaches a stable position.

[System architecture](draw in progress)


Log

Week 6

I started researching existing ball balancing systems and decided what type of sensors I wanted to use.

Initially I considered using a camera for ball tracking, but later I decided that ultrasonic sensors would simplify the implementation and reduce processing requirements.

I also selected STM32F407 as the main microcontroller platform.


Week 7

I ordered the electronic components and started designing the physical platform.

During this stage I tested the HC-SR04 sensors separately and verified that I could obtain stable distance measurements.

I also started learning how servo motors behave under PWM control.


Week 8

I began implementing the platform movement mechanism.

I connected the servo motors to the STM32 board and successfully controlled them using Rust.

The next challenge was integrating the sensor readings with motor control logic.


Week 9

I plan to implement the PID controller and tune the constants to achieve stable balancing behavior.

This will probably be the most difficult stage because incorrect tuning can lead to oscillation or unstable movement.


Hardware

The central component of the project is the STM32F407 microcontroller board.

The ball position is detected using two HC-SR04 ultrasonic sensors placed strategically on the platform.

Servo motors are used to tilt the platform and correct the movement of the ball.

The physical platform itself will be built using lightweight materials that allow smooth movement.

[Hardware diagram](draw in progress)


Schematics

The electrical schematic will include:

STM32F407 GPIO connections to both ultrasonic sensors

PWM output connections to the servo motors

Power supply connections

Ground connections for all components

A complete KiCAD schematic will be added later.


Bill of Materials

DeviceUsagePrice
STM32F407 DiscoveryMain microcontroller~150 RON
HC-SR04 Ultrasonic SensorBall position detection~15 RON x2
Servo Motor SG90/MG996RPlatform movement~25 RON x2
BreadboardPrototyping~10 RON
Jumper wiresConnections~10 RON
Power supplyPower source~30 RON
Platform materialsMechanical construction~50 RON
BallObject to balance~10 RON

Software

LibraryDescriptionUsage
embassy-stm32STM32 hardware abstractionGPIO and PWM control
embassy-executorAsync task executionRunning multiple tasks
embassy-timeTimersDelays and scheduling
embedded-halHardware abstraction layerPeripheral communication
defmtDebuggingLogging
defmt-rttDebuggingReal-time logs
panic-probeError handlingPanic debugging
micromathMathematical calculationsPID calculations

Control Algorithm

The balancing system uses a PID controller.

The proportional component reacts to the current error.

The integral component helps eliminate accumulated error over time.

The derivative component predicts future movement and reduces oscillation.

The controller output determines how much the servos need to rotate in order to stabilize the ball.


Challenges

One of the biggest challenges is achieving accurate ball detection using ultrasonic sensors.

Another challenge is tuning the PID constants correctly.

Mechanical instability may also create problems if the platform structure is not rigid enough.

Real-time responsiveness is extremely important because even small delays can make the system unstable.


Future Improvements

A future version of this project could use computer vision instead of ultrasonic sensors.

The platform could also be redesigned using 3D printed components for better precision.

Wireless monitoring through Bluetooth or Wi-Fi could also be added.


  1. https://embassy.dev/
  2. https://doc.rust-lang.org/book/
  3. https://www.st.com/en/microcontrollers-microprocessors/stm32f407vg.html
  4. https://components101.com/sensors/ultrasonic-sensor-working-pinout-datasheet