Complete Technical Paper Content — Ai On Arduino
1. Executive Abstract, Problem Formulation & Background
🚀 Arduino Sine Model Inference with DLAI This project demonstrates how to deploy and run a simple neural network model—specifically a sine regression model—on an Arduino UNO using the DLAI (Deep Learning Algorithm Implementation) library. It showcases the process of integrating a model trained in TensorFlow into a low-resource microcontroller environment. 📌 Project Description This is a simple, educational TinyML project that performs sine wave prediction on an Arduino UNO. The model used is created in TensorFlow , consisting of: Input layer with 1 neuron Two hidden layers , each with 16 neurons Random activation functions (e.g., ReLU, Tanh, etc.) All operations are in floating point (no quantization) The model is exported and converted using the DLAI Python tool and then deployed to the Arduino. 📦 What is DLAI? DLAI (Deep Learning Algorithm Implementation) is a lightweight C/C++ library for deploying deep learning models on embedded systems and microcontrollers. 🔗 DLAI GitHub Repository : https://github.com/Mat-thias/dlai ✅ What This Project Demonstrates Running a neural network inference on Arduino UNO Converting a model from PyTorch/TensorFlow into C header format Using floating point operations for inference Driving an LED output using sine predictions (brightness mapped from sine value) 🛠️ Setup Instructions 1. Create an Arduino Sketch Create a new sketch for your Arduino UNO project. 2. Download and Add the DLAI Library Download dlai.zip from: https://github.com/Mat-thias/dlai Open Arduino IDE Go to Sketch > Include Library > Add .ZIP Library... Select the downloaded file to install. 3. Include Required Headers in Your Sketch # include " sine_model.h " # include " dlai.h " # include " Layers/src/layers.h " # include " Models/src/models.h " 4. Identify Layer Count and Workspace Size From sine_model.h , find: # define LAYER_SIZE 5 # define MAX_WORKSPACE_SIZE 32 Use these constants in your sketch. 5. Declare Layer Graph and Workspace Layer *graph[ LAYER_SIZE ]; float workspace[ MAX_WORKSPACE_SIZE ]; 6. Initialize the Model Sequential model ( sine_model, // Model weights and parameters sine_model_len, // Length of model array graph, // Layer array LAYER_SIZE , // Number of layers workspace, // Scratch buffer MAX_WORKSPACE_SIZE // Buffer size ); 7. Arduino setup() Function void setup () { Serial. begin ( 9600 ); pinMode ( ANALOG_LED_PIN , OUTPUT ); } 8. Arduino loop() Function void loop () { float *input = model. input ; float *output = model. output ; long start_time; for ( int x = 0 ; x < 360 ; x++) { *input = ( float )x * 2 * PI / 360 ; // Convert degrees to radians start_time = millis (); model. predict (); // Run inference int y = sine_value_to_brightness (*output); // Convert [-1,1] to [0,255] analogWrite ( ANALOG_LED_PIN , y); // Drive LED brightness Serial. print ( " sine( " ); Serial. print (x); Serial. print ( " °) = " ); Serial. print (y); Serial. print ( " -- [ " ); Serial. print ( millis () - start_time); Serial. println ( " ms] " ); } } 9. Brightness Mapping Helper Function int sine_value_to_brightness ( float val) { val = constrain (val, - 1.0 , 1.0 ); // Ensure range return ( int )((val + 1.0 ) * 127.5 ); // Scale to [0, 255] } 📁 Folder Structure Example your-sketch/ ├── your-sketch.ino ├── sine_model.h ← Converted model header ├── dlai/ ← DLAI library folder │ ├── dlai.h │ ├── Layers/ │ └── Models/ 🧠 Summary With this setup, you're running a floating-point neural network inference on one of the smallest Arduino boards available. This is a solid entry point into TinyML development and embedded AI, showcasing how neural models can control real-world hardware like LEDs based on predictions.
This project demonstrates how to deploy and run a simple neural network model—specifically a sine regression model—on an Arduino UNO using the DLAI (Deep Learning Algorithm Implementation) library. It showcases the process of integrating a model trained in TensorFlow into a low-resource microcontroller environment.
This is a simple, educational TinyML project that performs sine wave prediction on an Arduino UNO. The model used is created in TensorFlow , consisting of:
The model is exported and converted using the DLAI Python tool and then deployed to the Arduino.
2. Related Work, Literature Survey & Algorithmic Foundations
DLAI (Deep Learning Algorithm Implementation) is a lightweight C/C++ library for deploying deep learning models on embedded systems and microcontrollers.
# include " sine_model.h " # include " dlai.h " # include " Layers/src/layers.h " # include " Models/src/models.h "
Sequential model ( sine_model, // Model weights and parameters sine_model_len, // Length of model array graph, // Layer array LAYER_SIZE , // Number of layers workspace, // Scratch buffer MAX_WORKSPACE_SIZE // Buffer size );
void loop () { float *input = model. input ; float *output = model. output ; long start_time; for ( int x = 0 ; x < 360 ; x++) { *input = ( float )x * 2 * PI / 360 ; // Convert degrees to radians start_time = millis (); model. predict (); // Run inference int y = sine_value_to_brightness (*output); // Convert [-1,1] to [0,255] analogWrite ( ANALOG_LED_PIN , y); // Drive LED brightness Serial. print ( " sine( " ); Serial. print (x); Serial. print ( " °) = " ); Serial. print (y); Serial. print ( " -- [ " ); Serial. print ( millis () - start_time); Serial. println ( " ms] " ); } }
3. Dataset Ingestion, Preprocessing & Stochastic Augmentations
int sine_value_to_brightness ( float val) { val = constrain (val, - 1.0 , 1.0 ); // Ensure range return ( int )((val + 1.0 ) * 127.5 ); // Scale to [0, 255] }
your-sketch/ ├── your-sketch.ino ├── sine_model.h ← Converted model header ├── dlai/ ← DLAI library folder │ ├── dlai.h │ ├── Layers/ │ └── Models/
With this setup, you're running a floating-point neural network inference on one of the smallest Arduino boards available. This is a solid entry point into TinyML development and embedded AI, showcasing how neural models can control real-world hardware like LEDs based on predictions.
This project demonstrates how to deploy and run a simple neural network model—specifically a sine regression model—on an Arduino UNO using the DLAI (Deep Learning Algorithm Implementation) library. It showcases the process of integrating a model trained in TensorFlow into a low-resource microcontroller environment.
4. Neural Network Backbone, Layer Specifications & Loss Formulations
This project explores the deployment of multiple deep learning models on a single Arduino microcontroller. As stress continues to be a major health concern, there is growing interest in developing effective stress management systems that can detect and mitigate stress. Deep neural networks (DNNs) have shown their effectiveness in accurately classifying stress, but most of the existing solutions rely on the cloud or large, obtrusive devices for inference. The emergence of tiny machine learning provides an opportunity to bridge this gap and enable ubiquitous intelligent systems. In this article, we propose a context-aware stress detection approach that uses a microcontroller to continuously infer physical activity to mitigate motion artifacts when inferring stress from heart rate and electrodermal activity. We deploy two DNNs onto a single resource-constrained microcontroller for real-world stress recognition, with the resultant stress and activity recognition models achieving 88% and 98% accuracy, respectively. Our proposed context-aware approach improves the accuracy and privacy of stress detection systems while eliminating the need to store or transmit sensitive health data. Please cite the respository as: M. Gibbs, K. Woodward and E. Kanjo, "Combining Multiple Tiny Machine Learning Models for Multimodal Context-Aware Stress Recognition on Constrained Microcontrollers" in IEEE Micro, vol. 44, no. 03, pp. 67-75, May-June 2024, doi: 10.1109/MM.2023.3329218.
This project explores the deployment of multiple deep learning models on a single Arduino microcontroller.
As stress continues to be a major health concern, there is growing interest in developing effective stress management systems that can detect and mitigate stress. Deep neural networks (DNNs) have shown their effectiveness in accurately classifying stress, but most of the existing solutions rely on the cloud or large, obtrusive devices for inference. The emergence of tiny machine learning provides an opportunity to bridge this gap and enable ubiquitous intelligent systems. In this article, we propose a context-aware stress detection approach that uses a microcontroller to continuously infer physical activity to mitigate motion artifacts when inferring stress from heart rate and electrodermal activity. We deploy two DNNs onto a single resource-constrained microcontroller for real-world stress recognition, with the resultant stress and activity recognition models achieving 88% and 98% accuracy, respectively. Our proposed context-aware approach improves the accuracy and privacy of stress detection systems while eliminating the need to store or transmit sensitive health data.
Please cite the respository as: M. Gibbs, K. Woodward and E. Kanjo, "Combining Multiple Tiny Machine Learning Models for Multimodal Context-Aware Stress Recognition on Constrained Microcontrollers" in IEEE Micro, vol. 44, no. 03, pp. 67-75, May-June 2024, doi: 10.1109/MM.2023.3329218.
5. Training Protocol, Convergence Behavior & Experimental Evaluation
Arduino AI Explorer An autonomous AI system that explores the physical world through Arduino sensors, continuously updating firmware and learning from environmental data. Quick Start Install Dependencies pip install -r requirements.txt Install Arduino CLI # Download from: https://arduino.github.io/arduino-cli/ arduino-cli core install arduino:avr Connect Arduino Connect Arduino Uno via USB Start with a temperature sensor on pin A0 Run Explorer python main.py Open user's UI and see what to connect next to read the data: How It Works Connects to Arduino via USB auto-detection Reads sensor data continuously Analyzes data using local AI model Generates new firmware based on insights Updates Arduino firmware automatically Saves all versions for rollback Suggests hardware changes to user Repeats cycle for autonomous exploration File Structure main.py - Main exploration loop arduino_interface.py - USB communication & firmware upload firmware_manager.py - Version control & sketch generation ai_core.py - AI analysis & decision making firmware_versions/ - All firmware versions saved here exploration_log.json - Session data and insights Supported Sensors Temperature (analog pin A0) Light (analog pin A1) Motion (digital pin 2) More sensors added dynamically by AI Configuration GPT4ALL Setup: Ensure GPT4ALL server is running on http://localhost:4891 Model will be trained with each exploration cycle Training data saved to ArduinoAI_training/ folder Variables to edit: current_sensors in main.py - Starting sensor list base_url in ai_core.py - GPT4ALL server endpoint Arduino board type in arduino_interface.py Testing After running multiple iterration AI asking user to change physical Arduino connections to evolve Requests working with local AI model running in GPT4ALL Generating new firmware based on the data from the real world sensors:
An autonomous AI system that explores the physical world through Arduino sensors, continuously updating firmware and learning from environmental data.
# Download from: https://arduino.github.io/arduino-cli/ arduino-cli core install arduino:avr
After running multiple iterration AI asking user to change physical Arduino connections to evolve
Model Figures & Evaluation Curves (4 Images)
Deep Learning Execution Pipeline
(Preprocessing)
(Feature Extraction)
(Self-Attention)
(Loss Optimization)