A learning resource fromSpread Robotics Education Foundation

Lesson 06 · 55 minutes · Motion sensor

Shake and get silly

Buttons are not the only inputs. The micro:bit can sense movement with a tiny sensor inside.

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.

Move the board
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

AB

Waiting for movement.

MakeCode steps

Add movement to the badge

  1. 1

    Open Emotion Badge

    Use your previous project or rebuild the A and B button events.

    Open MakeCode
  2. 2

    Add a gesture event

    Open Input. Add on shake to the workspace.

  3. 3

    Choose the output

    Inside on shake, add show icon and choose the silly face.

  4. 4

    Test three inputs

    Press A, press B, then shake the simulator. Each input should have its own output.

  5. 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

Can you explain it?