FINAL PROJECT

JAVIER VEGA // PROJECT LOG

FINAL PROJECT

The AI Goal Sentinel is a portable device that turns any regular soccer goal into a smart training system. You simply attach it to the crossbar, and it is ready to use. It automatically detects your shots and sends data instantly to your phone or computer, showing you the speed of the ball and exactly where it entered the goal. It turns a normal practice session into a fun, measurable game.

I am making this project because professional football tools are usually too expensive and hard to use for normal players. Most people cannot measure how fast they shoot or improve their accuracy with data. This project solves that problem by creating a cheap and easy-to-use device that lets anyone track their progress, just like professional athletes do.

THE ORIGIN STORY (MOTIVATION)

I have been passionate about football since I was a kid. It's not just a hobby; it's part of who I am. However, training alone can be difficult without feedback. I often wonder: "How fast was that shot?" or "Did I hit the corner precisely?"

This project combines my love for the sport with digital fabrication. My goal is to build a device that helps players like me improve their accuracy and power through real-time data, making training sessions more effective and fun.

The AI Goal Sentinel is an autonomous device designed to attach to any standard goalpost. To achieve portability and precision, the system integrates the following hardware components:

A. ELECTRONICS & LOGIC

  • XIAO ESP32C6: Powerful microcontroller with integrated Wi-Fi and Bluetooth unit running bare-metal C for microsecond precision.
  • Custom PCB: Fabricated board to integrate MCU, hardware protection, and sensor connections.
  • 8x Diffuse Photoelectric Sensors (3m): Industrial-grade laser sensors arranged to create an invisible speed trap.
  • SS14 SMD Diodes: Critical logic-level hardware protection.

B. POWER & MECHANICS

  • Powerbank (5V): Provides portable autonomy.
  • 3D Printed Body: Weather-resistant cases ensuring sensors correctly face the player in parallel lines.
  • Velcro Straps: Flexible quick-release mechanism for the posts.

CRITICAL RESEARCH: BALL DETECTION

To catch a football traveling at 70+ km/h, the optical hardware needs an insanely fast response time. I initially evaluated a standard 30cm diffuse sensor but rejected it due to its short range. I then considered complex retroreflective sensors, but a major breakthrough changed the project's direction.

Yellow Diffuse Sensor

1. Solviora E3F-DS30C4 (Standard)

  • Response Time: 1 ms (Excellent)
  • Range: 3 - 80 cm
  • Verdict: REJECTED

Analysis: While the 1ms response time was perfect for high-speed tracking, its maximum range of 30 cm is a critical failure point. A football passing through the center of the net would go undetected.

Yellow Diffuse Sensor

2. E3F 3-Meter Diffuse Variant

  • Response Time: 1 ms (Instant Reaction)
  • Range: Up to 3 Meters (300 cm)
  • Verdict: SELECTED

Analysis: THE PLOT TWIST. I discovered an upgraded industrial variant of the yellow sensor that extends the diffuse range to a massive 3 meters. This eliminates the need to align complex reflector plates across the goal, while keeping the crucial 1ms reaction time to prevent blind spots. Best of all: it keeps the budget low.

TOP SECRET SCHEMATIC

Initial Concept Sketch v1.0

Final Project Sketch

Fig 1. First hand-drawn visualization of the system components and placement on the goal frame.

FULL-SCALE GOAL CONCEPT

The system will be implemented on a physical goal structure with a size of 1 meter height and 1.3 meters width. This compact format allows portability while still providing a realistic training experience.

The design includes a total of 8 sensors, distributed symmetrically: 4 sensors on the left post and 4 sensors on the right post.

These sensors create multiple detection zones across the goal area. When the ball crosses, the system identifies the entry position, approximates the shot trajectory, and calculates speed using the time difference between sensor triggers.

SYSTEM DIAGRAM

Goal sensor diagram

Fig 2. Sensor distribution along both vertical posts to detect ball crossing position and speed.

SYSTEM WORKFLOW

⚽ Ball crosses goal →
📡 Sensors detect interruption →
🧠 ESP32 processes timing data →
📊 Calculates position + speed →
📱 Sends data to user interface

