At Lancaster University I've been working on an energy project for schools.
Here's one of the experiments the students can reproduce using a micro:bit and a magnet.
1 x micro:bit
1 x battery pack with batteries
1 x magnet
Code the micro:bit before sticking everything to the door.
Find your range
The micro:bit can measure magnetic force strength. We need to know
- the magnetic force strength when the magnet is next to the micro:bit?
- the magnetic force strength when the magnet is as far away as the door opened
- Use this code and put the magnet next to the micro:bit.
- From Basic drag out "show number 0" and place it under forever
- From Input > More drag out "magnet force x" and place it on top of 0
- Change x to stength
When you download the code, the micro:bit will calibrate itself by asking you to draw a circle. Tilt the micro:bit around until you've drawn a circle using the lights on the front.
- Write down the number. Wait and check a few times until the number is consistent.
- Move the magnet away from the micro:bit.
- Record the number. Wait and check a few times until the number is consistent.
When the magnet was away from my micro:bit, the value was 40. Sometimes it was 39, 38. So here's my code to record the number of times a door is opened:
Instructions on how to recreate the code:
- From logic drag out "if else"
- From logic drag out "0 < 0" and drop it onto the if statement
- From input > more drag out "magnet force x" and drop it onto the first 0
- Change x to stength
- Change the second 0 to your magnet number
- From basic drag out a icon to indicate the door has been opened
- In the Variable menu create a new variable called doorOpened
- From Variables drag out "change item by 1"
- Change item to "doorOpened"
- From Basic drag out "show number 0"
- From Variables drag out "doorOpened" and drop it on the 0
I paused the micro:bit for 5 seconds (5000 milliseconds) to allow the door to close before recording another door open. How long does it take for your door to close? How often do people keep the door open for?
- From basic drag out "pause (ms) 100"
- Change 100 to the number of milliseconds it takes your door to close
- Find a door that when opened decreases the temperature of the room
- Cellotape the magnet to the edge of the door where it opens
- Cellotape the micro:bit to the door frame
- Plug in the battery
- Open the door to test it's working
This experiment was used with others to try and help schools save money. A student would record the number of times the door was opened each day and reset it to start recording the next day. They would display the information each day and try to change behaviours so the door wouldn't be opened as much.