Night Safety Light
Living in Canada year round, we all know what’s like in the winter. Sun goes down by 4-5pm. The street can be dark and slippery. Can we make a wearable device with Microbit to help us be safe in the dark?
Identify what features do you want?
- Flashing LED when it’s dark.
- Have an on/off button to save power
- Only turn on when walking?
- Display sensor measurement on button pressed?
Features on the Microbit
- Light sensor, range 0 to 255. 0 is complete dark. 255 is super bright.
- Acceleronmeter, tell us if we are moving.
- Buttons, to navigate among features, or turn on/off LED. Typical uses:
- When button A is pressed
- When button B is pressed
- When button A+B are pressed together
Let’s know the sensors
LEDs, Light Emitting Diode
LEDs has become very common in our household. Usually the LEDs we saw are light bulb, like this one
On Microbit they look like these:
Here is short video introduing LEDs by Microbit. YouTube Microbit LEDs
- LEDs are small, effecient, bright, and don’t require much power
- LEDs lights up when a one way electrical current pass through it
- When we stop the electrical current, it takes time for the light to go away
- This time is related to strength of ambient light
- Microbit measure the time it takes for the LEDs to go out, and use that to estimate ambient light.
Here is another YouTube video that talks about using LED as light sensor. Have a look if you want to know more. They also shows a nice demonstration. Sparkfun using LED as light sensor
Design our program with flowchart
Before we start writing our code, we should first design our program. Creating a flow chart helps us to reduce bugs in our program, and also make it easier to spot them. We will do this step together in class.
Here are the basic element of flowchart
Below is an example of a simple flow chart
Build our code based on the flowchart design
In this project, I’ll ask you to use the While True
block, instead of the built in Forever
block, in order to practice our logical thinking. Here are some of the blocks:
-
While True Loop. Grap a
while True...do...
block from theLoops
classBlock Python -
For decision block, ie.
if...else...
. Grab anif...else...
block fromLogic
classNotice that you can expand or shink the
if...else...
with the+
or-
sign. You can also findBlock Python -
To read estimated ambient light level, use the
light level
block fromInput
classBlock Python -
If you want to add a button to your program, use
button (A) is pressed
block from theInput
classBlock Python Expand your
if...else...
block to include button feature.
Finishing Up
- Find a way to put Microbit on your backpack, or wear it on your wrist.
- Make a short video to demonstrate your work.
- Present the problem we are trying to solve
- What the solution is.
Here are some ideas to make microbit wearable.