< Return to Video

Simple door alarm coding video

  • 0:01 - 0:02
    to make my door alarm I've got a new
  • 0:02 - 0:04
    make code project let's get rid of the
  • 0:04 - 0:06
    on start block but we're going to keep
  • 0:06 - 0:07
    the forever block because we're going to
  • 0:07 - 0:09
    keep checking the magnetic field
  • 0:09 - 0:12
    measured by the microbits magnetometer
  • 0:12 - 0:13
    its
  • 0:13 - 0:16
    Compass go to logic and find the if
  • 0:16 - 0:19
    block and drag that in and also in logic
  • 0:19 - 0:21
    you'll find the comparison block so get
  • 0:21 - 0:23
    that hexagonal block and drop it on top
  • 0:23 - 0:25
    of
  • 0:25 - 0:28
    true then if we go to input and click on
  • 0:28 - 0:30
    more you'll find a block called magnet
  • 0:30 - 0:34
    magnetic force drop it in the first Hole
  • 0:34 - 0:36
    In the comparison block and we're going
  • 0:36 - 0:39
    to change it so it measures the overall
  • 0:39 - 0:41
    strength of the magnetic force your
  • 0:41 - 0:43
    microbits magnetometer can measure
  • 0:43 - 0:45
    magnetic force in different dimensions
  • 0:45 - 0:47
    but we're just interested in just how
  • 0:47 - 0:49
    strong it is overall and we're going to
  • 0:49 - 0:51
    pop a number in here that we might need
  • 0:51 - 0:52
    to change later but I'm just going to
  • 0:52 - 0:55
    pick 200 for the moment it measures the
  • 0:55 - 0:57
    strength of magnetic field in a unit
  • 0:57 - 0:59
    called micro Teslas and I'm going to try
  • 0:59 - 1:02
    200 to to start with if the magnetic
  • 1:02 - 1:05
    field Falls below 200 micro Teslas I'm
  • 1:05 - 1:08
    going to show an angry face because what
  • 1:08 - 1:10
    that will mean is the magnet has gone
  • 1:10 - 1:12
    away from my microbit somebody's opened
  • 1:12 - 1:15
    the door and uh we want to know
  • 1:15 - 1:16
    someone's been in the room so it's going
  • 1:16 - 1:18
    to show an angry face on the
  • 1:18 - 1:21
    display how do I know what number to
  • 1:21 - 1:23
    pick for the magnetic force how do I
  • 1:23 - 1:24
    know how strong my magnet is well we're
  • 1:24 - 1:26
    going to do something to sort that out
  • 1:26 - 1:29
    so if we go to input drag in on button a
  • 1:29 - 1:31
    press
  • 1:31 - 1:34
    and we'll add a show number block and
  • 1:34 - 1:36
    let's copy the magnetic force block if I
  • 1:36 - 1:39
    right click on it duplicate and drag it
  • 1:39 - 1:41
    in here and drop it there what this
  • 1:41 - 1:43
    means now is that when I press button a
  • 1:43 - 1:46
    I can measure the amount of magnetic
  • 1:46 - 1:48
    force measured by my microbit I can see
  • 1:48 - 1:49
    it on the
  • 1:49 - 1:52
    display so we're ready to try this out
  • 1:52 - 1:54
    now doesn't work in the simulator so
  • 1:54 - 1:55
    we're going to need to put this on a
  • 1:55 - 1:57
    real microbit so uh I'm going to call it
  • 1:57 - 2:00
    door alarm and I'm going to download the
  • 2:00 - 2:04
    hex file and transfer it to my microbit
  • 2:04 - 2:06
    I fix the microbit in the battery pack
  • 2:06 - 2:07
    to the door frame using something like
  • 2:07 - 2:10
    blue Tack and put the magnet on the door
  • 2:10 - 2:12
    itself very close to it have a look on
  • 2:12 - 2:14
    the back of your microbit board and see
  • 2:14 - 2:15
    where the compass is you need to make
  • 2:15 - 2:18
    sure the magnet is close to the compass
  • 2:18 - 2:20
    chip on the back of your
  • 2:20 - 2:22
    microbit now we can calibrate it with
  • 2:22 - 2:26
    the door closed press button a and get a
  • 2:26 - 2:28
    reading of the magnetic field strength
  • 2:28 - 2:30
    in my case it's around
  • 2:30 - 2:33
    453 microteslas
  • 2:33 - 2:35
    I'm then going to open the door and
  • 2:35 - 2:38
    press button a again and take a reading
  • 2:38 - 2:41
    with the door open it's 129 micro Teslas
  • 2:41 - 2:43
    now it can still measure some magnetism
  • 2:43 - 2:45
    don't forget the Earth is magnetic and
  • 2:45 - 2:46
    there are other things probably in my
  • 2:46 - 2:48
    house that are magnetic as well so the
  • 2:48 - 2:50
    microb bit is still picking up some
  • 2:50 - 2:53
    magnetic field so my number of 200
  • 2:53 - 2:56
    should work pretty well if it's more
  • 2:56 - 2:58
    than 200 it means the door is shut which
  • 2:58 - 3:00
    sounds likely cuz with the door shut I
  • 3:00 - 3:04
    had 453 micro Teslas if it's below 200
  • 3:04 - 3:05
    that probably means someone's open the
  • 3:05 - 3:07
    door in this case I know that when my
  • 3:07 - 3:10
    door is open I have 129 micro Teslas so
  • 3:10 - 3:12
    that should work okay now I should be
  • 3:12 - 3:14
    able to tell when someone open my door
  • 3:14 - 3:17
    an angry face will appear on my microbit
  • 3:17 - 3:19
    display and I'll know that somebody has
  • 3:19 - 3:21
    been in my room there are lots of things
  • 3:21 - 3:22
    you could do to this project to augment
  • 3:22 - 3:24
    it you could perhaps add a delay to give
  • 3:24 - 3:26
    yourself some time to get out the room
  • 3:26 - 3:28
    remember if you need to reset it you can
  • 3:28 - 3:30
    just press button a to show the magnetic
  • 3:30 - 3:32
    force again and that will clear the
  • 3:32 - 3:34
    angry face off the display on your
  • 3:34 - 3:36
    microbit uh maybe you could add an
  • 3:36 - 3:38
    audible alarm as well you could add a
  • 3:38 - 3:41
    music block so that when somebody opens
  • 3:41 - 3:44
    your door it makes an audible sound to
  • 3:44 - 3:46
    warn you that somebody has been inside
  • 3:46 - 3:48
    your room there are all sorts of ways
  • 3:48 - 3:51
    you could modify this
  • 3:51 - 3:54
    project
Title:
Simple door alarm coding video
Description:

more » « less
Video Language:
English
Team:
Microbit_Educational_Foundation
Project:
Make it: code it
Duration:
03:52

English (auto-generated) subtitles

Incomplete

Revisions

  • Revision 1 ASR: YouTube automatic subtitles
    Amara Bot