BBC micro:bit
PIR Motion Sensor


Passive Infrared Sensors (PIR) are commonly used in burglar alarm systems to detect the motion of humans. The one used here was a miniature PIR made by DFRobot.


These vary in size, range, detecting angle, reaction time and price. What most have in common is the 3 pin connection. You connect power, ground and a signal pin. you'll need to make sure that your sensor will work fine with 3V3.



The diagram shows a generic PIR. Your cables will be marked on the board that you are using. In this case, the red and black cables are power and ground - they are connected to 3V and GND. The signal cable is connected to pin 0.


This sensor is as easy to program as it is to wire up,

micro:bit Code

When the sensor is triggered, an exclamation mark is drawn to the matrix for 2 seconds. Then the screen is cleared until the sensor next detects motion.


  1. Do a better job of the burglar alarm than this example. Add some more action on the matrix or some serious buzzing, perhaps a siren.
  2. The sensor needs a wee while to reset itself after it has been triggered. Even with this, you can still use it as an input of human interface proportions in the right situation. Consider what this might be and find another way to use the sensor. If you have the Android app, you might get the sensor to trigger something on your phone or tablet.