Lesson 12 Accelerometer

Introduction

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.

What you need

  • micro:bit board
  • Micro USB Cable
  • micro:bit breadboard adaptor
  • Breadboard
  • 8 RGB LED NeoPixel Ring
  • Male to male jumper wires

Accelerometer

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:

Hardware Connection

Please complete hardware connection according to the picture below.

After connection, you will see:

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 download the whole program from the link below.

https://makecode.microbit.org/_R2yHPUecyh2i

Code Explanation

show bar graph
Displays the value with bar chart format just similar to plot bar graph.

Acceleration
Get the acceleration value (milli g-force) in one of three dimensions, or the combined force in all directions (x, y, and z).

Results

With the inclination of micro:bit, LED on the Rainbow ring will gradually illuminate one by one. The bigger inclination angle, more LED beads will be illuminated.

Taking it further

In this case, we have judged the inclination of one direction(X axes) only. If we want to test the inclination of a flat surface( say XY flat surface), then how would you design the circuit and write the program?

micro:bit Starter Kit Lessons

  • Lesson 01 – LED
  • Lesson 02 – Button
  • Lesson 03 – Trimpot
  • Lesson 04 – Photocell
  • Lesson 05 – RGB LED
  • Lesson 06 – Self-lock Switch
  • Lesson 07 – Temperature Sensor
  • Lesson 08 – Servo
  • Lesson 09 – Buzzer
  • Lesson 10 – Motor
  • Lesson 11 – Rainbow LED
  • Lesson 12 – Accelerometer
  • Lesson 13 – Compass
  • Lesson 14 – Ambient Light

 

First published at 4:22pm on July 9, 2019
Last updated at 4:22pm on July 9, 2019