Skip to main content

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:

  1. Learn about the human infrared sensor.

  2. Learn about the light sensor.

  3. Learn about the human infrared sensor and light sensor programming blocks in MakeCode.


Materials required:

ItemPictureQuantity
micro:bit V21
Jacdac Expansion board1
Jacdac 10cm Connection Wire2
Human infrared sensor1
Light Sensor1
USB Cable1

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

Microsoft Makecode


Makecode programming

Step 1: How to add Jacdac extension

  1. Enter Microsoft Makecode and click "New Project".

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


  1. Click "Extend" in the code drawer.

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


Step 2:

  1. 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.

  1. 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.

  1. 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

---

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?