Make an AI sports data logger with micro:bit CreateAI that logs how much time you and others spend running, walking and being still.
Treoir tionscadal céim ar chéim saor in aisce,
Céim 1: é a thuiscint
How does it work?
In this project, you’ll train a machine learning (ML) model to recognise when you’re running, walking and being still.
You’ll combine that model with a MakeCode program that uses the micro:bit’s data logging function to record what action you are doing every second.
This project could be useful in sports such as football or netball where you need to analyse how active certain players are. You could also use it to monitor how much time you have spent running or walking during school breaks or a during a workout.
Cad is foghlaim meaisín ann?
Is cineál hintleachta saorga (AI) é foghlaim meaisín (ML) inar féidir le ríomhairí foghlaim uathu agus cinntí a dhéanamh bunaithe ar shonraí.
Cuireann daoine oiliúint ar mhúnlaí ML chun cabhrú leo na cinntí sin a dhéanamh, mar shampla, ‘gníomhartha’ difriúla a aithint nuair a bhogann tú do micro:bit ar bhealaí éagsúla.
Cad a chaithfidh mé a dhéanamh?
Teastaíonn daoine ó chórais AI chun iad a dhearadh, a thógáil, a thástáil agus a úsáid. Baileoidh tú sonraí chun samhail ML a thraenáil, é a thástáil, é a fheabhsú, agus é a chomhcheangail le cód ríomhaire chun gléas cliste a chruthú a úsáideann AI. Úsáidfidh tú micro:bit agus an suíomh gréasáin micro:bit CreateAI chun é seo a dhéanamh.
Céim 2: Cruthaigh é
Cad a theastaíonn uait
- A micro:bit V2, USB cable, and a battery pack with 2 x AAA batteries
- A computer (e.g. desktop, laptop, or Chromebook) with access to the micro:bit CreateAI website, using a Chrome or Edge web browser
- Mura bhfuil Bluetooth cumasaithe ag do ríomhaire, beidh micro:bit V2 breise uait
- A strap and holder, or another way to attach the micro:bit to your wrist (e.g. flexible craft stems or elastic bands)
- You may also find our micro:bit CreateAI teaching tips useful
Bailigh samplaí sonraí
When you open the project in micro:bit CreateAI, you’ll see we’ve given you some data samples for ‘running’, 'walking’ and ‘still’ actions:
walking
running
still
You can add your own movement samples using the micro:bit's movement sensor or accelerometer.
I micro:bit CreateAI, cliceáil ar an gcnaipe ‘Connect’ chun do bhailiú sonraí a nascadh micro:bit agus lean na treoracha.
Attach the data collection micro:bit to your left wrist like a watch, with the logo at the top. Click on the first action, ‘walking’, and click 'Record' to record your own data samples. Má dhéanann tú botún, is féidir leat aon samplaí nach dteastaíonn uait a scriosadh. Is féidir leat freisin cnaipe B a bhrú ar an micro:bit chun taifeadadh a thosú.
Más mian leat taifeadadh go leanúnach ar feadh 10 soicind chun 10 sampla a fháil, cliceáil ar na trí phonc in aice leis an gcnaipe taifeadta agus roghnaigh an rogha sin.
Now record your own data samples for the ‘running’ action, then the ‘still’ action, making sure for ‘still’ that you collect samples in different positions, such as facing up and down.
Déan an múnla a oiliúint agus a thástáil
Cliceáil an cnaipe ‘Samhail a thraenáil’ chun an tsamhail a thraenáil, agus ansin déan tástáil uirthi. Try walking and see if ‘walking’ is the estimated action, then running to see if ‘running’ is the estimated action. Keep still and see if ‘still’ is estimated. Give your micro:bit to someone else to wear (making sure they put it on the same wrist and in the same orientation) and see if it works as well for them.
Feabhas a chur ar do mhúnla
Is féidir an chuid is mó de na samhlacha a fheabhsú le níos mó sonraí. Más gá an tsamhail a fheabhsú, cliceáil ar ‘← Cuir samplaí sonraí in eagar’.
You can delete any data samples which you think don’t fit or add more samples from yourself and other people.
Traenáil an tsamhail arís, agus déan tástáil arís air.
Cuir an tsamhail agus an cód ar do micro:bit
I micro:bit CreateAI cliceáil ar ‘Cuir in Eagar i MakeCode’ chun cód an tionscadail a fheiceáil san eagarthóir MakeCode.
Is féidir leat an cód a mhodhnú nó triail a bhaint as mar atá sé. Attach your micro:bit using a USB cable, click on the ‘Download’ button in the MakeCode screen, and follow the instructions to transfer your AI model and the code blocks to it.
Attach a battery pack to the micro:bit and put it on, ready to test out.
Collect your data
First press buttons A and B together to delete any old data logs from your micro:bit. Reset the timer by pressing the reset button on the back of the micro:bit. Press button A to start logging and button B to stop logging.
Your data will stay on your micro:bit even if you disconnect the battery or press the reset button.
Déan anailís ar do shonraí
Dícheangail an pacáiste ceallraí agus breiseán an micro:bit ar ais isteach sa ríomhaire. Tá an chuma ar an micro:bit mar thiomántán USB ar a dtugtar MICROBIT. Féach sa tiomántán MICROBIT agus oscail an comhad MY_DATA chun tábla de do shonraí a fheiceáil i mbrabhsálaí gréasáin:

The time stamps in the log represent the amount of time that has passed since your micro:bit was powered on or reset.
Click on Visual preview to see a graph of your data:

You can also click on the Copy button and then paste your data into a spreadsheet.
Conas a oibríonn na bloic cód
This program uses a variable called ‘logging’. A variable in a computer program is a container for storing data which can be accessed and updated while the program is running. In this program, the variable ‘logging’ controls if the micro:bit is logging or not and can be set to ‘true’ or ‘false’. Variables that can be set to these two values are called ‘Boolean’ variables.
When the program starts, the variable ‘logging’ is set to false. A show icon block is used to display a ‘no’ icon on the LED display to indicate the micro:bit is not logging. The set columns and set timestamp blocks create labels for the data logging table your micro:bit will produce.
The on button A pressed block is used to set logging to ‘true’ and show a ‘yes’ icon on the LED display. The on button B pressed block is used to set logging to ‘false’ and show a ‘no’ icon on the LED display. And the on buttons A + B pressed block sets logging to ‘false’, displays a skull icon, and deletes any log.
Finally, an ‘every’ block is used to check every 1,000 milliseconds or second if the micro:bit is logging. If it is, an ‘if then else’ block is used with ‘is ML detected’ and ‘log data’ blocks to record a 0 if you are still, a 1 if you are walking and a 2 if you are running in your data logging table. If the micro:bit cannot detect what you are doing, it records a -1 in the table. Bigger numbers are used for more active actions, so the resulting data logging graph gives you a clear visual record of how active you have been.
Meastóireacht
How accurate is the AI sports logger in tracking your movements? How could you improve its accuracy? Who would find this device particularly useful? How does it compare to the Step counter or the Movement data logger projects?
Céim 3: Déan é a leathnú
- Add a fourth action such as ‘throwing’ for sports like netball or tennis.

Excel spreadsheet with formula to count certain activity cells
- Add up how much time you spent on each activity. You could do this saving your data as a CSV file, opening it in a spreadsheet and using a formula such as =COUNTIF(B2:B70,1) Where B2:B70 is the range of the activity cells, and 1 is the activity number meaning ‘walking’.
This content is published under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) licence.