
April 21, 2026
This article was originally published on Dev.to
Edge AI is often seen as a field reserved for powerful single-board computers, but what if you could run machine learning logic directly on a standard Arduino? In this article, we will explore NocML , an efficient machine learning library specificall...
Edge AI is often seen as a field reserved for powerful single-board computers, but what if you could run machine learning logic directly on a standard Arduino?
In this article, we will explore NocML, an efficient machine learning library specifically designed for resource-constrained microcontrollers.
NocML is a lightweight C++ library built to bridge the gap between complex ML logic and the limited processing power of microcontrollers like the ESP32, Arduino Uno, or Nano. Inspired by the Scikit-Learn API, it offers a familiar workflow for developers coming from a Python background.
MinMaxScaler for data normalization on-device.One of the strongest features of NocML is its ability to perform sensor classification directly on the "edge." Imagine building a device that classifies activity types based on accelerometer data.
Here is a practical example of how to implement a KNN algorithm using NocML:
#include <NocML.h>
// Define training data (Features)
float X_train = {
{1.0, 2.0}, // Category A
{1.5, 1.8}, // Category A
{5.0, 8.0}, // Category B
{6.0, 7.0} // Category B
};
// Labels for training data
int y_train = {0, 0, 1, 1};
// Initialize KNN with k=3
KNN knn(3);
void setup() {
Serial.begin(115200);
// Local training (Fit)
knn.fit((float*)X_train, y_train, 4, 2);
Serial.println("KNN Model Ready!");
}
void loop() {
// New sensor data to classify
float input = {1.2, 2.1};
// Perform prediction
int prediction = knn.predict(input);
Serial.print("Classification Result: ");
Serial.println(prediction == 0 ? "Category A" : "Category B");
delay(2000);
}
You can easily integrate NocML into your project via the Arduino Library Manager or by visiting the official repositories.
Alternatively, explore the source code and documentation:
NocML is part of the TinyML movement, making artificial intelligence accessible on devices costing only a few dollars. By bringing logic closer to the data source, we create faster, more reliable, and smarter IoT systems.
Are you working on an Edge AI project? Give NocML a try and share your results!
#Arduino #MachineLearning #TinyML #IoT #OpenSource #NocLab #ArtificialIntelligence