This project makes a useful leveler (spirit level ruler) by using the built-in accelerometer and LED screen on Micro:bit, it monitors the roll/pitch from accelerometer sensor, and visualize the leveling status by the moving dot on the LED screen. The challenge part adds dynamic warning sound for how much the levelling is reached, making the project more fun and practically useful. Goals:
Get to know roll/pitch concept, and accelerometer sensor
Coordinate of the LED matrix on Micro:bit
Concept and practice of "data scaling and mapping"
START A BIT > Projects Library > This page
Here is the demo of the basic requirement, please go to the Challenge chapter for the demo of challenging result.
This project uses 1 Micro:bit board with a USB cable, nothing else needed.
When powering up, the Micro:bit shows a dot on the LED screen, this dot indicates the level status, if the level is status is good, then the dot moves to the middle, otherwise, the dot moves to the direction that the level is lower.
[ ] Simple: 30-60 minutes
[x] Moderate: 1-2 hours
[ ] Challenging: more than 2 hours
The estimation bases on average situation without unexpected troubleshooting, assuming that the student meets prerequisites. It only indicates rough time needed to complete this project, but not about technical difficulty, not covering discussion and sharing time. Here is a possible breakdown:
5 minutes: Understand requirement and solution, collect materials
10-15 minutes: Task 1: Monitor Environment Sound Level
10-15 minutes: Task 2: Make a List of Images, Show a Specific Image by Button A/B
30-45 minutes: Task 3: Scale "Sound Level" Values to Map Valid Index of Array
The challenge topic is not included in effort estimation, it could take extra 45-60 minutes for that part.
One should have prior knowledge
Micro:bit V2 board: Know what they are, better to have prior experience with it
MakeCode by Microsoft, the programming tool, better to have prior experience using it with Micro:bit
1x Micro:bit V2 board , with USB cable
Micro:bit LED screen has 25 LED arranged in a 5x5 grid.
Use (x,y) coordinates to specify a particular LED, x is the horizontal position (0,1,2,3,4) y is the vertical position (0, 1, 2, 3, 4).
Use plot and unplot to turn a LED on or off, or toggle to flip the state.
More info here from MakeCode document (link)
Similar as "Sound Level", there are ready-made blocks to capture the roll/pitch level, the input is already converted from analog to digital values, ranged -180~180 degrees.
Use "Serial Write" to visualize the real time changing of roll/pitch input.
Adding a small delay helps slowing down a little bit of the data, so to observe clearer.
After "Downloading", click "Show data Device" to visualize the real time data.
Which direction makes changes of roll or pitch input?
Which exact way makes "-" or "+" values
Can you find out the boundary -180 or 180 positions?
Considering the final product we want to build, which angle range is the most interesting to catch?
Tips:
Remember to "unplot" before "plot", otherwise, "ghost trailing" bug happens
Remember to "round" the "map", so to get "whole number" for LED coordinate
Find out how it works in actual testing, how should we improve it?
Here is a prototype
As you have seen, using the full "-180~180" range as input for mapping make it not practically useful, the sensitivity is very dull.
Tips: The low/high ends of the input range matters, try to narrow them, test and find out
Does this work well? Why?
Does this work well? Why?
Constrain the input data (i.e. roll, pitch) to be a valid range to be mapped!
Here is a final working copy, if you need
Add a warning sound tipping how much we have reached the right levelling (middle dot)
Sound differently when reaching more and more levelled
It beeps more and more urgently (faster beeping) when the dot goes further away from the middle dot
It beeps less and less urgently (slower beeping) when the dot does closer and closer to the middle dot
It stops beeping when it finally reaches the middle dot
Enable/disable the beeping sound by pressing "Logo" button
Beat is the time duration in milliseconds, by changing the beat for play-rest looping, it creates a beeping speeding.
It's similar as PJ014: The Blinking Dot solution for blinking the LED.
This prototype looks more or less correct for the main need. Try it out and think about the remaining things to fix:
When reaching the middle dot (2.2), we want it to stop beeping, how to do this? Remember the "0Hz" issue in PJ014?
We need also an extra switch to enable/disable the warning sound by pressing "Logo"
Here is a final working copy, if you need
Make the dot blinking, and let it
blink faster when getting less levelled
blink slower when becoming more levelled
make it constant on (no blinking) when reaching right levelled (middle dot)
We don't provide any tips and hints for this part, please explore and try things out.
Stand in front of the class, share with your group what you have made, please cover important points
Tell what it is your product
Demonstrate how it works
Explain how it works
Share with your group about
What troubles you met
How you analyze
How you get help
How you solve it
What you have learnt
Find out working copy as a MakeCode shared project.