[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.64,0:00:05.04,Default,,0000,0000,0000,,To make my door alarm, I've got a new MakeCode \Nproject. Let's get rid of the 'on start' block Dialogue: 0,0:00:05.04,0:00:09.56,Default,,0000,0000,0000,,but keep the 'forever' block because we're going \Nto keep checking the magnetic field measured by Dialogue: 0,0:00:09.56,0:00:18.16,Default,,0000,0000,0000,,the micro:bit's magnetometer, its compass. Go to \N'Logic' and find the 'if' block and drag that in, Dialogue: 0,0:00:18.16,0:00:22.68,Default,,0000,0000,0000,,and also in 'Logic' we'll find the comparison \Nblock, so get that hexagonal block and drop Dialogue: 0,0:00:22.68,0:00:29.96,Default,,0000,0000,0000,,it on top of 'true'. Then, if we go to 'Input' \Nand click on 'more', you'll find a block called 'magnetic force'. Dialogue: 0,0:00:29.96,0:00:36.92,Default,,0000,0000,0000,,Drop it in the first hole in \Nthe comparison block, and we're going to change it Dialogue: 0,0:00:36.92,0:00:42.72,Default,,0000,0000,0000,,so that it measures the overall strength of the \Nmagnetic force. Your micro::bit's magnetometer can Dialogue: 0,0:00:42.72,0:00:47.36,Default,,0000,0000,0000,,measure magnetic force in different dimensions, \Nbut we're just interested in just how strong it is overall. Dialogue: 0,0:00:47.36,0:00:51.96,Default,,0000,0000,0000,,And we're going to pop a number \Nin here that we might need to change later but Dialogue: 0,0:00:51.96,0:00:56.32,Default,,0000,0000,0000,,I'm just going to pick 200 for the moment. It \Nmeasures the strength of the magnetic field Dialogue: 0,0:00:56.32,0:01:01.84,Default,,0000,0000,0000,,in a unit called 'microTeslas' and I'm going to \Ntry 200 to start with. If the magnetic field Dialogue: 0,0:01:01.84,0:01:09.48,Default,,0000,0000,0000,,falls below 200 microTeslas, I'm going to show an \Nangry face because what that will mean is that the Dialogue: 0,0:01:09.48,0:01:14.96,Default,,0000,0000,0000,,magnet has gone away from my micro:bit, somebody's \Nopened the door, and we want to know if someone's Dialogue: 0,0:01:14.96,0:01:20.56,Default,,0000,0000,0000,,been in the room so it's going to show an angry \Nface on the display. How do I know what number Dialogue: 0,0:01:20.56,0:01:24.48,Default,,0000,0000,0000,,to pick for the magnetic force? How do I know \Nhow strong my magnet is? Well, we're going to Dialogue: 0,0:01:24.48,0:01:29.84,Default,,0000,0000,0000,,do something to sort that out. So, if I go \Nto 'Input', I drag in 'on button A pressed', Dialogue: 0,0:01:30.84,0:01:37.20,Default,,0000,0000,0000,,and we'll add a 'show number' block. Let's copy \Nthe magnetic force block if I right-click on it, Dialogue: 0,0:01:37.20,0:01:43.48,Default,,0000,0000,0000,,duplicate, and drag it in here and drop it there. \NWhat this means now is that when I press button A, Dialogue: 0,0:01:43.48,0:01:48.00,Default,,0000,0000,0000,,I can measure the amount of magnetic force \Nmeasured by the micro:bit. I can see it on the display. Dialogue: 0,0:01:48.00,0:01:53.56,Default,,0000,0000,0000,,So, we're ready to try this \Nout now. It doesn't work in the simulator, Dialogue: 0,0:01:53.56,0:01:58.36,Default,,0000,0000,0000,,so we're going to put this on a real micro:bit. \NSo, I'm going to call it 'door alarm', Dialogue: 0,0:01:58.36,0:02:04.52,Default,,0000,0000,0000,,and I'm going to download the hex file, and \Ntransfer it to my micro:bit. I've fixed the Dialogue: 0,0:02:04.52,0:02:09.20,Default,,0000,0000,0000,,micro:bit and the battery pack to the door frame \Nusing something like Blu Tak and put the magnet Dialogue: 0,0:02:09.20,0:02:13.80,Default,,0000,0000,0000,,on the door itself, very close to it. Have a look \Non the back of the micro:bit board and see where the compass is. Dialogue: 0,0:02:13.80,0:02:18.96,Default,,0000,0000,0000,,You need to make sure the magnet \Nis close to the compass chip on the back of your micro:bit. Dialogue: 0,0:02:18.96,0:02:26.84,Default,,0000,0000,0000,,Now we can calibrate it. With the door \Nclosed, press button A and get a reading of Dialogue: 0,0:02:26.84,0:02:35.32,Default,,0000,0000,0000,,the magnetic field strength. In my case, it's around \N453 microTeslas. I'm then going to open the door, Dialogue: 0,0:02:35.32,0:02:42.00,Default,,0000,0000,0000,,press button A again and take a reading with the \Ndoor open. It's 129 microTeslas now. Dialogue: 0,0:02:42.00,0:02:46.08,Default,,0000,0000,0000,,It can still measure some magnetism, don't forget the Earth \Nis magnetic, and there are other things probably Dialogue: 0,0:02:46.08,0:02:51.56,Default,,0000,0000,0000,,in my house that are magnetic as well, so the \Nmicro:bit is still picking up some magnetic field. Dialogue: 0,0:02:51.56,0:02:58.16,Default,,0000,0000,0000,,So my number of 200 should work pretty well. If \Nit's more than 200, it means the door is shut, Dialogue: 0,0:02:58.16,0:03:04.00,Default,,0000,0000,0000,,it sounds likely. Because with the door shut \Nthat's 453 microTeslas. Below 200, that probably Dialogue: 0,0:03:04.00,0:03:08.60,Default,,0000,0000,0000,,means somebody has opened the door, in this \Ncase I know when my door is open I have 129 microTeslas. Dialogue: 0,0:03:08.60,0:03:13.84,Default,,0000,0000,0000,,So that should work OK now, I should \Nbe able to tell when someone has opened my door, Dialogue: 0,0:03:13.84,0:03:18.84,Default,,0000,0000,0000,,an angry face will appear on my micro:bit's \Ndisplay, and I'll know that somebody has been in my room. Dialogue: 0,0:03:18.84,0:03:23.08,Default,,0000,0000,0000,,There are lots of things you could do \Nto this project to augment it. You could perhaps Dialogue: 0,0:03:23.08,0:03:27.92,Default,,0000,0000,0000,,have a delay to give yourself some time to get \Nout the room. Remember if you need to reset it, Dialogue: 0,0:03:27.92,0:03:32.72,Default,,0000,0000,0000,,you could press button A to show the magnetic \Nforce again and that will clear the angry face Dialogue: 0,0:03:32.72,0:03:38.00,Default,,0000,0000,0000,,off the display of your micro:bit. Maybe you \Ncould add an audible alarm too or Dialogue: 0,0:03:38.00,0:03:44.96,Default,,0000,0000,0000,,you could add a music block so that when somebody opens \Nyour door, it makes an audible sound to warn you Dialogue: 0,0:03:44.96,0:03:51.92,Default,,0000,0000,0000,,that somebody has been inside your room. There are \Nall sorts of ways you could modify this project.