ESP32 Vibration Anomaly Detector
Learn normal vibration and flag deviations while separating sensor, mounting and operating-condition faults.
Learning objectives
- Design normal-operation data coverage
- Explain anomaly score and threshold trade-offs
- Deploy fixed preprocessing on ESP32
- Profile memory, latency and false alarms
Prerequisites
- ESP32 sampling and timers
- Basic vibration and FFT concepts
- Safe motor measurement practice
Dataset and labelling plan
- Capture normal data across speed, load and warm-up states
- Create held-out normal sessions from a different time
- Collect supervised fault examples only when safe
- Record sensor orientation, mounting and sample rate
- Exclude startup transients or label them as a separate state
Training and validation pipeline
- Check time waveform, saturation and spectral stability
- Create frequency-domain or learned features
- Train normal-vs-anomalous scoring model
- Set threshold using held-out normal and safe fault data
- Quantise and test score distribution again
- Document false-positive and missed-fault cases
Model deployment procedure
- Use deterministic sampling with overrun detection
- Verify sensor range and anti-alias assumptions
- Deploy model and threshold as separately versioned values
- Measure inference under Wi-Fi and peak task load
- Latch repeated anomalies but allow safe reset policy
- Export score, operating state and diagnostic context
Memory and performance targets
| Metric | Target | Unit | Why it matters |
|---|---|---|---|
| Validation accuracy | >= 88 | % | Balanced labelled evaluation target |
| Flash usage | <= 1100 | KB | Leaves application and OTA margin |
| Peak RAM / arena | <= 260 | KB | Fits ESP32-S3 workload safely |
| Inference latency | <= 60 | ms | Supports repeated monitoring windows |
Deployment checkpoints
| Check | Expected result | Evidence |
|---|---|---|
| Normal baseline | Held-out normal false alarms remain below approved limit | Score distribution |
| Known deviation | Safe simulated fault crosses threshold repeatedly | Serial log |
| Sampling integrity | No dropped samples during worst-case workload | Overrun counter |
| Memory | Heap and stack margin remain positive after repeated inference | Runtime profile |
| Fallback | Sensor failure produces diagnostic state, not a normal prediction | Fault-injection evidence |
Inference code
collect_window(samples);
if (!sensor_ok || sample_overrun) { state = SENSOR_FAULT; return; }
features = vibration_features(samples);
score = invoke_anomaly_model(features);
state = score > threshold ? SUSPECT : NORMAL;
if (repeated_suspect()) request_inspection();Troubleshooting
| Symptom | Likely cause | Corrective action |
|---|---|---|
| False alarms after remounting | Mounting changes the vibration transfer path | Rebuild/validate baseline for approved mounting |
| Anomalies only during Wi-Fi | Sampling jitter or power noise | Measure timing and rail integrity |
| Every score is constant | Feature scaling or model input mismatch | Compare device features with training export |
| Reset during inference | Peak current or memory exhaustion | Capture rail and heap/stack margins |
Safety, privacy and model limits
- Use guards, current limiting and safe simulated faults; never create a dangerous mechanical failure.
- An anomaly is a request for inspection, not proof of a specific defect.
- Store only required operational data and define retention.
- A changed machine, mounting or speed range may invalidate the baseline.
Measured deployment profile
Log in to record deployment measurementsInterview and viva questions
- Why is normal-only training insufficient without held-out abnormal evaluation?
- How is a threshold selected?
- Why must mounting be controlled?
- What is the difference between sensor fault and machine anomaly?
- How would you monitor model drift?
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.
