Hardware Guide
The ESP32 runs autoencoder-based anomaly detection with TFLite Micro by learning normal sensor patterns and flagging deviations. Models under 20 KB fit easily in the 520 KB SRAM, leaving headroom for Wi-Fi reporting and multi-sensor monitoring.
| Spec | ESP32 |
|---|---|
| Processor | Dual-core Xtensa LX6 @ 240 MHz |
| SRAM | 520 KB |
| Flash | Up to 16 MB (external) |
| Key Features | Hardware crypto acceleration, Ultra-low-power co-processor (ULP) |
| Connectivity | Wi-Fi 802.11 b/g/n, Bluetooth 4.2 BR/EDR + BLE |
| Price Range | $2 - $5 (chip), $5 - $15 (dev board) |
Anomaly detection is one of the most resource-efficient ML workloads — typical autoencoder models are 10-20 KB with minimal inference latency. The ESP32's 520 KB SRAM provides over 16x the 32 KB minimum requirement. This headroom matters because anomaly detection often runs alongside other application logic: sensor polling, data buffering, Wi-Fi communication, and threshold management. TFLite Micro's static memory allocation model works well here — allocate a fixed tensor arena and the rest is available for the application. The Xtensa LX6 architecture is fully supported by TFLite Micro with ESP-NN optimized kernels for the Xtensa architecture. The ULP co-processor can handle sensor polling during deep sleep, waking the main processor only when readings exceed configurable thresholds. Wi-Fi enables real-time anomaly reporting to MQTT brokers or HTTP endpoints.
Set up sensor data collection
Connect vibration (ADXL345), temperature (DS18B20), or current sensors (ACS712) to the ESP32 via I2C or ADC. Log baseline data during normal operation — you need 1000+ samples of 'normal' behavior to train an effective autoencoder.
Train an autoencoder in TensorFlow
Build a small autoencoder (3-4 layers, 10-20 neurons per layer) in TensorFlow/Keras. Train only on normal data — the model learns to reconstruct normal patterns. High reconstruction error indicates an anomaly.
Quantize and convert the model
Apply int8 post-training quantization with TFLite converter. The quantized autoencoder should be under 20 KB. Convert to a C array with xxd -i for embedding in firmware.
Implement anomaly scoring on ESP32
Run inference on each sensor reading window. Calculate reconstruction error (MSE between input and output). Set an anomaly threshold based on the error distribution from validation data. Report anomalies via MQTT when the error exceeds the threshold for N consecutive windows.
Half the cost ($1-3 chip) with 400 KB SRAM — more than enough for anomaly detection. Single-core RISC-V is sufficient. Best choice for high-volume, cost-sensitive deployments.
Ultra-low-power (< 100 nA shutdown) for battery-operated monitoring. 128 KB SRAM is sufficient for anomaly models. No Wi-Fi — use BLE or wired connection for data reporting.
Connect sensors to AI inference on the ESP32 — design monitoring workflows visually and compile to firmware.
Get Started Free