0:00:01.560,0:00:08.360 To create your simple AI exercise timer, [br]you’ll train a machine learning (or ML) model. 0:00:08.360,0:00:15.080 This model will recognise when you’re [br]exercising and when you’re not exercising. 0:00:15.080,0:00:23.720 You’ll then combine the model with some [br]ready-made code for an exercise timer... 0:00:23.720,0:00:28.720 before downloading it to your [br]micro:bit and using it in real life. 0:00:28.720,0:00:35.960 Click ‘Open in micro:bit CreateAI’ to launch the project. 0:00:35.960,0:00:40.760 The project comes with 3 samples [br]of movement data for exercising 0:00:40.760,0:00:45.440 and 3 samples of movement [br]data for not exercising. 0:00:45.440,0:00:51.000 You’ll need to add more samples by [br]recording your own movement data. 0:00:51.000,0:00:56.480 micro:bit CreateAI collects movement [br]data samples using the accelerometer 0:00:56.480,0:01:02.240 (or movement sensor) on the micro:bit.[br]You will wear a micro:bit and battery 0:01:02.240,0:01:08.840 pack on your wrist or ankle, so that you can move [br]freely to record your own movement data samples. 0:01:08.840,0:01:13.480 To get started, you need to set [br]up the data collection micro:bit. 0:01:13.480,0:01:22.240 Connect the wrist-worn micro:bit to CreateAI. [br]If your computer has Bluetooth enabled then you 0:01:22.240,0:01:28.680 will just need 1 micro:bit and a USB data lead.[br]If you don’t have a Bluetooth connection, 0:01:28.680,0:01:33.800 you’ll be prompted to use 2 micro:bits.[br]The second micro:bit will remain connected 0:01:33.800,0:01:39.640 to the USB cable and act as a radio [br]link to the data collection micro:bit. 0:01:39.640,0:01:42.936 Follow the instructions on screen to connect. 0:01:44.495,0:01:47.320 Once your data collection micro:bit is connected 0:01:47.320,0:01:53.280 you’ll see the lines on the live graph [br]change as you move your micro:bit about.[br] 0:01:53.280,0:01:58.360 You’re now ready to add your [br]own movement data samples.[br] 0:01:58.360,0:02:04.440 As this project already includes some [br]data samples, we suggest you just add 0:02:04.440,0:02:12.840 1 more sample for each action for now, and spend [br]more time collecting and analysing data later. 0:02:12.840,0:02:16.600 Decide what ‘exercising’ [br]action you are going to do. 0:02:16.600,0:02:23.040 This could be running, walking briskly, [br]jumping, boxing, dancing, or any other exercise. 0:02:23.040,0:02:29.920 Make sure the micro:bit is attached to [br]the wrist or ankle that will be moving. 0:02:29.920,0:02:34.440 To add data to a specific action, [br]select it by clicking on it. 0:02:34.440,0:02:39.640 You will get a 3 second countdown [br]before a 1 second recording starts. 0:02:39.640,0:02:45.200 Click record and start moving right away [br]to ensure you get a clean data sample. 0:02:45.200,0:02:49.080 A clean sample is one where you [br]are moving for the entire sample, 0:02:49.080,0:02:55.440 you don’t start late or finish moving early.[br]Next try adding an extra data sample 0:02:55.440,0:03:00.920 to the ‘not exercising’ data set.[br]Select it by clicking on the action, 0:03:00.920,0:03:06.440 then stay still, or only move very [br]slightly as you record the sample. 0:03:06.440,0:03:10.800 You’ll notice that the x,y,z [br]lines change places depending 0:03:10.800,0:03:14.768 on the angle at which you hold your micro:bit. 0:03:14.768,0:03:18.320 The project doesn’t have a lot of data right now, 0:03:18.320,0:03:24.400 but we have enough to train our own [br]machine learning model using CreateAI. 0:03:24.400,0:03:30.360 So click ‘Train’ to use the [br]current data to build an ML model. 0:03:30.360,0:03:34.640 The tool now builds a mathematical [br]model that should recognise different 0:03:34.640,0:03:39.360 actions when you move your micro:bit.[br]As soon as the model has been trained, 0:03:39.360,0:03:44.080 you’ll see the Testing model page.[br]Your data collection micro:bit can now 0:03:44.080,0:03:50.160 be used to test how well the model is working.[br]It should still be connected to the tool, 0:03:50.160,0:03:59.800 and you’ll see that as you move it, CreateAI [br]is estimating what action you are doing. 0:03:59.800,0:04:05.240 Try out different levels of exercising or [br]not exercising to see both the estimated 0:04:05.240,0:04:12.400 action and the certainty bar graph change.[br]The % on the certainty bar graph shows how 0:04:12.400,0:04:16.840 confident the model is that [br]you are doing each action. 0:04:16.840,0:04:22.240 You may notice your model is not estimating [br]some actions accurately, or maybe it is 0:04:22.240,0:04:28.560 working well for one action but not the other,[br]so after exploring how it is currently working, 0:04:28.560,0:04:34.520 it’s a good idea to click on ‘Edit [br]data samples’ and improve your model. 0:04:34.520,0:04:41.320 Machine learning models usually work best with [br]more data, so record some extra samples for each 0:04:41.320,0:04:48.800 of the actions, or focus on collecting more data [br]for the action that was problematic in testing. 0:04:48.800,0:04:54.240 You can record 1 sample at a time or [br]you can record 10 samples in sequence. 0:04:54.240,0:04:58.840 Clean data samples also [br]help an ML model work better 0:04:58.840,0:05:05.560 so interrogate your data set and identify any [br]data samples that could confuse the model. 0:05:05.560,0:05:12.080 You can delete these by pressing x.[br]Once you’ve added more data and checked 0:05:12.080,0:05:17.720 your data set, click Train model [br]again to use your amended data set. 0:05:17.720,0:05:27.000 Then test the model again on [br]the ‘Testing model’ page. 0:05:27.000,0:05:30.200 Once you’re happy with how [br]the ML model is behaving, 0:05:30.200,0:05:34.120 you can use it with the ready-made project code. 0:05:34.120,0:05:40.920 Click on 'Edit in MakeCode' to see the code blocks [br]in a special version of Microsoft MakeCode. 0:05:40.920,0:05:48.560 You can always return to CreateAI using [br]the arrow in the top left of the screen. 0:05:48.560,0:05:54.720 These code blocks use the model you [br]have created within an exercise timer. 0:05:54.720,0:05:59.760 The code uses two variables to keep track [br]of how long you've been exercising and how 0:05:59.760,0:06:04.160 long you've not been exercising.[br]When the program first runs it sets 0:06:04.160,0:06:09.360 these timer variables to 0.[br]The 'on ML start' blocks are 0:06:09.360,0:06:15.400 triggered when the ML model decides you have [br]started either exercising or not exercising. 0:06:15.400,0:06:19.240 They show different icons on the [br]micro:bit's LED display depending 0:06:19.240,0:06:25.920 on the action it has estimated you are doing.[br]The 'on ML stop' blocks are triggered when the 0:06:25.920,0:06:32.960 ML model decides you have finished an action, [br]in this case exercising or not exercising. 0:06:32.960,0:06:38.240 Code inside each block clears the screen and [br]adds the duration of the action that has just 0:06:38.240,0:06:43.360 finished to the variable storing [br]the total times for each action. 0:06:43.360,0:06:49.680 The ML model works with the code to allow you [br]to view the total time spent on each action. 0:06:49.680,0:06:55.160 Press button A to see the total time you have [br]been exercising and press button B to see the 0:06:55.160,0:07:00.680 total time you have been inactive.[br]The timer counts in milliseconds, 0:07:00.680,0:07:07.880 thousandths of a second, so the number shown [br]is divided by 1000 to show a time in seconds. 0:07:07.880,0:07:12.640 To make your simple AI exercise [br]timer run on your micro:bit, you 0:07:12.640,0:07:19.360 just need to download this code to a micro:bit.[br]If you don’t have another micro:bit available, 0:07:19.360,0:07:26.440 simply replace the code currently on the data [br]collection micro:bit with the project code.[br] 0:07:26.440,0:07:31.200 Now test the project out in real life. [br]Do the correct icons display 0:07:31.200,0:07:36.640 when you are exercising or not?[br]You can test if the timer code is working 0:07:36.640,0:07:41.640 well with the model in 3 easy steps:[br]Press the reset button. 0:07:41.640,0:07:46.040 Exercise for 30 seconds.[br]Then press button A. 0:07:46.040,0:07:50.080 You should see the number 30 [br]scroll across your display. 0:07:50.080,0:07:55.240 You’re now ready to connect to CreateAI, [br]collect your own data, use it to train, 0:07:55.240,0:08:00.160 test & improve a machine learning model.[br]And you can then combine this model with 0:08:00.160,0:08:05.642 the ready-made code and try [br]it out on your own micro:bit.