Project 3Sensors25 min
π On the Move! - Using the Accelerometer
Make your micro:bit notice when you shake it or tilt it.
Workshop projects (3 of 6)
The micro:bit has a super cool sensor that can tell when you move it! It's called an accelerometer, and in this project you'll learn to use it.
What is an accelerometer?
An accelerometer is like a magic sensor that can tell:
- If you shake the micro:bit
- If you tilt it left or right
- If you turn it upside down
- If you move it suddenly
It's the same sensor phones use to turn the screen around!
What are we going to do?
We're going to make a program that:
- When you shake the micro:bit: shows an X
- When you tilt it left: shows an arrow pointing left
- When you tilt it right: shows an arrow pointing right
- Normally: shows a normal face
Step 1: Create the project
- Create a new project called "Movement detector"
- First, let's show a normal face at the start
- This time we'll use "show icon" instead of "show leds"
In the "on start" block, add a "show icon" with this face:

Step 2: Notice when you shake the micro:bit
Let's do something fun when you shake the micro:bit!
- Go to the "Input" category (pink)
- Find the "on shake" block
- Drag it to the workspace
- Inside it, put a "show icon" with an X:

Step 3: Notice tilting to the left
Now let's make an arrow appear when you tilt the micro:bit.
- In "Input", find "on shake"
- Drag it to the workspace
- Change "shake" to "tilt left"
- Add a "show leds" with an arrow pointing left:

Step 4: Notice tilting to the right
The same for the right!
- Add an "on tilt right"
- Put in an arrow pointing right:

Step 5: Try your program!
- In the simulator, you can pretend to move it:
- Click "SHAKE" to pretend to shake it
- Move your mouse over the simulated micro:bit to tilt it

Let's make it better!
Add more movements
You can add more kinds of movement:
- "on screen up"
- "on screen down"
- "on free fall"
Add sounds
Give each movement its own sound!
- Go to "Music" and add "ring tone (Hz)" after each "show leds"
- Use different tones for each movement:
- Shake: high and fast tone
- Left/right: middle tones
- Normal: soft tone

Fun experiment: Digital dice
Let's make dice that roll when you shake the micro:bit!
- Change the "on shake" block
- Instead of showing an X, use "show number"
- Go to "Math" and find "pick random 1 to 6"
- Now every time you shake it, a number from 1 to 6 appears!

What have you learned?
- β What an accelerometer is and what it's for
- β How to detect different kinds of movement
- β The blocks: "on shake", "on tilt"
- β How to make a program that reacts to real movement
- β How to make digital dice
Common problems
π€ Shaking doesn't work?
- In the simulator, make sure you click "SHAKE"
- If you're using a real micro:bit, shake it harder (but carefully!)
π€ Tilting doesn't work well?
- Tilt the micro:bit more clearly to one side
- In the simulator, make sure the simulated micro:bit tilts to the right side.
Extra challenges
- Step counter: Make a number go up every time you shake it (like a pedometer)
- Movement alarm: Make an alarm sound when it detects movement
- Balance game: Show "Good!" only when it's completely flat
Ready for your next project?
Amazing! You've mastered the micro:bit's sensors. Now let's put everything you know together to make a super smart flashlight. Go to Project 4: Smart Flashlight.