BUILDING AN INVISIBLE TUNNEL

Instead of using expensive Doppler radars or complex 160-degree camera tracking, the AI Goal Sentinel uses pure physics. We are building a "Speed Trap" (Time-of-Flight Gate) identical to the ones used in ballistic chronographs and professional sports setups.

The Sequence of Events
  1. 4 sensors are placed on the front edge of the goal post, and 4 sensors are placed on the back edge, creating two perfectly parallel laser planes separated by a known physical distance.
  2. When the ball crosses the first plane, it triggers a hardware interrupt. The XIAO ESP32C6 starts a high-precision internal microsecond timer.
  3. When the ball crosses the second plane, the timer is stopped.
  4. Using the fixed distance and the exact time difference, the MCU calculates the final speed using standard kinematics: v = d / Δt.

Moving to industrial 3-meter sensors created a massive electrical hazard. The chosen sensors operate at 12V, but the XIAO ESP32C6 microcontroller operates strictly at 3.3V. If a 12V signal hits the XIAO pins, the board will fry instantly.

The Solution: Logic-Level Valve To protect the board without relying on bulky optocouplers, the custom PCB integrates SS14 Schottky SMD Diodes acting as one-way valves.
  • The diode is placed with its cathode (grey line) pointing toward the sensor's signal wire.
  • Idle (No Ball): The sensor outputs 12V. The diode blocks it entirely. The XIAO pin remains safely HIGH via its internal 3.3V pull-up.
  • Triggered (Ball Detected): The NPN sensor connects the line to Ground (0V). The diode "opens", pulling the XIAO pin to LOW, successfully registering a hit without exposing the board to dangerous voltages.

TEST 01 — INFRARED DISTANCE SENSORS

What was tested Checking sensor response time, detection range, and signal stability simulating a ball entering the goal.

TEST 02 — AI VISION: VIRTUAL GOAL ZONE

What was built A web interface using ml5.js to track an index finger. Entering a virtual "Goal Zone" sends a physical signal via Web Serial API to the MCU.

How It Works — The 5-Step Architecture

STEP 1: THE STAGE (HTML & CSS) First, we need a place to show the camera. In HTML, we create a <video> tag. Over that video, we place two transparent elements using CSS absolute positioning: The Crosshair (follows the finger) and The Goal Zone (the target).
STEP 2: SUMMONING THE AI (ML5.js) We feed our webcam video into ml5.handpose(). The AI places exactly 21 tracking landmarks on the hand's joints. Landmark #8 is always the tip of the index finger. JavaScript reads its X and Y coordinates every frame.
// Get the raw coordinates of Landmark #8 (Index Finger Tip)
let x = results[0].landmarks[8][0];
let y = results[0].landmarks[8][1];
STEP 3: THE HITBOX MATH Webcams are mirrored by default. To fix this, we subtract the X coordinate from the video width: let invertedX = 640 - x;. Then we check all four boundaries to see if the finger is inside the goal area.
let invertedX = 640 - x; // Fix the webcam mirror effect

let isInside = (invertedX > 195 && invertedX < 445 && y > 150 && y < 330);

if (isInside) {
    goalAlert.innerText = "GOAL SCORED!";
}
STEP 4: THE HARDWARE BRIDGE (Web Serial API) Browsers run in a sandbox. The Web Serial API bypasses this safely. If the finger enters the zone, the browser sends a "1" through USB to turn the physical LED ON. If it leaves, it sends "0".
STEP 5: CONNECTING THE HARDWARE Once connected via the Web Serial prompt, the system status changes from DISCONNECTED to ONLINE.
Before connecting
Before pressing CONNECT
After connecting
After selecting the serial port

System In Action

Video 1: Browser AI tracking the index finger & Goal Zone detection.
Video 2: Physical Hardware LED turning ON via Web Serial signal.

AI SIDEKICK LOG

