Introduction: Micro:bit Experiment 12: Accelerometer —— Elecfreaks Mirco: Bit Starter Kit Course
Micro:bit has integrated multiple sensors including accelerometer. Today, we are going to use accelerometer to make an level device and display the inclination on NeoPixel ring in bar chart format.
Step 1: Step
1 x Micro:bit Board
1 x Micro-B USB Cable
Tips: If you want all components above, you may need Elecfreaks Micro:bit Starter Kit.
Micro:soft Makecode Online Editor
There is an accelerometer on your micro:bit which detects the speed change of micro:bit. It converts analog information into digital form that can be used in micro:bit programs. Output is in milli-g. The device will also detect a small number of standard actions, e.g. shake, tilt and free-fall.
The corresponding X, Y, Z axle direction of accelerometer are showed below:
Please complete hardware connection according to the picture below.
After connection, you will see:
Step 2: Programming
Open Microsoft Makecode, write your code in the edit area. I would like to suggest you program by yourself first.Of course, you can see the whole program in the link below. Just click "Edit" on the right top corner of the interface to edit your program, then click "Download" on the right bottom corner to download your code into micro:bit.
show bar graph
Display the value with bar chart format just similar to plot bar graph.
Get the acceleration value (milli g-force) in one of three dimensions, or the combined force in all directions (x, y, and z).
With the inclination of micro:bit, LED bead on 8 RGB Rainbow LED Ring gradually illuminated one by one. The bigger inclination angle, more LED bead will be illuminated.
In this case, we have judged the inclination of one direction(X axle) only. If we want to test the inclination of a flat surface( say XY flat surface), then how to design circuit and program. We look forward to your comments and further discussions with us.