Chapter 25 Infrared Motion Sensor

In this chapter, we will learn a widely used sensor, infrared motion sensor.

Project 25.1 Infrared Motion Detector with LED Indicator

In this project, we will make a motion detector, with the human body infrared pyroelectric sensors.

When someone is in close proximity to the motion detector, it will automatically light up and when there is no one close by, it will be out.

This infrared motion sensor can detect the infrared spectrum (heat signatures) emitted by living humans and animals.

Component List

ESP32-WROVER x1

Chapter01_00

GPIO Extension Board x1

Chapter01_01

Breadboard x1

Chapter01_02

LED x1

Chapter01_03

Resistor 220Ω x1

Chapter01_04

Jumper F/M x3

Jumper M/M x2

Chapter24_08

HC SR501

Chapter25_00

Component knowledge

The following is the diagram of the infrared Motion sensor(HC SR-501):

Top

Bottom

Schematic

Chapter25_00

Chapter25_01

Chapter25_02

Description:

Working voltage: 5v-20v(DC) Static current: 65uA.

Automatic Trigger. When a living body enters into the active area of sensor, the module will output high level (3.3V). When the body leaves the sensor’s active detection area, it will output high level lasting for time period T, then output low level(0V). Delay time T can be adjusted by the potentiometer R1.

According to the position of jumper cap, you can choose non-repeatable trigger mode or repeatable mode.

L: non-repeatable trigger mode. The module output high level after sensing a body, then when the delay time is over, the module will output low level. During high level time, the sensor no longer actively senses bodies.

H: repeatable trigger mode. The distinction from the L mode is that it can sense a body until that body leaves during the period of high level output. After this, it starts to time and output low level after delaying T time.

Induction block time: the induction will stay in block condition and does not induce external signal at lesser time intervals (less than delay time) after outputting high level or low level

Initialization time: the module needs about 1 minute to initialize after being powered ON. During this period, it will alternately output high or low level.

One characteristic of this sensor is when a body moves close to or moves away from the sensor’s dome edge, the sensor will work at high sensitivity. When a body moves close to or moves away from the sensor’s dome in a vertical direction, the sensor cannot detect well (please take note of this deficiency). Note: The sensing range (distance before a body is detected) is adjusted by the potentiometer.

We can regard this sensor as a simple inductive switch when in use.

Circuit

Schematic diagram

Chapter25_03

Hardware connection

If you need any support, please feel free to contact us via: support@freenove.com

Chapter25_04

Code

In this project, we will use an infrared motion sensor to trigger an LED, essentially using the infrared motion sensor as a motion switch. So the code of this project is similar to that of project “Button & Led”. The difference is when infrared motion sensor detects changes, it will out high level; when it detects nothing, it will output low level. When the sensor outputs high level, LED turns ON; Otherwise, LED turns OFF.

Move the program folder “ Freenove_Ultimate_Starter_Kit_for_ESP32/Python/Python_Codes “ to disk(D) in advance with the path of “D:/Micropython_Codes”.

Open “Thonny”, click “This computer” -> “D:” -> “Micropython_Codes” -> “25.1_Infrared_Motion_Detector” and then double click “Infrared_Motion_Detector.py”.

25.1_Infrared_Motion_Detector

../../../_images/Chapter25_08.png

Click “Run current script”. Put the sensor on a stationary table and wait for about a minute. Then try to move away from or move closer to the Infrared Motion Sensor and observe whether the LED turns ON or OFF automatically.

Move to the Infrared Motion Sensor

Chapter25_06

Move away from the Infrared Motion Sensor

Chapter25_07

Chapter25_01

R1 is used to adjust the delay time. When rotated counterclockwise,

when the sensor recognizes the person, the output high level time will

be shorter, the shortest is about 0.5 seconds. When rotated clockwise,

when the sensor recognizes a person, the output high level will be longer,

up to about 300 seconds.

R2 is used to adjust the sensor sensing distance. When rotated

counterclockwise, when the sensor sensing distance will be shortened,

the nearest is about 3 meters. When rotated clockwise, the sensor sensing

distance will become far away, the farthest is about 7 meters.

When H is selected on the right, when the sensor senses a person,

it will always sense whether there is a person, and output a high level,

until no person is sensed for a period of time, it will output a low level

When L is selected on the right, when the sensor senses a person,

it no longer continues to sense whether the person exists, directly

outputs a high level for a period of time, and then outputs a low level.