Skip to content » Microbit Unit Home » Microbit Accelerometer Tutorial

Microbit Accelerometer Tutorial

Microbit accelerometer tutorial

In this tutorial we will be looking at how you can use the Microbit’s on-board accelerometer to control your Microbit, so that you can complete the challenges and use your learning when creating projects such as the Truth or Dare game or the radio controlled car.

What is an accelerometer?

An accelerometer is an electro-mechanical device that measures acceleration forces. These forces may be static, like the constant force of gravity pulling at your feet, or they could be dynamic. The are caused by moving or vibrating the accelerometer.

Source : dimension engineering


What are accelerometers used for?

  • Detecting seismic activity ( detecting  earthquakes, predicting eruptions)
  • Ship autopilots
  • Space shuttle navigation
  • Drone stabilisation
  • Camera anti-blur stabilisation
  • Car airbag crash detection

How can we use the BBC Microbit accelerometer in our projects?

  • Detecting shaking events
  • Detecting acceleration events
  • Detecting tilting

BBC Microbit shake sensor

 Microbit accelerometer tutorial - onShake block

The onShake function is triggered whenever the Microbit is shaken.


BBC Microbit tilt sensor ( left/right)


tilting microbit X axis

The X Axis tilt returns a value from 0(right) to 4(left)

Code example

tilt code example x axis

BBC Microbit tilt sensor (forward/backward)

Microbit accelerometer tutorial - tilty

Microbit accelerometer tutorial - The Y Axis tilt returns a value from 0(forward) to 4(backwards)

The Y Axis tilt returns a value from 0(forward) to 4(backwards)

Code example
Microbit accelerometer tutorial

Click to enlarge

Challenge 19 - Shake a smile

Create a program that every time you shake the Microbit, it displays a smiley  face!

Challenge 20 - Magic 8 Ball

Create a program that every time you shake the Microbit, it gives you a random piece of advice.

Challenge 21 - Left/ Right Tilting Microbit

Create a program that tells you if your Microbit is tilting to the left or right

Challenge 22 - Left/Right tilting dot

Create a program where the Microbit displays how far left or right it has been tilted by displaying a dot on the screen.

Challenge 23 - Microbit XY Tilting

Create a program which displays an arrow indicating which direction the Microbit is tilting at that moment.

Challenge 24 - Dot Matrix tilting

Create a program the uses a dot on the LED diplay matrix to indicate what direction the Microbit is tilting towards.