Full Disclosure: To bring this AI Vision prototype to life, I enlisted the help of an AI assistant (Gemini) as a coding co-pilot. I knew conceptually what I wanted (tracking a finger to trigger a physical LED goal), but the AI pointed me to ml5.js for the hand-tracking network and the Web Serial API to bridge the browser with the hardware. Together we iterated on the mirror correction trick and the hit-box math. All final decisions, testing, and hardware validation were done by me.

!
Conclusion: This directly validates the Final Project architecture. The Smart Precision Goal needs exactly this pipeline: detect an event → process it → fire a hardware signal → report to a visual interface.

TEST 03 — SPEED TRAP (15CM BENCH TEST)

What was built The final validation of the "Time-of-Flight" logic. Two sensors were placed 15cm apart on a workbench. The microcontroller was programmed with hardware interrupts (`RISING`) to measure the microsecond difference when a hand was passed through the lasers. The data was sent via Serial to a Python Flask local server, which hosted the real-time "Comic Dashboard".
Real-time Speed Trap test. Passing a ball across two sensors separated by 15cm, sending microsecond calculations to Python.
// XIAO ESP32C6: Hardware Interrupt Logic (C++)
const int sensorAdelante = 28; 
const int sensorAtras = 5;    
const float distancia_metros = 0.15; 

volatile unsigned long tiempoInicio = 0;
volatile unsigned long tiempoFin = 0;
volatile bool enVuelo = false;
volatile bool calculoListo = false;

// Hardware Interrupts triggered on RISING signal (0V to 3.3V)
void isrAdelante() {
  if (!enVuelo) {
    tiempoInicio = micros();
    enVuelo = true;
  }
}

void isrAtras() {
  if (enVuelo && !calculoListo) {
    tiempoFin = micros();
    calculoListo = true;
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(sensorAdelante, INPUT);
  pinMode(sensorAtras, INPUT);
  attachInterrupt(digitalPinToInterrupt(sensorAdelante), isrAdelante, RISING);
  attachInterrupt(digitalPinToInterrupt(sensorAtras), isrAtras, RISING);
}

void loop() {
  if (calculoListo) {
    unsigned long deltaMicros = tiempoFin - tiempoInicio;
    float tiempoMs = deltaMicros / 1000.0; 
    
    // v = d / t
    float tiempoSegundos = deltaMicros / 1000000.0;
    float velocidadMs = distancia_metros / tiempoSegundos; 
    float velocidadKmh = velocidadMs * 3.6; 
    
    Serial.print("HIT:");
    Serial.print(velocidadKmh);
    Serial.print(":");
    Serial.println(tiempoMs);

    enVuelo = false;
    calculoListo = false;
  }
}

Roadmap aligned with the Fab Academy 2026 Official Schedule.

  • WEEK 1 (JAN 21)

    Project Management

    Defining the concept, sketching the initial idea, and setting up the documentation website (Git & HTML).

  • WEEK 2 (JAN 28)

    Computer-Aided Design

    Creating the first 2D and 3D representations of the goal structure using SolidWorks.

  • WEEK 3 (FEB 04)

    Computer-Controlled Cutting

    Laser cutting a scale model to test the mechanism and verify the folding system.

  • WEEKS 6-8 (FEB-MAR)

    Electronics Design & Production

    Designing the custom PCB in KiCad (Week 6) and fabricating it (Week 8) to house the ESP32 and power management.

  • WEEK 7 (MAR 04)

    Computer-Controlled Machining

    Designing and cutting the full-scale frame structure using the monofab. Testing stability on the field.

  • WEEK 9 (MAR 18)

    Input Devices

    Calibrating the sensors to determinate speed and position of the ball when it crosses the goal line.

  • WEEK 11 (APR 01)

    Networking & Communications

    Programming the ESP32 to communicate wirelessly (Wi-Fi/Bluetooth) and send score data to a device.

  • WEEK 14 (APR 29)

    Interface Programming

    Developing the visual App or Web Dashboard where the player sees their speed and accuracy stats.

  • WEEKS 15-17 (MAY)

    System Integration & Development

    Final assembly, 3D printing enclosure, cable management, field testing, and recording the presentation video.