Back to engineering projects
// PRJ_004 · Real-Time Embedded

Real-Time
Football Tracker.

A wearable ESP32 + FreeRTOS system that classifies in-game actions — dribbles, passes, shots — in real time, while an ultrasonic sensor watches the space around the player. Multi-task scheduling, dynamic acceleration thresholds, and angle validation all run on the player's foot.

Project type
Real-time embedded wearable
Role
Firmware · Sensing & mechanical design
Core systems
ESP32 · FreeRTOS · IMU · ultrasonic
Focus
Live event classification
The 3D-printed football tracker mounted on a player's ankle
// Ankle-mounted prototype · ESP32 + ultrasonic
MCU
ESP32 FreeRTOS · multi-task
Motion
MPU6050 I²C · 400 kHz · 20 Hz sample
Proximity
HC-SR04 40 kHz · 2-400 cm · ±3 mm
Logic rate
100 Hz real-time game decisions
// 01 — Problem

Turn a foot into a sensor.

Football performance analytics typically rely on broadcast video or expensive stadium-wide tracking. The brief: build a wearable, real-time system that monitors a single player's interactions with the ball — dribbles, passes, shots — while also detecting nearby defenders, all on a microcontroller. Latency matters: the system has to keep up with live play.

Goals

  • Classify ball touches into dribbles, passes, and shots
  • Validate touches against valid foot angles to reject false positives
  • Detect defenders entering a 150 cm threshold around the player
  • Run everything on a battery-friendly, multi-task FreeRTOS schedule

Design tradeoffs

Three concepts were compared via FMEA: ball-mounted IMU + UWB anchors, foot-mounted IMU + ultrasonic, and a multi-IMU BLE mesh. Concept 2 won on feasibility, ruggedness and cost — the FMEA flagged ultrasonic beam-occlusion as the highest-RPN risk and drove the mounting and field-of-view decisions.

// 02 — Detection Pipeline

Two sensors. One real-time scheduler.

The MPU6050 handles motion classification at high rate. The HC-SR04 watches for nearby defenders at low rate. FreeRTOS keeps both tasks isolated and passes events to a logic task through queues — so a 10-second ultrasonic ping can never block a 20 Hz IMU read.

Sample the IMU at 20 Hz

The MPU6050 streams accelerometer + gyroscope data over I²C at 400 kHz. Touch detection looks for sudden acceleration spikes; classification thresholds split the action: dribble (2.0-3.0 g), pass (3.0-5.0 g), shot (> 5.0 g).

Validate by foot orientation

Pitch and roll are computed from accelerometer components — pitch via atan2(accel_y, sqrt(accel_x² + accel_z²)), roll via atan2(-accel_x, accel_z). Touches outside valid playing angles are discarded as false positives.

Scan for defenders every 10 s

HC-SR04 fires a 10 µs trigger pulse, emits eight 40 kHz ultrasonic bursts, and times the echo. Distance = (pulse · 343 m/s) / 2. A 30 ms timeout prevents lockup in noisy environments.

FreeRTOS coordinates everything

Sensor tasks are independent; a logic task at priority 6 owns touch decisions; the defender task runs at priority 4. Queue-based message passing keeps tasks decoupled. A possession/off-ball state machine drives the live statistics output.

Real-time tactical feedback

"GOOD POSITIONING — clear space" if the nearest defender is > 150 cm; "BAD POSITIONING — defender in close proximity" otherwise. Action counts (dribbles / passes / shots) update live alongside max-acceleration tracking.

// 03 — Build

A custom CAD enclosure, strapped to a foot.

The hardware lives in a 3D-printed ESP32-S3 case designed in Fusion 360 and sliced on a Bambu Lab A1. Two openings expose the HC-SR04 transducers; a separate clip holds the MPU6050 close to the player's ankle. Cabling is strain-relieved through the strap to survive a real game.

Mechanical

  • Fusion 360 CAD of a slim ESP32-S3 case with a slide-in lid
  • Cutouts sized for the HC-SR04 transducers and USB-C access
  • Velcro strap channel integrated into the body for a clean fit
  • Printed on a Bambu Lab A1 in PLA, 0.20 mm layer height

Firmware

  • FreeRTOS tasks for IMU acquisition, ultrasonic scan, logic, and output
  • Inter-task queues for motion events and proximity readings
  • Possession / off-ball finite state machine
  • Calibration sketches for the MPU6050 across ±2g / ±16g and ±250°/s ranges
  • Live statistics over serial: action counts, max-g, current state
ESP32 / ESP32-S3 FreeRTOS MPU6050 IMU HC-SR04 Ultrasonic I²C @ 400 kHz Fusion 360 Bambu Lab A1 FMEA Sensor calibration
// 05 — Outcome

A real wearable, real time.

The system reliably distinguishes the three action classes during bench tests and continues to run cleanly when worn. The ultrasonic threshold gives a readable, immediate "good positioning" / "bad positioning" call without starving the IMU pipeline. The dual-sensor architecture cleanly separates technical skill (motion) from tactical awareness (space) — and the FreeRTOS scaffolding leaves room to add sensor fusion or BLE telemetry later.

What worked

  • Hard task isolation via FreeRTOS — no scheduling surprises under load
  • Angle validation cut down false touch detections substantially
  • Bambu Lab A1 print quality made the wearable look and feel finished
  • FMEA caught the ultrasonic beam-blind-spot risk early

What I'd change

  • Add complementary-filter sensor fusion for cleaner orientation
  • Stream events over BLE instead of serial for true wireless use
  • Replace HC-SR04 with a multi-zone ToF array to eliminate beam blind spots
  • Add on-device storage for full-game replay and post-match analytics