Skip to content
12micro:bit · MakeCode 25 minutes

Tilt alarm

A ball tilt switch on P1 with debounce.

Tilt alarm project
Illustration of the finished idea. Build from the diagram and connection table, not the photo.

Lesson goal: Read a two-leg ball tilt switch between P1 and GND with a pull-up, debounce it, and light P0 when tilted.

Open MakeCode

Section 1

Understand

  • tilt switch
  • contact chatter
  • debounce
  • state change
  • 1A ball tilt switch between P1 and GND, with pull-up.
  • 2Tilted one way it closes; the LED lights.
  • 3A short debounce stops chattering.

Safety first

  • Unplug the USB cable before you add, move or remove any wire. Plug back in only after an adult or you have re-checked every connection against the table.
  • micro:bit pins are 3 V logic. Never connect 5 V, a battery pack or anything from a 5 V supply to any ring, port or the 3V ring.