Please select an option to see content specific to your location and shop online.

  • Free delivery on orders over £25 Free delivery on orders over £25

Project

micro:bit project: Machine learning dance move detector

a dance detecting micro:bit

Scroll down

The latest version of the BBC micro:bit is now powerful enough to run machine leaning. This project builds a system running on the micro:bit which can identify TikTok dance routines using the onboard accelerometer.

Throughout the project you will learn how to collect training data, build a neural network classifier and deploy it on the micro:bit using Edge Impulse We used it to build a micro:bit that can identify when someone is dancing the “Floss” TikTok. 

At the time of publication, (16/11/20) this project requires the Beta version of MakeCode https://makecode.microbit.org/beta This should change to the standard version  https://makecode.microbit.org in the future, please see https://microbit.org/beta-testing

 

 

1. micro:bit dance move transmitter

The dance move transmitter is battery operated and held by the dancer. It uses the accelerometer to sense the dance moves. Each reading consists of an x-axis, y-axis and z-axis comma-separated string (x,y,z). The data samples are sent over radio to another micro:bit which acts as the dance move receiver.

microbit-dancemove-transmitter

microbit dance transmitter makecode

  • Connect one micro:bit to your PC using the micro USB cable.
  • On Makecode, click the more options icon on the Download button to pair and connect to the micro:bit.

makecode-pair-device

  • Download the code to the micro:bit.
  • Detach the micro:bit from the PC and remove the USB cable.
  • Attach the battery to the micro:bit and switch it on.
  • When the micro:bit has started, press button A.

The top left LED on the display should blink showing that data is being transmitted

 

2. micro:bit dance move receiver

This micro:bit acts as the receiver for the accelerometer data and streams it to the PC. Attach it with the micro USB cable to your PC.

microbit-dancemove-receiver

receiver makecode

  • Pair the micro:bit with Makecode.
  • Download the code to the microb:it.

When the dance move transmitter is sending accelerometer readings, the top left LED on the display will blink to show that data is being received.

 

3. Install Edge Impulse Tools

The machine learning capability is provided by Edge Impulse. This is a browser-based studio for developing machine learning models. It is also used to produce C/C++ libraries of your trained model that can run standalone on the micro:bit.

edge impulse

node js

  • Install the Edge Impulse tools using Command Prompt.
$ npm install -g edge-impulse-cli

 

4. Connect the micro:bits

Before dance data can be collected the micro:bit dance move receiver needs to connect to Edge Impulse.

  • Make sure the dance move receiver is connected to your PC via its USB cable.
  • Switch on the dance move transmitter and press button A.
  • One LED should be flashing on both micro:bit displays showing that they are connected and data is being transmitted.
  • Start the Data Forwarder from a Command Prompt window and follow the prompts:
$ edge-impulse-data-forwarder
  • Open the url provided by the data forwarder and the device should show up in Edge Impulse studio.

Further details of using Edge Impulse Data Forwarder are here.

Edge Impulse data forwarder

 

5. Data acquisition

It’s now time to start collecting dance move samples for model training. Two types of samples need collecting; random dance moves and “Floss” TikTok moves. This will allow you to build a machine learning model that can distinguish between the two classes of data.

  • Select Data acquisition from the studio menu bar.
  • Give the data a label. We called ours “random-dance” and start collecting as many 10 second samples of random dance moves as possible. 30 to 40 should be sufficient.
  • Create a new label. We called ours “floss” and collect samples of the TikTok dance you want to be identified. 5 to 10 should be enough.

edge impulse

 

6. Create impulse

Once enough training data has been collected the machine learning pipeline can be configured.

  • Select Create impulse for the studio menu bar.
  • Select Time series data for x, y, z axes and set window size to 2000 ms.
  • Select Spectral Analysis for x, y & z.
  • Click Save Impulse.

save impulse

 

7. Spectral features

Now just click through the following buttons to set up the model features.

  • Set filter
  • Save parameters
  • Generate features

Once the features have been generated, you should see in the Feature Explorer a nice separation of the two different data classes – indicating that a good machine learning model can be created. The “random dance” samples are in yellow and “floss” samples nicely separated in blue below:

spectral features

 

8. Neural network training

This step builds a machine learning model representing the collected data set.

  • Select NN Classifier from the menu bar.
  • Set min confidence rating = 0.6.
  • Click Start Training – it takes a couple of minutes.

Once the training process has finished you can review the accuracy of the model.

neural network training

9. Model testing

Now the model can be tested to see if it can identify the TikTok dance movements.

  • Go back to Data Acquisition.
  • Select Test Data then capture some more TikTok dance samples.
  • Select Model Testing from the menu bar.
  • Select the samples to test and click Classify.

The model should be able to detect your dance now.

model testing

10. Deploy model

This step generates the C/C++ libraries that will be used to build the standalone model that runs on the micro:bit.

  • Select Deployment from the menu bar.
  • Select C++ library.
  • Click Build.

This will generate a compressed .zip file which should be saved to your PC.

Deploy model

 

11. Build firmware

This step integrates your specific machine learning model with the dance move project code and builds the firmware for the micro:bit.

  • Clone the dance-activated-microbit project from the OKdo GitHub:
$ git clone https://github.com/LetsOKdo/dance-activated-microbit.git
  • Open the File Explorer and delete the following directories from the project:
    • sourceedge-impulse-sdk
    • sourcemodel-parameters
    • sourcetflite-model
  • Expand the downloaded library zip and copy the contents to the project source directory.
  • Build firmware:
$ python build.py

 

  • Attach one of the micro:bits to the PC with the USB cable.
  • Copy the microbit.hex file in the project directory to the micro:bits drive.

12. Dance testing

This is the final step where you can test that everything is working.

  • Disconnect the micro:bit from the PC and remove the USB cable.
  • Attach the battery and switch it on.

A single LED should be ON in the centre of the display to indicate the ML model is running.
Now try your TikTok floss dance moves – the display will show a smiley as soon as it recognises the dance!

Summary

Machine Learning is an important technological development that is now within reach of the micro:bit with its latest revision. Edge Impulse is a powerful environment that simplifies many of the complexities of building Machine Learning models and makes it easy to deploy them on the micro:bit to do interesting things.

Further information about building Machine Learning models with Edge Impulse can be found in this video tutorial and on their website.

Hopefully following this project will have given you a good insight into Machine Learning and demonstrated its amazing capability on the micro:bit, in a fun way, so you can go and build your own.

Happy dancing!

 

Like what you read? Why not show your appreciation by giving some love.

From a quick tap to smashing that love button and show how much you enjoyed this project.