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.
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
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
- Arduino Nano 33 BLE Rev2 (nRF52840 + BMI270 IMU)
- USB cable for Serial connection and power
- Chrome browser (Web Serial API support required)
Arduino libraries (install via Arduino IDE Library Manager):
Arduino_BMI270_BMM150-- IMU driver for Rev2 boardsTensorFlowLite-- TFLite Micro runtime for Arduino
No additional dependencies are needed for the web app -- it runs as a standalone HTML file.
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)
-
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).
-
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].
-
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.
-
If the highest confidence exceeds 85%, the result is sent over Serial in the format
TENNIS:<shot_type>:<confidence>. -
The web app parses incoming Serial data, updates the counters and chart in real time, and logs each detected shot with a timestamp.
-
Open
IMU_Classifier_Serial.inoin the Arduino IDE. Make suremodel.his in the same directory. -
Install the required libraries (
Arduino_BMI270_BMM150andTensorFlowLite) via the Library Manager. -
Upload the sketch to the Arduino Nano 33 BLE Rev2.
-
Close the Arduino IDE Serial Monitor (only one application can read the Serial port at a time).
-
Open
tenis-analyzer_app.htmlin Chrome. -
Click "Connect Arduino" and select the board's COM port in the browser popup.
-
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.
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.).
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.
- 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)insetup()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.
- 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