Artificial Intelligence (AI) October 18, 2026 0

TinyML: Machine Learning on Microcontrollers

By Admin 5 min read

Most people picture machine learning running on powerful servers, but some of the most interesting applications run on chips that cost a few dollars, have kilobytes of memory and run for months on a small battery. This field is called TinyML. It brings AI to sensors, wearables and everyday objects without needing the internet.

What is TinyML?

TinyML means deploying machine-learning models on microcontrollers (MCUs): small, low-power processors found in Arduino boards, ESP32 modules, smartwatches, appliances and industrial sensors. Typical constraints:

  • Memory: tens to hundreds of kilobytes of RAM, up to a few megabytes of flash storage
  • Clock speed: tens to a couple of hundred MHz
  • Power: milliwatts or less, often battery or solar powered
  • No operating system in many cases

Models must therefore be tiny, often under 100 KB, and run in a fraction of a second.

Why use it?

  • Always-on sensing at very low power, such as listening for a wake word
  • Privacy: raw audio or sensor data never leaves the device
  • Low latency: immediate response
  • No connectivity needed: useful in remote areas
  • Low cost at scale, since chips are cheap
  • Less data transmission: the device sends only a result such as "cough detected" rather than a stream

Typical applications

  • Keyword spotting ("Hey device") and simple voice commands
  • Gesture recognition using accelerometers in wearables
  • Predictive maintenance: vibration analysis of motors and pumps
  • Anomaly detection in industrial sensors
  • Agriculture: sensors detecting pests, soil conditions or livestock behaviour
  • Health: fall detection and activity recognition
  • Simple image tasks such as person detection with tiny cameras
  • Smart home devices that react to sounds like glass breaking

The workflow

  1. Define the task and constraints. What is the input (sound, motion), what outputs do you need, how much memory and power are available?
  2. Collect data from the actual sensor on the actual device, in realistic conditions. A model trained on clean lab data may fail in the field.
  3. Preprocess and extract features. For audio, convert waveforms to spectrograms or MFCCs. For motion, compute statistics over short windows.
  4. Train a small model on a computer, typically a small neural network or even classic machine learning such as decision trees.
  5. Optimise: quantise to 8-bit integers and prune.
  6. Convert to a format that runs on the MCU, for example TensorFlow Lite for Microcontrollers, which produces a C array of the model.
  7. Deploy the model together with inference code on the board.
  8. Test in the real world and iterate on data and thresholds.

A small training example

Here is a simplified Python workflow for classifying two gestures from accelerometer windows. In a real project you would record data from your board; here random data stands in to show the structure.

import numpy as np
import tensorflow as tf

# 200 windows of 3-axis data with 50 samples each (flattened to 150 values), 2 classes
X = np.random.randn(200, 150).astype("float32")
y = np.random.randint(0, 2, 200)

model = tf.keras.Sequential([
    tf.keras.layers.Input(shape=(150,)),
    tf.keras.layers.Dense(16, activation="relu"),
    tf.keras.layers.Dense(8, activation="relu"),
    tf.keras.layers.Dense(2, activation="softmax"),
])
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
model.fit(X, y, epochs=5, batch_size=16, verbose=0)

def representative_data():
    for i in range(100):
        yield [X[i:i + 1]]

converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_data
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.int8
converter.inference_output_type = tf.int8
tflite_model = converter.convert()

open("gesture.tflite", "wb").write(tflite_model)
print("Model size:", len(tflite_model), "bytes")

Then convert the file to a C array (for example with the xxd -i command) and include it in your Arduino or embedded project along with the TensorFlow Lite Micro library.

Tools and platforms

  • TensorFlow Lite for Microcontrollers: the most widely used runtime.
  • Edge Impulse: a web platform for collecting data, training and deploying models to many boards with little code.
  • Arduino Nano 33 BLE Sense and similar boards: include microphones and motion sensors, popular for learning.
  • ESP32, Raspberry Pi Pico and STM32 boards.
  • CMSIS-NN and vendor libraries for optimised neural-network operations on ARM chips.
  • MicroPython and C++ for programming.

Challenges

  • Tight memory: you must account for the model, the input buffers and the runtime.
  • Limited operations: not every neural-network layer is supported.
  • Noisy sensors and varied conditions: gathering diverse data is crucial.
  • Power management: sleeping between measurements and waking only when needed.
  • Updating models in the field requires a plan for over-the-air updates.
  • Accuracy versus size: you need to decide acceptable trade-offs.

Tips for beginners

  1. Start with an existing example for your board (keyword spotting or gesture recognition).
  2. Collect your own data to see how much accuracy depends on it.
  3. Try simple models first. A decision tree on hand-made features can beat a neural network and use far less memory.
  4. Measure inference time and memory use on the device early.
  5. Use a threshold and confirmation logic (for example, trigger only after three positive windows) to reduce false alarms.
  6. Think about privacy and consent when sensing sound or movement of people.

Frequently Asked Questions

Do I need to know deep learning to start?

Basic Python and a willingness to experiment are enough with platforms like Edge Impulse, though understanding the concepts helps debugging.

How is TinyML different from edge AI?

TinyML is a subset focused on extremely constrained devices like microcontrollers. Edge AI also includes phones and more powerful edge computers.

Can a microcontroller run a language model?

Not a modern large one. Tiny devices handle small tasks such as classification and anomaly detection.

What hardware should I buy to learn?

A board with built-in sensors, such as the Arduino Nano 33 BLE Sense, or an ESP32 development board, is a cost-effective start.

Conclusion

TinyML puts machine learning on chips that run for months on a battery. With careful data collection, small models and quantisation, you can build sensors and devices that understand sound or motion locally and privately.