50. Case 49: The PIR Railing#

50.1. Introduction#

When we enter some communities or companies, we will see that there are railings to stop the entry and exit of vehicles, but when we are about to walk in front of the railings, they will automatically rise again to let people enter, these applications are mostly using the human infrared sensor.

The human infrared sensor application is very wide, it can be used in shopping malls, hotels, scenic spots, and so on. Now let’s do a small project with the infrared sensor to understand how it helps to improve our living experiences.

../../_images/49_1.png

Materials Required#

Nezha expansion board × 1

micro:bit V2 × 1

PIR sensor × 1

RJ11 cable × 1

Bricks × n

Note: If you want all of the above components, you may purchase the Nezha 48 IN 1 Inventor’s Kit.

Assembly Steps#

Component Details

../../_images/49_8.png

Build it as the assembly steps suggest:

../../_images/49_2.png

../../_images/49_3.png

../../_images/49_4.png

../../_images/49_5.png

../../_images/49_6.png

../../_images/49_7.png

50.2. Connection Diagram#

Connect the PIR sensor to J1 and the servo to S1 as the picture indicates below.

../../_images/49_9.png

50.3. MakeCode Programming#

Step 1#

Click “Advanced” in the MakeCode drawer to see more choices.

../../_images/49_10.png

For programming the servo , We need to add a package. Click “Extensions” at the bottom of the drawer and search with “nezha” to download it.

../../_images/49_11.png

For programming the PIR sensor, we need to add a package. Search with “PlanetX” in the dialogue box and click to download it.

../../_images/49_12.png

Notice: If you met a tip indicating that some codebases would be deleted due to incompatibility, you may continue as the tips say or create a new project in the menu.

Reference#

../../_images/49_13.png

Link: https://makecode.microbit.org/#editor

You may also download it directly:

Result#

After powering on the NEZHA expansion board, if the PIR sensor detects the arrival of someone, the railing will be raised automatically and it will drop after a while.