Intruder Detection

Are your friends constantly sneaking into your dorm room to eat your snacks? You need better friends! Wait, no, you need this intruder detection micro:bit project!

This tutorial was contributed by Luo Beiyu from the National University of Singapore.

Step 0 – Pre-build Overview

In this project, we are going to create an intruder detection system which will sound when someone opens the door. The status of the house will be displayed on the OLED.

MATERIALS: 1 x BBC micro:bit, 1 x Micro USB cable, 1 x Breakout board, 1 x Crash Sensor, 1 x OLED, 1 x Buzzer, 2 x Female-Female jumper wires


  • Get to know the Crash Sensor, OLED and Buzzer
  • Make something with a OLED
  • Make something with a Crash Sensor

Step 1 – Components

Insert the micro:bit into the Breakout Board and plug in the micro USB cable, then connect the buzzer using the jumper cables. The positive (usually longer) pin on the Buzzer will connect to the yellow pin on the breakout board, while the negative (usually shorter) one connects to the black pin. Plug the other end of the jumper wires to Pin 0.
Plug in the OLED as shown in the picture above. You should be able to plug it into any of the three rows.
Plug in the crash sensor to Pin 1. Make sure the colour of the wire follows the coloured pins on the break out board.

Step 2 – Pre-coding

We’ll need to add a package of code to be able to use our kit components. Click on Advanced in the Code drawer to see more code sections and look at the bottom of the Code Drawer for Add Package.
This will open up a dialog box. Do a search for tinkercademy or just tinker. Click on the search icon  or press enter, then click on tinkercademy-tinker-kit.

Note: If you get a warning telling you some packages will be removed because of incompatibility issues, either follow the prompts or create a new project in the Projects file menu.

Click on Tinkercademy or OLED inside the Code Drawer to find our custom blocks for the various components in your kit

Step 3 – Coding

You should always initialize the OLED at the begining. 64 and 128 represent the height and width of the OLED respectively.
Since there are only two conditions, we need only one ‘else-if’ statement.

When the Crash Sensor is triggered, the buzzer will sound and the OLED will display the message “Intruder Detected”. Or else, if there is no force is applied to the Crash Sensor, the buzzer will not sound and the OLED will display the message “The house is safe”.

Step 4 – Success!

Voilà! You have created a intruder detector!