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

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

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

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:
Click
and choose Load from your computer

We have already downloaded the codes on computer desktop, so open the file and choose
3-3-pir.sb3
Manually build blocks:
In
, find
block.In
, find
block and set baud rate to 9600, and put it under
.In
, drag
.

In
, drag
into
.

In
, find and put
into the condition box of
.Add the following block under “if”:
prints “Someone!”; Add the following block under “else”:
prints “No one!”
Complete Test Code

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
to set the baud rate before uploading code to avoid garbled words.)
