WEBVTT 00:00:00.640 --> 00:00:02.159 to make my door alarm I've got a new 00:00:02.159 --> 00:00:04.000 make code project let's get rid of the 00:00:04.000 --> 00:00:05.759 on start block but we're going to keep 00:00:05.759 --> 00:00:07.120 the forever block because we're going to 00:00:07.120 --> 00:00:09.080 keep checking the magnetic field 00:00:09.080 --> 00:00:11.639 measured by the microbits magnetometer 00:00:11.639 --> 00:00:12.839 its 00:00:12.839 --> 00:00:16.199 Compass go to logic and find the if 00:00:16.199 --> 00:00:19.199 block and drag that in and also in logic 00:00:19.199 --> 00:00:21.199 you'll find the comparison block so get 00:00:21.199 --> 00:00:23.240 that hexagonal block and drop it on top 00:00:23.240 --> 00:00:24.519 of 00:00:24.519 --> 00:00:27.800 true then if we go to input and click on 00:00:27.800 --> 00:00:29.960 more you'll find a block called magnet 00:00:29.960 --> 00:00:33.640 magnetic force drop it in the first Hole 00:00:33.640 --> 00:00:36.320 In the comparison block and we're going 00:00:36.320 --> 00:00:39.320 to change it so it measures the overall 00:00:39.320 --> 00:00:41.440 strength of the magnetic force your 00:00:41.440 --> 00:00:43.120 microbits magnetometer can measure 00:00:43.120 --> 00:00:44.920 magnetic force in different dimensions 00:00:44.920 --> 00:00:47.199 but we're just interested in just how 00:00:47.199 --> 00:00:49.399 strong it is overall and we're going to 00:00:49.399 --> 00:00:50.960 pop a number in here that we might need 00:00:50.960 --> 00:00:52.480 to change later but I'm just going to 00:00:52.480 --> 00:00:55.120 pick 200 for the moment it measures the 00:00:55.120 --> 00:00:56.760 strength of magnetic field in a unit 00:00:56.760 --> 00:00:59.480 called micro Teslas and I'm going to try 00:00:59.480 --> 00:01:01.519 200 to to start with if the magnetic 00:01:01.519 --> 00:01:05.360 field Falls below 200 micro Teslas I'm 00:01:05.360 --> 00:01:08.400 going to show an angry face because what 00:01:08.400 --> 00:01:10.200 that will mean is the magnet has gone 00:01:10.200 --> 00:01:12.040 away from my microbit somebody's opened 00:01:12.040 --> 00:01:14.680 the door and uh we want to know 00:01:14.680 --> 00:01:15.880 someone's been in the room so it's going 00:01:15.880 --> 00:01:18.119 to show an angry face on the 00:01:18.119 --> 00:01:20.799 display how do I know what number to 00:01:20.799 --> 00:01:22.520 pick for the magnetic force how do I 00:01:22.520 --> 00:01:24.280 know how strong my magnet is well we're 00:01:24.280 --> 00:01:26.320 going to do something to sort that out 00:01:26.320 --> 00:01:29.360 so if we go to input drag in on button a 00:01:29.360 --> 00:01:30.840 press 00:01:30.840 --> 00:01:33.600 and we'll add a show number block and 00:01:33.600 --> 00:01:36.040 let's copy the magnetic force block if I 00:01:36.040 --> 00:01:38.759 right click on it duplicate and drag it 00:01:38.759 --> 00:01:40.680 in here and drop it there what this 00:01:40.680 --> 00:01:43.479 means now is that when I press button a 00:01:43.479 --> 00:01:45.520 I can measure the amount of magnetic 00:01:45.520 --> 00:01:47.759 force measured by my microbit I can see 00:01:47.759 --> 00:01:48.799 it on the 00:01:48.799 --> 00:01:51.920 display so we're ready to try this out 00:01:51.920 --> 00:01:53.719 now doesn't work in the simulator so 00:01:53.719 --> 00:01:54.640 we're going to need to put this on a 00:01:54.640 --> 00:01:57.079 real microbit so uh I'm going to call it 00:01:57.079 --> 00:01:59.880 door alarm and I'm going to download the 00:01:59.880 --> 00:02:03.759 hex file and transfer it to my microbit 00:02:03.759 --> 00:02:05.680 I fix the microbit in the battery pack 00:02:05.680 --> 00:02:07.320 to the door frame using something like 00:02:07.320 --> 00:02:09.720 blue Tack and put the magnet on the door 00:02:09.720 --> 00:02:11.800 itself very close to it have a look on 00:02:11.800 --> 00:02:13.640 the back of your microbit board and see 00:02:13.640 --> 00:02:15.400 where the compass is you need to make 00:02:15.400 --> 00:02:17.599 sure the magnet is close to the compass 00:02:17.599 --> 00:02:19.599 chip on the back of your 00:02:19.599 --> 00:02:22.400 microbit now we can calibrate it with 00:02:22.400 --> 00:02:26.000 the door closed press button a and get a 00:02:26.000 --> 00:02:28.239 reading of the magnetic field strength 00:02:28.239 --> 00:02:30.319 in my case it's around 00:02:30.319 --> 00:02:32.599 453 microteslas 00:02:32.599 --> 00:02:35.319 I'm then going to open the door and 00:02:35.319 --> 00:02:37.640 press button a again and take a reading 00:02:37.640 --> 00:02:41.400 with the door open it's 129 micro Teslas 00:02:41.400 --> 00:02:43.080 now it can still measure some magnetism 00:02:43.080 --> 00:02:45.000 don't forget the Earth is magnetic and 00:02:45.000 --> 00:02:46.360 there are other things probably in my 00:02:46.360 --> 00:02:47.959 house that are magnetic as well so the 00:02:47.959 --> 00:02:49.680 microb bit is still picking up some 00:02:49.680 --> 00:02:52.879 magnetic field so my number of 200 00:02:52.879 --> 00:02:55.720 should work pretty well if it's more 00:02:55.720 --> 00:02:58.360 than 200 it means the door is shut which 00:02:58.360 --> 00:03:00.239 sounds likely cuz with the door shut I 00:03:00.239 --> 00:03:03.640 had 453 micro Teslas if it's below 200 00:03:03.640 --> 00:03:04.959 that probably means someone's open the 00:03:04.959 --> 00:03:06.680 door in this case I know that when my 00:03:06.680 --> 00:03:09.920 door is open I have 129 micro Teslas so 00:03:09.920 --> 00:03:11.680 that should work okay now I should be 00:03:11.680 --> 00:03:13.840 able to tell when someone open my door 00:03:13.840 --> 00:03:17.040 an angry face will appear on my microbit 00:03:17.040 --> 00:03:18.640 display and I'll know that somebody has 00:03:18.640 --> 00:03:20.760 been in my room there are lots of things 00:03:20.760 --> 00:03:22.360 you could do to this project to augment 00:03:22.360 --> 00:03:24.080 it you could perhaps add a delay to give 00:03:24.080 --> 00:03:26.280 yourself some time to get out the room 00:03:26.280 --> 00:03:28.159 remember if you need to reset it you can 00:03:28.159 --> 00:03:30.239 just press button a to show the magnetic 00:03:30.239 --> 00:03:31.599 force again and that will clear the 00:03:31.599 --> 00:03:33.920 angry face off the display on your 00:03:33.920 --> 00:03:36.080 microbit uh maybe you could add an 00:03:36.080 --> 00:03:38.400 audible alarm as well you could add a 00:03:38.400 --> 00:03:41.480 music block so that when somebody opens 00:03:41.480 --> 00:03:44.360 your door it makes an audible sound to 00:03:44.360 --> 00:03:46.360 warn you that somebody has been inside 00:03:46.360 --> 00:03:48.200 your room there are all sorts of ways 00:03:48.200 --> 00:03:50.920 you could modify this 00:03:50.920 --> 00:03:53.920 project