Train a Gesture Model for a Microcontroller: the short answer
Gesture recognition is the best first TinyML project because the data is easy to collect and the model is small. Choose three or four classes, for example idle, wave, circle and shake, and always include an idle or unknown class, or the model will force every movement into a gesture.
- Level
- Intermediate
- Time
- About 6 min
- Topic
- IoT and AI at the edge
Collect accelerometer data, train a small classifier with Edge Impulse and run it on a microcontroller.
Before this: What Is Edge AI and TinyML?, IMUs and Sensor Fusion
Gesture recognition is the best first TinyML project because the data is easy to collect and the model is small. Choose three or four classes, for example idle, wave, circle and shake, and always include an idle or unknown class, or the model will force every movement into a gesture. Collect data from the real sensor mounted the way it will be used: an accelerometer at 50 to 100 Hz, in windows of about 1 to 2 seconds. Aim for at least a few minutes of data per class, from several people and with natural variations in speed and angle.
In Edge Impulse, create a project, connect the board through its data forwarder or firmware, and record samples for each class. Build an impulse: a time-series input with your window size, a spectral analysis processing block that turns raw motion into frequency and statistics features, and a small neural network classifier. Train it, then check the confusion matrix: it shows which classes get mixed up. If wave and shake are confused, collect more varied data for both rather than training longer.
Always test on data the model has not seen. Edge Impulse keeps a separate test set; aim for accuracy close to the training accuracy, because a big gap means the model memorised the training data (overfitting). Then deploy as an Arduino library, include it in your sketch, fill the input buffer with fresh readings and call run_classifier(). Only act when a class's score stays above a threshold (such as 0.8) for two windows in a row, which cuts false triggers.
Data matters more than the model
A gesture model learns from examples of accelerometer readings, so collect many repeats of each gesture from different people, speeds and board orientations. Include a class for no gesture, such as idle or random movement, otherwise the model will name a gesture for anything it sees. Label carefully, because a wrongly labelled recording teaches the wrong lesson.
Cut the recordings into windows of fixed length, such as a second, and keep some recordings aside as a test set that the model never trains on.
Judge it honestly
High accuracy on the training data means little. Check the accuracy on the unseen test set and look at the confusion matrix, which shows which gestures get mixed up. If two gestures are confused, record more of them or make them more different.
Then test on the real board. Sensor mounting, sample rate and noise on the real device differ from your recording setup, and a model that tested well on a laptop can disappoint in the hand.
Fit it on the chip
A microcontroller has limited memory, so a small model of a few thousand weights is typical. Quantising the model to 8-bit integers makes it smaller and faster with a little loss in accuracy. Check the RAM use and the time one prediction takes against your sampling rate.
- Training with no idle class, so the model sees gestures everywhere.
- Judging the model by its accuracy on the training data.
- Testing only on a laptop and not on the real device.
Practise this lesson with Maker
The explanation above is free for everyone. The practice for Intermediate lessons in every domain are part of the Maker plan at ₹499 a month, and Pro includes them too.
With Maker you also get: a worked example, a hands-on task, a 3-question check.
