Human Body Infrared Sensor
The human body infrared sensing module uses a pyroelectric infrared sensor. It uses the characteristics of temperature changes to detect infrared radiation, and uses the dual-sensitive-element complementary method to suppress interference caused by temperature changes, improving the working stability of the sensor. The product is widely used, for example: safety devices, anti-theft alarms, induction doors, automatic lamps, smart toys, etc.
Module Source
Purchase link: https://item.taobao.com/item.htm?spm=a1z10.3-c-s.w4002-19589090137.18.2b9836b4sjtBQL&id=608680529121 Materials download link: https://pan.baidu.com/s/1Bu0DL-1quXvY1Ede4c9ELw Extraction code: 8888
Specifications
Operating voltage: 4.5~20V Operating current: <50uA Level output: high 3.3V / low 0V Sensing angle: <100 degree cone angle Output method: GPIO Number of pins: 3 Pin
View Materials
- Fully automatic sensing: when a person enters its sensing range, it outputs a high level; when a person leaves the sensing range, it automatically delays closing the high level and outputs a low level;
- Two trigger modes: (selectable via jumper)
Non-repeatable trigger mode: After sensing and outputting a high level, once the delay period ends, the output will automatically change from high level to low level;
Repeatable trigger mode: After sensing and outputting a high level, if there is human activity within its sensing range during the delay period, the output will remain high until the person leaves, after which it will delay changing the high level to low level.
HC-SR501 Human Body Sensing Module Instructions
- After the sensing module is powered on, there is about one minute of initialization time. During this period, the module will output 0-3 times at intervals, and it enters standby mode after one minute.
- Avoid interference sources such as lights directly shining on the lens on the surface of the module at close range, so as to avoid introducing interference signals that cause false actions; avoid flowing wind as much as possible, as wind will also cause interference to the sensor.
- The sensing module uses a dual-element probe. The window of the probe is rectangular, and the dual elements (A element and B element) are located at both ends of the longer direction. When a human body walks from left to right or from right to left, the time and distance of the infrared spectrum reaching the dual elements are different; the larger the difference, the more sensitive the detection. When a human body walks toward the probe from the front, or from top to bottom, or from bottom to top, the dual elements cannot detect the change in infrared spectrum distance, so there is no difference, and therefore the sensing is insensitive or does not work. Therefore, when installing the sensor, the direction of the probe's dual elements should be as parallel as possible to the direction of the most human body activity, to ensure that the human body is sensed by the dual elements sequentially when passing through. To increase the sensing angle range, this module uses a circular lens, which also enables sensing on all four sides of the probe, but the sensing range on the left and right sides is still larger than that on the top and bottom directions.
Porting Process
Pin Selection
Port to Project
Our goal is to port the example to the ESP32-S3 dev board. Complete driver code has been provided for you. Follow the steps below to complete the porting. For detailed instructions on creating folders and new .c and .h files, refer to section 1.4.2 in the [DHT11 Temperature and Humidity Sensor] chapter; we will not repeat it here. However, here we change the file names bsp_dht11.c and bsp_dht11.h to bsp_HumanIR.c and bsp_HumanIR.h, and change the folder name to HumanIR.
Write Code
In the file bsp_HumanIR.c, write the following code.
/*
* LCSC-Openkits (LCKFB) software and hardware materials and related expansion board software and hardware materials are all open source on the official website.
* Dev board official website: www.lckfb.com
* Technical support resides on the forum; any technical questions are welcome for exchange and learning at any time.
* LCKFB Forum: club.szlcsc.com
* Follow our Bilibili account: [LCSC-Openkits (LCKFB)] to keep up with our latest updates!
* We do not make money by selling boards; we take cultivating engineers as our mission.
* Change Logs:
* Date Author Notes
* 2024-01-04 LCKFB-lp first version
*/
#include "bsp_HumanIR.h"
void delay_ms(unsigned int ms)
{
vTaskDelay(ms / portTICK_PERIOD_MS);
}
/******************************************************************
* Function Name: HumanIR_Init
* Function Description: Human body infrared module initialization
* Function Parameters: none
* Function Return: none
* Author: LC
* Notes: none
******************************************************************/
void HumanIR_Init(void)
{
gpio_config_t lll_config = {
.pin_bit_mask = (1ULL<<HUMANIR_PIN), // Configure pin
.mode =GPIO_MODE_INPUT, // Input mode
.pull_up_en = GPIO_PULLUP_DISABLE, // Disable pull-up
.pull_down_en = GPIO_PULLDOWN_DISABLE, // Disable pull-down
.intr_type = GPIO_INTR_DISABLE // Disable pin interrupt
};
gpio_config(&lll_config);
}
/******************************************************************
* Function Name: Get_HumanIR
* Function Description: Get the level status of the human body infrared output pin
* Function Parameters: none
* Function Return: 0=human body infrared detected 1=no human body infrared detected
* Author: LC
* Notes: none
******************************************************************/
char Get_HumanIR(void)
{
return ( gpio_get_level(HUMANIR_PIN) ? 1 : 0 );
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
In the file bsp_HumanIR.h, write the following code.
/*
* LCSC-Openkits (LCKFB) software and hardware materials and related expansion board software and hardware materials are all open source on the official website.
* Dev board official website: www.lckfb.com
* Technical support resides on the forum; any technical questions are welcome for exchange and learning at any time.
* LCKFB Forum: club.szlcsc.com
* Follow our Bilibili account: [LCSC-Openkits (LCKFB)] to keep up with our latest updates!
* We do not make money by selling boards; we take cultivating engineers as our mission.
* Change Logs:
* Date Author Notes
* 2024-01-04 LCKFB-lp first version
*/
#ifndef _BSP_HUMANIR_H_
#define _BSP_HUMANIR_H_
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "freertos/queue.h"
#include <inttypes.h>
#include "sdkconfig.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "rom/ets_sys.h"
#include "esp_system.h"
#include "driver/gpio.h"
#define HUMANIR_PIN 1
void delay_ms(unsigned int ms);
void HumanIR_Init(void);
char Get_HumanIR(void);
#endif2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Porting Verification
In the main function of your own project, write the following code.
/*
* LCSC-Openkits (LCKFB) software and hardware materials and related expansion board software and hardware materials are all open source on the official website.
* Dev board official website: www.lckfb.com
* Technical support resides on the forum; any technical questions are welcome for exchange and learning at any time.
* LCKFB Forum: club.szlcsc.com
* Follow our Bilibili account: [LCSC-Openkits (LCKFB)] to keep up with our latest updates!
* We do not make money by selling boards; we take cultivating engineers as our mission.
* Change Logs:
* Date Author Notes
* 2024-01-04 LCKFB-lp first version
*/
#include <stdio.h>
#include "HumanIR/bsp_HumanIR.h"
void app_main(void)
{
HumanIR_Init();
while(1)
{
printf("%d\r\n", Get_HumanIR() );
delay_ms(500);
}
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Power-on effect:
Driver code:
File Download
📌 Materials Download Center (click to jump)
📌 In the Materials Download Center -> Module Porting Materials Download, inside the compressed package of this chapter.