Machine Learning is a very useful tool to analyze sensor data. It lets us automatically extract high-level information from data streams which may be complex, noisy and only weakly related to what we are interested in. With a bit of care around the computational requirements of the system, we can run the ML model directly on the sensor node. This lets us build affordable, power-efficient, privacy-compatible solutions which can operate stand-alone or be connected to other systems (IoT or otherwise).
I recently made an automatic toothbrush timer, using an accelerometer and a microcontroller. It is intended to be a fun and practical example for the emlearn-micropython machine learning library.
Below is a quick demo of the gadget in operation:
The project is available at: https://github.com/jonnor/toothbrush/ You will find there the software, firmware, data, ML training pipeline and 3d-printed parts.
There is now an example project in emlearn-micropython for doing (human) activity recognition using accelerometer/IMU. It can be found here: https://github.com/emlearn/emlearn-micropython/tree/master/examples/har_trees Example applications of human activity detection could be sleep tracking, overall everyday activities' classification (sitting, walking, running, etc), exercise tracking (can be specific exercises like jacks/lunges/pushups/etc). Since machine learning is dependent on datasets, what exactly we will be able to do is of course a bit dependent on what datasets we are able to find and/or gather.
The feature extraction code is in MicroPython, but it could easily be ported to C. The classifier used is Random Forest, and that is implemented in C using the emlearn C library.
emlearn-micropython is a Machine Learning and Digital Signal Processing library for MicroPython. It enables MicroPython applications to run efficient Machine Learning models on microcontroller, without having to touch any C code. It builds on the emlearn C library and exposes a set of small, independent MicroPython modules. The modules (as .mpy files) can be installed at runtime, using the MicroPython package manager "mip". This aims to enable a user experience that is just as convenient and powerful as we already have on standard (C)Python, for microcontrollers.
emlearn is an open-source library for implementing. It allows to convert models trained with Python (using scikit-learn or Keras) into portable C99 code. Here are two presentations that introduce the project. The first is very short and concise, where-as the other is a bit longer and detailed.