PIR Sensor (Motion Detection)
What you'll build¶
Build a simple motion alarm: when the PIR sensor sees movement, the buzzer sounds.
Wiring¶
| Part | Part pin | micro:bit pin |
|---|---|---|
| PIR sensor | OUT | P2 |
| PIR sensor | VCC | 3V |
| PIR sensor | GND | GND |
| Active buzzer | − | GND |
| Active buzzer | + | P1 |

Code¶
How it works¶
A PIR (passive infrared) sensor outputs 1 while it detects a moving warm body. pin2.read_digital() reads that,
and the buzzer on pin 1 mirrors it.
Try this next¶
- Show
Image.SURPRISEDon the display when motion is detected. - Count how many times motion was detected and scroll the total with button A.
- Send an alert to another micro:bit over radio.