-
to make my door alarm I've got a new
-
make code project let's get rid of the
-
on start block but we're going to keep
-
the forever block because we're going to
-
keep checking the magnetic field
-
measured by the microbits magnetometer
-
its
-
Compass go to logic and find the if
-
block and drag that in and also in logic
-
you'll find the comparison block so get
-
that hexagonal block and drop it on top
-
of
-
true then if we go to input and click on
-
more you'll find a block called magnet
-
magnetic force drop it in the first Hole
-
In the comparison block and we're going
-
to change it so it measures the overall
-
strength of the magnetic force your
-
microbits magnetometer can measure
-
magnetic force in different dimensions
-
but we're just interested in just how
-
strong it is overall and we're going to
-
pop a number in here that we might need
-
to change later but I'm just going to
-
pick 200 for the moment it measures the
-
strength of magnetic field in a unit
-
called micro Teslas and I'm going to try
-
200 to to start with if the magnetic
-
field Falls below 200 micro Teslas I'm
-
going to show an angry face because what
-
that will mean is the magnet has gone
-
away from my microbit somebody's opened
-
the door and uh we want to know
-
someone's been in the room so it's going
-
to show an angry face on the
-
display how do I know what number to
-
pick for the magnetic force how do I
-
know how strong my magnet is well we're
-
going to do something to sort that out
-
so if we go to input drag in on button a
-
press
-
and we'll add a show number block and
-
let's copy the magnetic force block if I
-
right click on it duplicate and drag it
-
in here and drop it there what this
-
means now is that when I press button a
-
I can measure the amount of magnetic
-
force measured by my microbit I can see
-
it on the
-
display so we're ready to try this out
-
now doesn't work in the simulator so
-
we're going to need to put this on a
-
real microbit so uh I'm going to call it
-
door alarm and I'm going to download the
-
hex file and transfer it to my microbit
-
I fix the microbit in the battery pack
-
to the door frame using something like
-
blue Tack and put the magnet on the door
-
itself very close to it have a look on
-
the back of your microbit board and see
-
where the compass is you need to make
-
sure the magnet is close to the compass
-
chip on the back of your
-
microbit now we can calibrate it with
-
the door closed press button a and get a
-
reading of the magnetic field strength
-
in my case it's around
-
453 microteslas
-
I'm then going to open the door and
-
press button a again and take a reading
-
with the door open it's 129 micro Teslas
-
now it can still measure some magnetism
-
don't forget the Earth is magnetic and
-
there are other things probably in my
-
house that are magnetic as well so the
-
microb bit is still picking up some
-
magnetic field so my number of 200
-
should work pretty well if it's more
-
than 200 it means the door is shut which
-
sounds likely cuz with the door shut I
-
had 453 micro Teslas if it's below 200
-
that probably means someone's open the
-
door in this case I know that when my
-
door is open I have 129 micro Teslas so
-
that should work okay now I should be
-
able to tell when someone open my door
-
an angry face will appear on my microbit
-
display and I'll know that somebody has
-
been in my room there are lots of things
-
you could do to this project to augment
-
it you could perhaps add a delay to give
-
yourself some time to get out the room
-
remember if you need to reset it you can
-
just press button a to show the magnetic
-
force again and that will clear the
-
angry face off the display on your
-
microbit uh maybe you could add an
-
audible alarm as well you could add a
-
music block so that when somebody opens
-
your door it makes an audible sound to
-
warn you that somebody has been inside
-
your room there are all sorts of ways
-
you could modify this
-
project