Motion Gesture Sensor Classifier
Classify stationary, circle and shake gestures from fixed sensor windows.
Arduino Nano 33 BLE Sense / nRF528403-axis accelerometerEdge Impulse export or TensorFlow Lite Micro
Learning objectives
- Understand accelerometer sampling and coordinate axes
- Collect balanced labelled time-series data
- Explain train/validation/test separation
- Deploy and profile an int8 classifier
Prerequisites
- Arduino C/C++ basics
- Sampling frequency and serial logging
- Basic classification metrics
Dataset and labelling plan
- Define three gestures plus an explicit unknown class
- Collect from multiple users and orientations
- Use equal capture duration per class
- Keep test sessions separate from training captures
- Document sample rate, window length and overlap
Training and validation pipeline
- Inspect raw signals for clipping and missing samples
- Extract spectral or statistical features consistently
- Train a small classifier and review confusion matrix
- Quantise to int8 and compare accuracy
- Export a C++ library or .tflite model
- Test unseen gestures and low-confidence rejection
Model deployment procedure
- Freeze preprocessing and class order
- Add model bytes and resolver to firmware
- Allocate tensor arena from measured requirement plus margin
- Match device sampling/window logic to training exactly
- Run inference outside time-critical interrupt handlers
- Log class, confidence, latency and rejection result
Memory and performance targets
| Metric | Target | Unit | Why it matters |
|---|---|---|---|
| Validation accuracy | >= 85 | % | Demonstrates useful separation on unseen sessions |
| Flash usage | <= 700 | KB | Must fit application and update margin |
| Peak RAM / arena | <= 180 | KB | Prevents allocation failure and stack collision |
| Inference latency | <= 40 | ms | Must finish within the sampling schedule |
Deployment checkpoints
| Check | Expected result | Evidence |
|---|---|---|
| Dataset split | No samples from one capture appear in both train and test | Dataset manifest |
| Quantisation | Int8 accuracy loss remains within 3 percentage points | Evaluation report |
| On-device output | Known gestures classify and unknown motion rejects | Serial evidence |
| Timing | Worst-case loop remains responsive during inference | Timestamp trace |
Inference code
// Pseudocode: identical preprocessing is mandatory
read_window(accel_buffer);
features = preprocess(accel_buffer);
if (invoke_model(features) != OK) enter_safe_fallback();
result = top_class_with_confidence();
if (result.confidence < 0.70) report_unknown();
else report_class(result);Troubleshooting
| Symptom | Likely cause | Corrective action |
|---|---|---|
| All gestures become one class | Window/sample rate differs from training | Match acquisition and feature pipeline |
| Model invokes but output is random | Tensor type, scale or zero-point mismatch | Use exported quantisation parameters |
| Intermittent crash | Tensor arena or stack overlap | Measure peak RAM and increase safe margin |
| High desktop accuracy, poor device result | Dataset leakage or narrow data | Rebuild session-separated test set |
Safety, privacy and model limits
- Do not collect identifiable motion data without consent.
- Remove names and unnecessary metadata from exported datasets.
- Gesture output must not directly control hazardous machinery.
- Model confidence is not calibrated safety probability.
Measured deployment profile
Log in to record deployment measurementsInterview and viva questions
- Why must one recording session not be split across train and test?
- What changes during int8 quantisation?
- Why is an unknown/reject policy necessary?
- How do window length and overlap affect latency?
- Which memory regions hold model, tensor arena and stack?
Lesson notes
Responsible TinyML workflow
Keep raw data, preprocessing, model version, compiler options and measured device results together. A desktop accuracy score does not prove embedded performance. Validate representative unseen samples on the actual target and define an explicit fallback for low confidence or out-of-distribution input.
Deployment evidence
Record the dataset split, confusion matrix, exported model hash, firmware build, board revision, peak memory, average and worst-case latency, power conditions and failures. Never treat an educational classifier as a safety-certified decision system.
