Passive Infrared Sensor with micro:bit
Written By: Cherie Tan
![](https://cdn.shopify.com/s/files/1/0829/7493/3281/files/pir_sensor_with_microbit_guide_image.001.jpg?v=1722994346)
![Dash icon](https://fast.littlebird.com.au/static/guides/dash.webp)
Difficulty
Easy
![Steps icon](https://fast.littlebird.com.au/static/guides/steps.webp)
Steps
8
A passive infrared (PIR) sensor measures infrared light radiating from objects in its view. These sensors collect incident infrared radiation with the use of a Fresnel lens, on a pyroelectric sensor and can detect human movement as long as it is within the range of the sensor. In this guide, learn to connect a PIR motion sensor to the micro:bit. Then learn to program the micro:bit with the PIR motion sensor to display an alert message when such movement is detected. Complete this guide to start incorporating the PIR motion sensor in your micro:bit!
![](https://files.littlebird.com.au/guides/2456_img1.png)
![](https://files.littlebird.com.au/guides/2456_img2.png)
A PIR (passive infrared) sensor also known as an infrared motion sensor is an inexpensive, low-power and durable sensor used for the detection of movement within its range. It includes a pyroelectric sensor and a Fresnel lens. You can see the pyroelectric sensor under the lenses as a round metal can. The curved lenses concentrates infrared radiation toward the sensor. Through a changing voltage level, it detects changes in the infrared radiation level which is why it is commonly used to detect whether a human has moved in or out of its range. There are three pins on the sensor: From left to right as shown: VCC - Voltage common collector DO - Digital output GND - Ground
![](https://files.littlebird.com.au/guides/2457_img1.png)
First, connect a red jumper wire to the VCC pin found on the PIR motion sensor.
![](https://files.littlebird.com.au/guides/2458_img1.png)
Connect another jumper wire this time to the DO pin found on the PIR motion sensor.
![](https://files.littlebird.com.au/guides/2459_img1.png)
Now, connect a black jumper wire to GND on the PIR motion sensor.
![](https://files.littlebird.com.au/guides/2461_img1.jpeg)
Connect a red jumper from VCC of the PIR Motion Sensor to 3.3V of the micro:bit
basic.forever(function () { if (pins.digitalReadPin(DigitalPin.P0) == 1) { basic.showIcon(IconNames.Happy) } else { basic.showIcon(IconNames.Angry) } })
Upload the following code into the Javascript panel of the MakeCode editor. To view it in blocks, simply click the Blocks button found on the top of the editor!