TinyML, or Tiny Machine Learning, is revolutionizing the world of microcontrollers. It allows you to run powerful machine-learning models on devices with limited resources, opening doors for intelligent applications at the edge of the network. This article will guide you through the exciting world of TinyML with Arduino, showcasing project examples, code snippets, and even a basic circuit diagram! So let’s start Machine Learning on Your Microcontroller.

Getting Started with TinyML on Arduino:

Machine Learning on Your Microcontroller

Here’s a roadmap to kickstart your TinyML journey:

  1. Data Collection: Gather sensor data from your Arduino (temperature, light, etc.) This data will be the foundation for training your machine-learning model.
  2. Model Training: Use a machine learning framework like TensorFlow to train a model on your collected data. TensorFlow Lite for Microcontrollers offers tools to convert this model into a format compatible with Arduino’s limitations.
  3. Deployment: Upload the converted model and code to your Arduino board. The code will process sensor data in real time using the model and generate outputs based on predictions.

Learning Resources:

Before diving into projects, equip yourself with some knowledge. Here are some valuable resources:

Machine Learning on Your Microcontroller


Project 1: Motion Detection with LED Notification (Circuit Diagram Included!)

Let’s build a project that detects motion using the Arduino Nano 33 BLE Sense and alerts you with an LED.


Circuit Diagram:

         |       | (Breadboard)
         |       |
         |       |
         |       v
         |  LED (Long leg to pin 13)  |
         |       ^
         |       |
         |       |
           | (100 ohm resistor)


This code snippet demonstrates a basic motion detection application with an LED notification.


#include <Arduino_TensorFlowLite.h>

// Define model parameters (replace with your model details)
const tflite::Model* model;
const tflite::MicroInterpreter* interpreter;
TfLiteTensor* inputTensor;
TfLiteTensor* outputTensor;

// Define pins
const int ledPin = 13;

void setup() {

  // Load your TensorFlow Lite model here
  // ... (model loading code)

  // Allocate memory for tensors

  // Obtain pointers to input and output tensors
  inputTensor = interpreter->input(0);
  outputTensor = interpreter->output(0);

  pinMode(ledPin, OUTPUT);

void loop() {
  // Read accelerometer data
  float x, y, z;
  // ... (accelerometer reading code)

  // Prepare input data for the model
  float input[1] = {x};

  // Run inference using the model

  // Get the model's prediction (probability of motion)
  float output = outputTensor->data()[0];

  // Set LED based on prediction
  if (output > 0.5) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);



  1. The code includes the Arduino_TensorFlowLite.h library.
  2. Replace the model loading section with code to load your pre-trained motion detection model converted for TensorFlow Lite microcontrollers.
  3. The setup function initializes serial communication, allocates memory for tensors based on your model, sets the LED pin as output, and includes a resistor in the circuit diagram for safety.
  4. The loop function continuously reads accelerometer data, prepares it for the model, performs inference, and lights the LED based on the model’s prediction of motion exceeding a threshold.

Project 2: Voice Activated Light Switch (More Advanced)

This is a more advanced project that requires additional components like a microphone and a pre-trained voice recognition model. You can find it in GitHub but first, you need to start with a simple one.


  1. github.com/sofianinho/training

Read more:

For Professional Designs or Help:



Mithun K. Das; B. Sc. in EEE from KUET; Head of R&D @ M's Lab Engineering Solution. "This is my personal blog. I post articles on different subjects related to electronics in the easiest way so that everything becomes easy for all, especially for beginners. If you have any questions, feel free to ask through the contact us page." Thanks.


Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *