3.3 PIR Motion Sensor

3.3.1 Overview

The PIR motion sensor adopts RE200B-P element.

Based on pyroelectric effect, the sensor is able to detect the infrared ray emitted by human body or animal. With Fresnel lens, it can even detect farther and wider. When a nearby human or animal motion is detected, the sensor outputs a high level.

3.3.2 Schematic Diagram

6-3

Working principle: The human body maintains at 37 degrees, so it will emit a specific wavelength of about 10μm infrared. The sensor captures 10μM infrared to determine whether there is a motion.

3.3.3 Code Blocks

  1. j15

    This block reads PIR motion sensor value. If there is a human motion, it outputs 1; otherwise, it outputs 0.

  2. j16

    This block determines whether a condition is satisfied. If yes, code in “if” will be executed. Or else, code in “else” will be executed.

3.3.4 Test Code

3.3.4.1 Build Code

There are two ways to upload the code: directly open the code file we provide; or manually build blocks.

Directly open the code file we provide:

  1. Click and choose Load from your computer

  1. We have already downloaded the codes on computer desktop, so open the file and choose 3-3-pir.sb3

Manually build blocks:

  1. In events, find j1 block.

  2. In serial, find j12 block and set baud rate to 9600, and put it under j1.

  3. In control, drag j2.

    6-4-4-1-1

6-4-4-1-2

  1. In control, drag j16 into j2.

6-3

  1. In pir, find and put j15 into the condition box of j16.

    Add the following block under “if”: 6-3 prints “Someone!”; Add the following block under “else”: 6-3 prints “No one!”

Complete Test Code

6-3

3.3.4.2 Test Result

After uploading code, when human motion is detected, the monitor prints “Someone!”; If not, it shows “No one!” (Note that click 6-2 to set the baud rate before uploading code to avoid garbled words.)

6-3