1 00:00:00,640 --> 00:00:02,159 to make my door alarm I've got a new 2 00:00:02,159 --> 00:00:04,000 make code project let's get rid of the 3 00:00:04,000 --> 00:00:05,759 on start block but we're going to keep 4 00:00:05,759 --> 00:00:07,120 the forever block because we're going to 5 00:00:07,120 --> 00:00:09,080 keep checking the magnetic field 6 00:00:09,080 --> 00:00:11,639 measured by the microbits magnetometer 7 00:00:11,639 --> 00:00:12,839 its 8 00:00:12,839 --> 00:00:16,199 Compass go to logic and find the if 9 00:00:16,199 --> 00:00:19,199 block and drag that in and also in logic 10 00:00:19,199 --> 00:00:21,199 you'll find the comparison block so get 11 00:00:21,199 --> 00:00:23,240 that hexagonal block and drop it on top 12 00:00:23,240 --> 00:00:24,519 of 13 00:00:24,519 --> 00:00:27,800 true then if we go to input and click on 14 00:00:27,800 --> 00:00:29,960 more you'll find a block called magnet 15 00:00:29,960 --> 00:00:33,640 magnetic force drop it in the first Hole 16 00:00:33,640 --> 00:00:36,320 In the comparison block and we're going 17 00:00:36,320 --> 00:00:39,320 to change it so it measures the overall 18 00:00:39,320 --> 00:00:41,440 strength of the magnetic force your 19 00:00:41,440 --> 00:00:43,120 microbits magnetometer can measure 20 00:00:43,120 --> 00:00:44,920 magnetic force in different dimensions 21 00:00:44,920 --> 00:00:47,199 but we're just interested in just how 22 00:00:47,199 --> 00:00:49,399 strong it is overall and we're going to 23 00:00:49,399 --> 00:00:50,960 pop a number in here that we might need 24 00:00:50,960 --> 00:00:52,480 to change later but I'm just going to 25 00:00:52,480 --> 00:00:55,120 pick 200 for the moment it measures the 26 00:00:55,120 --> 00:00:56,760 strength of magnetic field in a unit 27 00:00:56,760 --> 00:00:59,480 called micro Teslas and I'm going to try 28 00:00:59,480 --> 00:01:01,519 200 to to start with if the magnetic 29 00:01:01,519 --> 00:01:05,360 field Falls below 200 micro Teslas I'm 30 00:01:05,360 --> 00:01:08,400 going to show an angry face because what 31 00:01:08,400 --> 00:01:10,200 that will mean is the magnet has gone 32 00:01:10,200 --> 00:01:12,040 away from my microbit somebody's opened 33 00:01:12,040 --> 00:01:14,680 the door and uh we want to know 34 00:01:14,680 --> 00:01:15,880 someone's been in the room so it's going 35 00:01:15,880 --> 00:01:18,119 to show an angry face on the 36 00:01:18,119 --> 00:01:20,799 display how do I know what number to 37 00:01:20,799 --> 00:01:22,520 pick for the magnetic force how do I 38 00:01:22,520 --> 00:01:24,280 know how strong my magnet is well we're 39 00:01:24,280 --> 00:01:26,320 going to do something to sort that out 40 00:01:26,320 --> 00:01:29,360 so if we go to input drag in on button a 41 00:01:29,360 --> 00:01:30,840 press 42 00:01:30,840 --> 00:01:33,600 and we'll add a show number block and 43 00:01:33,600 --> 00:01:36,040 let's copy the magnetic force block if I 44 00:01:36,040 --> 00:01:38,759 right click on it duplicate and drag it 45 00:01:38,759 --> 00:01:40,680 in here and drop it there what this 46 00:01:40,680 --> 00:01:43,479 means now is that when I press button a 47 00:01:43,479 --> 00:01:45,520 I can measure the amount of magnetic 48 00:01:45,520 --> 00:01:47,759 force measured by my microbit I can see 49 00:01:47,759 --> 00:01:48,799 it on the 50 00:01:48,799 --> 00:01:51,920 display so we're ready to try this out 51 00:01:51,920 --> 00:01:53,719 now doesn't work in the simulator so 52 00:01:53,719 --> 00:01:54,640 we're going to need to put this on a 53 00:01:54,640 --> 00:01:57,079 real microbit so uh I'm going to call it 54 00:01:57,079 --> 00:01:59,880 door alarm and I'm going to download the 55 00:01:59,880 --> 00:02:03,759 hex file and transfer it to my microbit 56 00:02:03,759 --> 00:02:05,680 I fix the microbit in the battery pack 57 00:02:05,680 --> 00:02:07,320 to the door frame using something like 58 00:02:07,320 --> 00:02:09,720 blue Tack and put the magnet on the door 59 00:02:09,720 --> 00:02:11,800 itself very close to it have a look on 60 00:02:11,800 --> 00:02:13,640 the back of your microbit board and see 61 00:02:13,640 --> 00:02:15,400 where the compass is you need to make 62 00:02:15,400 --> 00:02:17,599 sure the magnet is close to the compass 63 00:02:17,599 --> 00:02:19,599 chip on the back of your 64 00:02:19,599 --> 00:02:22,400 microbit now we can calibrate it with 65 00:02:22,400 --> 00:02:26,000 the door closed press button a and get a 66 00:02:26,000 --> 00:02:28,239 reading of the magnetic field strength 67 00:02:28,239 --> 00:02:30,319 in my case it's around 68 00:02:30,319 --> 00:02:32,599 453 microteslas 69 00:02:32,599 --> 00:02:35,319 I'm then going to open the door and 70 00:02:35,319 --> 00:02:37,640 press button a again and take a reading 71 00:02:37,640 --> 00:02:41,400 with the door open it's 129 micro Teslas 72 00:02:41,400 --> 00:02:43,080 now it can still measure some magnetism 73 00:02:43,080 --> 00:02:45,000 don't forget the Earth is magnetic and 74 00:02:45,000 --> 00:02:46,360 there are other things probably in my 75 00:02:46,360 --> 00:02:47,959 house that are magnetic as well so the 76 00:02:47,959 --> 00:02:49,680 microb bit is still picking up some 77 00:02:49,680 --> 00:02:52,879 magnetic field so my number of 200 78 00:02:52,879 --> 00:02:55,720 should work pretty well if it's more 79 00:02:55,720 --> 00:02:58,360 than 200 it means the door is shut which 80 00:02:58,360 --> 00:03:00,239 sounds likely cuz with the door shut I 81 00:03:00,239 --> 00:03:03,640 had 453 micro Teslas if it's below 200 82 00:03:03,640 --> 00:03:04,959 that probably means someone's open the 83 00:03:04,959 --> 00:03:06,680 door in this case I know that when my 84 00:03:06,680 --> 00:03:09,920 door is open I have 129 micro Teslas so 85 00:03:09,920 --> 00:03:11,680 that should work okay now I should be 86 00:03:11,680 --> 00:03:13,840 able to tell when someone open my door 87 00:03:13,840 --> 00:03:17,040 an angry face will appear on my microbit 88 00:03:17,040 --> 00:03:18,640 display and I'll know that somebody has 89 00:03:18,640 --> 00:03:20,760 been in my room there are lots of things 90 00:03:20,760 --> 00:03:22,360 you could do to this project to augment 91 00:03:22,360 --> 00:03:24,080 it you could perhaps add a delay to give 92 00:03:24,080 --> 00:03:26,280 yourself some time to get out the room 93 00:03:26,280 --> 00:03:28,159 remember if you need to reset it you can 94 00:03:28,159 --> 00:03:30,239 just press button a to show the magnetic 95 00:03:30,239 --> 00:03:31,599 force again and that will clear the 96 00:03:31,599 --> 00:03:33,920 angry face off the display on your 97 00:03:33,920 --> 00:03:36,080 microbit uh maybe you could add an 98 00:03:36,080 --> 00:03:38,400 audible alarm as well you could add a 99 00:03:38,400 --> 00:03:41,480 music block so that when somebody opens 100 00:03:41,480 --> 00:03:44,360 your door it makes an audible sound to 101 00:03:44,360 --> 00:03:46,360 warn you that somebody has been inside 102 00:03:46,360 --> 00:03:48,200 your room there are all sorts of ways 103 00:03:48,200 --> 00:03:50,920 you could modify this 104 00:03:50,920 --> 00:03:53,920 project