Skip to content

About

Real-time tennis stroke classification with TensorFlow Lite on Arduino Nano 33 BLE Rev2 and a Web Serial companion dashboard

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Tennis Shot Analyzer

Real-time tennis stroke classification system using an Arduino Nano 33 BLE Rev2 with on-device TensorFlow Lite inference and a companion web dashboard connected via Web Serial API.

The device captures accelerometer and gyroscope data from the board's built-in IMU (BMI270), classifies the stroke type using a neural network running entirely on the microcontroller, and streams results to a browser-based dashboard that displays live statistics, shot distribution charts, and a session history.

Shot Types

The model classifies four tennis strokes:

  • Smash -- overhead power shot
  • Volea (Volley) -- net shot without bounce
  • Reves (Backhand) -- backhand stroke
  • Globo (Lob) -- high defensive arc shot

System Architecture

IMU Sensor (BMI270)
      |
      v
Arduino Nano 33 BLE Rev2
  - Reads 6-axis data (accel + gyro) at 119 samples/gesture
  - Normalizes sensor values to [0, 1]
  - Runs TFLite Micro inference (~16KB tensor arena)
  - Outputs classified shot via Serial (9600 baud)
      |
      v
Web Serial API (Chrome)
      |
      v
Web Dashboard (HTML/JS/Chart.js)
  - Real-time shot detection with confidence score
  - Per-stroke counters and percentage breakdown
  - Bar chart with shot distribution
  - Chronological shot history with timestamps
  - Session timer and PDF report export

Hardware Requirements

  • Arduino Nano 33 BLE Rev2 (nRF52840 + BMI270 IMU)
  • USB cable for Serial connection and power
  • Chrome browser (Web Serial API support required)

Software Dependencies

Arduino libraries (install via Arduino IDE Library Manager):

  • Arduino_BMI270_BMM150 -- IMU driver for Rev2 boards
  • TensorFlowLite -- TFLite Micro runtime for Arduino

No additional dependencies are needed for the web app -- it runs as a standalone HTML file.

Project Structure

tennis-shot-analyzer/
  IMU_Classifier_Serial.ino   -- Arduino sketch: IMU capture + TFLite inference
  model.h                     -- Trained model weights as C array (TFLite flatbuffer)
  tenis-analyzer_app.html     -- Companion web dashboard (Web Serial + Chart.js)

How It Works

  1. The Arduino continuously polls the accelerometer. When the combined acceleration exceeds 8G (indicating a stroke motion), it begins capturing 119 consecutive 6-axis samples (3 accel + 3 gyro axes).

  2. Each sample is normalized: accelerometer values are mapped from [-4, +4]G to [0, 1], and gyroscope values from [-2000, +2000] deg/s to [0, 1].

  3. The normalized window (119 x 6 = 714 features) is fed into a TensorFlow Lite model running on-device. The model outputs a probability distribution over the four stroke classes.

  4. If the highest confidence exceeds 85%, the result is sent over Serial in the format TENNIS:<shot_type>:<confidence>.

  5. The web app parses incoming Serial data, updates the counters and chart in real time, and logs each detected shot with a timestamp.

Usage

  1. Open IMU_Classifier_Serial.ino in the Arduino IDE. Make sure model.h is in the same directory.

  2. Install the required libraries (Arduino_BMI270_BMM150 and TensorFlowLite) via the Library Manager.

  3. Upload the sketch to the Arduino Nano 33 BLE Rev2.

  4. Close the Arduino IDE Serial Monitor (only one application can read the Serial port at a time).

  5. Open tenis-analyzer_app.html in Chrome.

  6. Click "Connect Arduino" and select the board's COM port in the browser popup.

  7. Start playing -- the dashboard updates in real time as strokes are detected.

To test the interface without hardware, press the D key on your keyboard to simulate random shots.

Communication Protocol

The Arduino sends lines over Serial at 9600 baud:

Message Description
TENNIS:ready Board initialized and waiting for motion
TENNIS:<type>:<conf> Detected shot (e.g., TENNIS:smash:0.952)

The web app filters lines starting with TENNIS: and discards all other Serial output (debug logs, sensor readings, etc.).

Model Training

The TFLite model was trained separately using IMU gesture data captured with the Arduino. Training data was collected by recording labeled repetitions of each stroke type. The trained model was quantized and exported as a C header file (model.h) for embedding into the Arduino sketch. The tensor arena requires approximately 16KB of RAM.

Technical Notes

  • The project initially used BLE (Bluetooth Low Energy) for wireless communication, but RAM conflicts between the BLE SoftDevice and TFLite on the nRF52840 caused reliability issues. Web Serial proved to be a simpler and more stable alternative.
  • The while (!Serial) in setup() means the board waits for a Serial connection before starting. This is intentional for the tethered use case.
  • The LED blinks during gesture capture to provide visual feedback.
  • For Rev1 boards (LSM9DS1 IMU), uncomment the corresponding include and comment out the BMI270 line.

Built With

  • Arduino (C++) -- embedded firmware
  • TensorFlow Lite Micro -- on-device ML inference
  • Web Serial API -- browser-to-microcontroller communication
  • Chart.js -- real-time data visualization
  • jsPDF -- session report export

About

Real-time tennis stroke classification with TensorFlow Lite on Arduino Nano 33 BLE Rev2 and a Web Serial companion dashboard

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages