Case 4: Smart Night Light
Introduction:
When the human infrared sensor detects a pedestrian passing by and the light sensor detects that the ambient light intensity is less than 5%, the micro:bit displays a "heart".
Case Purpose:
Learn about the human infrared sensor.
Learn about the light sensor.
Learn about the human infrared sensor and light sensor programming blocks in MakeCode.
Materials required:
| Item | Picture | Quantity |
|---|---|---|
| micro:bit V2 | ![]() | 1 |
| Jacdac Expansion board | ![]() | 1 |
| Jacdac 10cm Connection Wire | ![]() | 2 |
| Human infrared sensor | ![]() | 1 |
| Light Sensor | ![]() | 1 |
| USB Cable | ![]() | 1 |
Sensor principle description:

Principle description
Photosensitive sensor: a sensor used to detect the intensity of ambient light.

Principle description:
Human infrared sensor: a sensor that senses human movement.
Connection diagram
As shown in the figure below, insert the micro:bit into the Jacdac expansion board, and use the connecting wire to connect the light sensor and the human infrared sensor to the gold finger interface of the Jacdac expansion board in a daisy chain manner.

Programming software
Makecode programming
Step 1: How to add Jacdac extension
- Enter Microsoft Makecode and click "New Project".

- In the pop-up window, enter a project name and click Create.

- Click "Extend" in the code drawer.

- In the pop-up interface, enter "Jacdac" and click the search icon, select the Jacdac software library, as shown in the figure.

Step 2:
- Connect micro:bit to the computer with a data cable.
Note: If the micro:bit is running the Jacdac program for the first time, please pre-install a blank Jacdac program on the motherboard, otherwise skip this step.

- Connect the sensor, MakeCode will automatically identify and simulate it, and the sensor will provide real-time feedback of the sensor status in the simulation area.

Click on "ADD BLOCKS" sensor expansion module.
Note: To connect a new sensor, repeat the "Click on "ADD BLOCKS" sensor expansion module" operation process.

Write the program as shown
---
Reference program link:
https://makecode.microbit.org/_RVtWqVD92ik5
You can also download the program directly from the following website, and start running the program after downloading.
Result
The human infrared sensor detects a pedestrian passing by, and the light sensor detects that the ambient light intensity is less than 5%, and the micro:bit displays "heart".

Thinking
In addition to the case in this lesson, are there other programming methods to achieve the same function?
.png)




