New programming concept
Sensor
A sensor helps a computer notice something in the physical world. The micro:bit’s accelerometer senses movement, including a shake.
physical action→Accelerometer
sensor input→Shake event
program reacts
Connection: A sensor supplies an input. The shake is still an event, just like a button press.
Try it here
Trigger the shake event
Waiting for movement.
MakeCode steps
Add movement to the badge
- 1
- 2
Add a gesture event
Open Input. Add on shake to the workspace.
- 3
Choose the output
Inside on shake, add show icon and choose the silly face.
- 4
Test three inputs
Press A, press B, then shake the simulator. Each input should have its own output.
- 5
Transfer and move safely
Download to the board. Hold it securely and use a gentle shake away from other people and objects.
Cannot or prefer not to shake?
Use the simulator’s shake control, tilt the board gently, or let a partner activate the sensor. The coding goal is understanding the input—not performing a particular movement.
For the teacher
A calm 55-minute plan
Recall
Button A is an input. What was the output?
Introduce sensors
Compare phone rotation with micro:bit movement.
Add on shake
Keep the two button events unchanged.
Test three inputs
Use A, B, and shake in order.
Explain
Name sensor input, event, and output.
Before you finish