This a simple project to showcase on how one can deploy Machine learning models to AVR boards such as Arduino Pro Mini This code has been tested on Arduno Uno and Arduino Pro Mini
The dataset consists of 3 different types of plant flowers' (Setosa, Versicolour and Virginica) petal and sepal lengths, in cm.
The rows consist of the individual plant species and the columns are: Sepal Length
, Sepal Width
, Petal Length
and Petal Width
. The last column is the identity of the flower
, encoded as an integer, ie 0, 1 and 2.
The machine learning model will learn on the various characteristics of a specific flower type and after training will be able to predict the plant flower type given its characteristics.
The initial model training and conversion to Arduino-compatible code are performed in a Python notebook. The notebook (RandomForestClassifier_training.ipynb
) is available in this repository. It covers the following steps:
- Loading the Iris dataset using scikit-learn.
- Exploring and preparing the dataset.
- Splitting the dataset into training and testing sets.
- Training a RandomForestClassifier on the training set.
- Evaluating the model's accuracy on the testing set.
- Converting the trained model to Arduino-compatible code using the
emlearn
library. - Saving the converted model to a header file (
clf.h
).
The Arduino sketch (predict.ino
) uses the converted model (clf.h
) to make predictions on input features received through the serial monitor.
Copy the emlearn
folder and paste it to the location of your Arduino Library
Operating System | Arduino Library Path |
---|---|
Linux | ~/Arduino/libraries |
Windows | C:\Users<YourUsername>\Documents\Arduino\libraries |
Unix | ~/Arduino/libraries |
- Upload the Arduino sketch (
iris_prediction.ino
) to your Arduino board. - Open the serial monitor in the Arduino IDE.
- Enter the values for sepal length, sepal width, petal length, and petal width separated by commas.
- Press Enter, and the Arduino will print the predicted Iris species.
Feel free to experiment with different input values and observe the model's predictions. If you encounter any issues or have questions, please open an issue in this repository. Happy coding!