0:00:01.240,0:00:08.194 To create your AI activity timer, you [br]will train a machine learning, or ML, model 0:00:08.194,0:00:13.080 to recognise when you’re doing [br]different movements or activities. 0:00:13.080,0:00:18.960 You’ll then combine that model with some [br]ready-made code for an activity timer, 0:00:18.960,0:00:26.800 before downloading it to your [br]micro:bit and using it in real life. 0:00:26.800,0:00:33.960 Click ‘Open in micro:bit CreateAI’ to launch the project. 0:00:33.960,0:00:41.120 This project comes with 6 samples of movement [br]data for walking, 6 samples of movement data 0:00:41.120,0:00:47.200 for jumping up and down, and 6 samples of [br]movement data for staying fairly still. 0:00:47.200,0:00:54.200 You will add more samples by [br]recording your own movement data. 0:00:54.200,0:01:02.703 micro:bit CreateAI collects movement data[br]samples using the accelerometer,  [br]or movement sensor, on the micro:bit. 0:01:05.726,0:01:09.734 You will wear a micro:bit and battery pack on your wrist or ankle 0:01:09.734,0:01:15.120 so that you can move freely[br]to record your own movement data samples. 0:01:15.120,0:01:20.400 To get started, connect the [br]ankle-worn micro:bit to CreateAI. 0:01:20.400,0:01:23.816 We call this the data collection micro:bit. 0:01:23.816,0:01:31.640 If your computer has Bluetooth enabled then you will just need 1 micro:bit with a battery pack and a USB data lead. 0:01:31.640,0:01:36.640 If you don’t have a Bluetooth connection, [br]you’ll be prompted to use 2 micro:bits. 0:01:36.640,0:01:41.400 The second micro:bit will remain [br]connected to the USB cable and act as 0:01:41.400,0:01:50.600 a radio link to the data collection micro:bit.[br]Follow the instructions on screen to connect. 0:01:50.600,0:01:57.817 Once your micro:bit is connected, you will see the lines on the live graph change as  you move your micro:bit about. 0:01:57.817,0:02:02.297 You’re now ready to add your own movement data samples. 0:02:02.297,0:02:06.263 As this project already includes some data samples, 0:02:06.263,0:02:16.912 we suggest you just add 1 more sample for each action for now, and spend more time collecting and analysing data later. 0:02:16.912,0:02:24.800 Make sure your data collection micro:bit is attached to the inside of the ankle, with button B on top. 0:02:24.800,0:02:29.280 To add data to a specific action, [br]select it by clicking on it. 0:02:29.280,0:02:34.440 You will get a 3 second countdown [br]before a 1 second recording starts. 0:02:34.440,0:02:40.080 Click record and start moving right away [br]to ensure you get a clean data sample. 0:02:40.080,0:02:43.960 A clean sample is one where you [br]are moving for the entire sample, 0:02:43.960,0:02:48.593 you don’t start late or finish moving early. 0:02:48.593,0:02:55.519 Next try adding an extra data sample to the ‘jumping’ data set and the ‘being still’ data set. 0:02:55.519,0:03:05.040 Select them by clicking on the action, then click record and jump or stay quite still as you record the samples. 0:03:05.040,0:03:16.521 You’ll notice on the 'being still' samples [br]that the x,y,z lines change places depending on the angle of the attached micro:bit. 0:03:16.521,0:03:26.080 We don’t have a lot of data right now, but we do have enough to train our own  machine learning model using CreateAI. 0:03:26.080,0:03:33.720 So click ‘Train model’ to use the [br]current data to build an ML model. 0:03:33.720,0:03:41.363 The tool now builds a mathematical model that should recognise different actions when you move your micro:bit. 0:03:41.363,0:03:45.646 As soon as the model has been trained, you will see the Testing model page. 0:03:45.646,0:03:50.721 Now use the data collection micro:bit to test how well the model is working. 0:03:50.721,0:03:59.720 It should still be connected to the tool, and you’ll see that as you move it, CreateAI is estimating what action you are doing. 0:04:02.360,0:04:09.698 Try out each of the actions to see [br]both the estimated action and the certainty bar graph change. 0:04:11.257,0:04:19.126 The % on the certainty bar graph shows how confident the model is that you are doing each action. 0:04:21.600,0:04:26.520 You may notice your model is not estimating [br]some actions accurately, or maybe it is 0:04:26.520,0:04:32.720 working well for one action but not the other, [br]so after exploring how it is currently working, 0:04:32.720,0:04:40.360 it is a good idea to click on ‘Edit [br]data samples’ and improve your model. 0:04:40.360,0:04:46.360 Machine learning models usually work best with [br]MORE data, so record some extra samples for each 0:04:46.360,0:04:54.960 of the actions, or focus on collecting more data [br]for the action that was problematic in testing. 0:04:54.960,0:05:01.935 You can record one sample at a time or [br]you can record 10 samples in sequence. 0:05:10.160,0:05:23.081 Clean data samples also help an ML model work [br]better so examine your data set and identify any data samples that could confuse the model. 0:05:26.003,0:05:29.640 You can delete these by pressing X. 0:05:30.840,0:05:39.423 Once you’ve added more data and checked your data set, click ‘Train model’ again to use your amended data set. 0:05:40.483,0:05:45.992 Then test the model again on the ‘Testing model’ page. 0:05:48.555,0:05:54.640 Once you’re happy with how the ML model is behaving, you can use it with the ready-made project code. 0:05:54.640,0:06:02.480 Click on ‘Edit in MakeCode’ to see the code [br]blocks in a special version of Microsoft MakeCode. 0:06:02.480,0:06:09.560 You can always return to CreateAI using [br]the arrow in the top left of the screen. 0:06:09.560,0:06:19.240 These code blocks use the model you [br]have created within an exercise timer. 0:06:19.240,0:06:26.160 The code uses 3 variables to keep track [br]of how long you've been doing each action. 0:06:26.160,0:06:33.680 When the program first runs it [br]sets these timer variables to 0. 0:06:33.680,0:06:40.120 The 'on ML start' blocks are triggered when the ML [br]model decides you have started a specific action. 0:06:40.120,0:06:49.250 They show different icons on the micro:bit's LED display depending on the action it has estimated you are doing. 0:06:50.289,0:07:01.280 The 'on ML stop' blocks are triggered when the ML model decides you have finished an action, [br]in this case walking, jumping or being still. 0:07:01.280,0:07:06.880 Code inside each block clears the screen and [br]adds the duration of the action that has just 0:07:06.880,0:07:13.440 finished to the variable storing [br]the total times for each action. 0:07:13.440,0:07:19.440 The ML model works with the code to allow you [br]to view the total time spent on each action. 0:07:19.440,0:07:23.040 Press button A to see the estimate [br]of how long you were walking. 0:07:23.040,0:07:28.160 Press button B to see how long the [br]model estimated you were jumping. 0:07:28.160,0:07:34.080 To see the estimated duration you have [br]been still press A and B together. 0:07:34.080,0:07:44.111 The timer counts in milliseconds, thousandths of a second, so the number shown is divided by 1000 to show a time in seconds. 0:07:44.111,0:07:53.160 To make your AI activity timer run on your micro:bit, you just need to download this code to a micro:bit. 0:07:53.160,0:08:00.642 If you don’t have another micro:bit available,[br]simply replace the code currently on the data collection micro:bit with the project code. 0:08:01.646,0:08:05.000 Now you can test the project out in real life. 0:08:05.000,0:08:10.040 Do the correct icons display [br]when you are exercising or not? 0:08:10.040,0:08:15.800 You can test if the timer code is working [br]well with the model in 3 easy steps: 0:08:15.800,0:08:19.160 Press the reset button.[br]Jump for 30 seconds. 0:08:19.160,0:08:25.540 Then press button B.[br]You should see the number 30 scroll across your display. 0:08:25.540,0:08:28.560 You’re now ready to connect to CreateAI, 0:08:28.560,0:08:34.560 collect your own data, use it to train, test and [br]improve a machine learning model, and then you 0:08:34.560,0:08:40.600 can combine this model with the ready-made [br]code and try it out on your own micro:bit. 0:08:40.600,0:08:48.379 If you’re looking for ways to personalise this even more try adding some different actions like running or dance steps. 0:08:48.379,0:08:52.480 Enjoy!