Use Raspberry Pi to make human body sensor monitor

Reprint please indicate the source, thank you.

equipment:

Raspberry Pi 3B 1 set

CPI interface camera 1

HC-SR501 infrared human body sensor module 1

3 male to female Dupont wires

first step:

Install the camera on the Raspberry Pi. To enable the camera on the Raspberry Pi:

input the command:

sudo raspi-config

Then select the camera and set it to enable, and restart the Raspberry Pi.

Step two:

Plug the infrared human body sensor module into the DuPont line, there are three GPIO pins in total, the middle one is the signal line, and the left and right sides are 5V power input and GRAND respectively.

Note that when the 5V power input and GRAND are inserted into the GPIO pins of the Raspberry Pi, do not insert them wrongly! Otherwise the original may be burned. I inserted it backwards before and burned a temperature sensor

The pin on the left in the figure is positive, the pin on the right is negative, and the pin in the middle is the signal pin

The middle signal line can be plugged into any signal pin on the board

The distance and sensitivity valve can be adjusted according to your actual situation, and you don't need a screwdriver at all, you can turn it with your fingernails. The distance and sensitivity in the figure are both the maximum state

In addition, this component has two modes L and H:

L mode is non-repeatable trigger. When a human body is detected, it will output a high level and keep for a period of time to return to a low level. During this period, if a human body is still detected, the high level time will not be extended. Wait until the low-level blocking time (the previous default is 2.5S) has passed before starting to detect again.

The H mode can be triggered repeatedly. If the human body is always sensed, it will always output a high level until the human body is not detected, it will remain for a short time and then return to a low level.

This is the H mode in the picture.

third step:

Finally started to write code, the language used here is Python

import RPi.GPIO as GPIO
import time
import picamera

#初始化
def init():
    #设置不显示警告
    GPIO.setwarnings(False)
    #设置读取面板针脚模式
    GPIO.setmode(GPIO.BOARD)
    #设置读取针脚标号
    GPIO.setup(12,GPIO.IN)
    pass
 
def detct():
    while True:
    	curtime = time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time()))
        #当高电平信号输入时报警
        if GPIO.input(12) == True:
        	alart(curtime)
        else:
            continue
        time.sleep(3)

def alart(curtime):
    print curtime + " Someone is coming!"
    #根据时间获取图像
    camera.capture(curtime + '.jpg')

#声明摄像头
camera = picamera.PiCamera()

time.sleep(2)

init()
detct()
GPIO.cleanup()

Step 4: Execute the code

python xxx.py

This is basically done, the last step left is how to pose

Guess you like

Origin blog.csdn.net/u013772433/article/details/72468721