How to Deploy ML Models to Edge Devices like Arduino: The Complete TinyML Pipeline
Deploying ML models to edge devices like Arduino requires quantizing the model to int8, packaging it via Edge Impulse as an Arduino library, and flashing the resulting firmware to run inference entirely offline on microcontrollers such as the Nicla Vision.
The harvard-edge/cs249r_book repository provides a production-ready reference for deploying machine learning models to resource-constrained microcontrollers. This guide walks through the complete TinyML pipeline from sensor data acquisition to real-time inference on the Arduino Nicla Vision platform.
The Four-Stage TinyML Deployment Pipeline
According to the source code in kits/contents/arduino/nicla_vision/kws/kws.qmd, edge deployment follows a strict four-stage architecture that bridges cloud-based training with microcontroller inference.
Data Acquisition and Preprocessing
The pipeline begins with raw sensor capture on the edge device. The Arduino Nicla Vision captures 16 kHz / 16-bit audio streams through its built-in digital microphone. Edge Impulse collects these raw samples and applies an MFCC front-end that transforms each one-second audio slice into a 13×49×1 feature map suitable for neural network input.
Model Training and Quantization
The MFCC features upload to Edge Impulse where a compact 1-D CNN trains on target classes. The architecture consists of two Conv + MaxPool blocks followed by dropout and a final dense layer, classifying inputs into YES, NO, NOISE, and UNKNOWN categories. Post-training quantization converts weights to int8, compressing the model to a few kilobytes to fit within the Nicla's ≤256 KB RAM constraint.
Exporting the Arduino Library
In Edge Impulse's Deploy tab, selecting Arduino Library → TensorFlow-Lite → Quantized (int8) initiates the build process. The service bundles the quantized model, MFCC pre-processor, and a ready-to-compile Arduino sketch into a single ZIP file. This package contains the complete inference runtime needed for microcontroller execution.
Flashing and Running Inference
Install the exported ZIP via the Arduino IDE using Sketch → Include Library → Add .ZIP Library. The generated example sketch (e.g., nicla-vision_microphone_continuous) runs entirely offline, continuously reading microphone samples, processing them through the on-board MFCC block, invoking ei_classify(), and outputting probability vectors for the four classification labels.
Arduino Nicla Vision Hardware Architecture
The Arduino Nicla Vision serves as the target platform for this deployment pipeline. The board features an STM32 H7 microcontroller with 1 MB Flash and 256 KB RAM, providing sufficient memory for quantized CNNs while remaining in the micro-controller-class power envelope. The integrated digital microphone and RGB LED eliminate external component requirements for sensor-actuator loops.
Post-Processing: From Inference to Physical Action
The deployment pipeline includes a post-processing stage that maps model predictions to physical I/O operations. After calling ei_classify(), the application extracts the predicted class index and triggers corresponding LED states on the board.
The following code from kws.qmd (lines 66-86) demonstrates the LED control logic that bridges inference output to hardware actuation:
// Initialise LEDs (active-low)
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDB, OUTPUT);
digitalWrite(LEDR, HIGH);
digitalWrite(LEDG, HIGH);
digitalWrite(LEDB, HIGH);
void turn_off_leds() {
digitalWrite(LEDR, HIGH);
digitalWrite(LEDG, HIGH);
digitalWrite(LEDB, HIGH);
}
// pred_index: 0=YES (green), 1=NO (red), 2=UNKNOWN (blue), 3=NOISE (all off)
void turn_on_leds(int pred_index) {
turn_off_leds();
switch (pred_index) {
case 0: digitalWrite(LEDG, LOW); break; // YES → Green
case 1: digitalWrite(LEDR, LOW); break; // NO → Red
case 2: digitalWrite(LEDB, LOW); break; // UNKNOWN → Blue
// case 3 falls through → all off (noise)
}
}
This implementation demonstrates how TinyML inference drives real-world outputs without requiring host CPU resources or network connectivity.
Summary
- The harvard-edge/cs249r_book repository documents a complete TinyML pipeline for deploying ML models to Arduino edge devices through four stages: data acquisition, quantized training, library export, and flashing.
- MFCC preprocessing on Edge Impulse converts raw 16 kHz audio into 13×49×1 feature maps before feeding a quantized 1-D CNN that fits within 256 KB RAM.
- The Edge Impulse deployment workflow generates Arduino-compatible ZIP libraries containing TensorFlow Lite Micro runtimes and pre-built sketches.
- The Arduino Nicla Vision executes inference offline using
ei_classify()and maps predictions to physical actions via GPIO-controlled RGB LEDs.
Frequently Asked Questions
What is the maximum model size for Arduino Nicla Vision deployment?
The Arduino Nicla Vision features 256 KB of RAM and 1 MB of Flash storage. When deploying ML models to this edge device, you must quantize the model to int8 precision, typically resulting in a footprint of just a few kilobytes. This compression enables complex CNNs to run inference entirely on the microcontroller without external memory.
Does the inference require an internet connection after deployment?
No. Once flashed, the Arduino sketch runs completely offline. The model, MFCC preprocessor, and inference logic (ei_classify()) execute locally on the STM32 H7 microcontroller. Edge Impulse is only required during the initial training and export phases, not during real-time operation.
How does the MFCC preprocessing work on the edge device?
The MFCC (Mel-Frequency Cepstral Coefficients) front-end processes raw 16 kHz / 16-bit audio samples captured by the Nicla Vision's built-in microphone. This transforms each one-second audio slice into a 13×49×1 feature map before feeding the neural network, reducing computational requirements while preserving essential spectral characteristics for keyword spotting tasks.
Where can I find the complete source files for this deployment tutorial?
The complete implementation resides in the harvard-edge/cs249r_book repository under kits/contents/arduino/nicla_vision/kws/kws.qmd. This file contains the full hands-on tutorial including data collection procedures, model training parameters, and the LED post-processing logic demonstrated in this guide.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →