Rich's Wordpress

又一个WordPress站点

PIR (Passive Infra-Red Sensor)

It is very common to use human body detecting sensors – the infrared sensors in indoor security applications. The principle is that the detection element will detect the infrared radiation of the human body, and convert it into a weak voltage signal, which is amplified and output. In order to improve the detection sensitivity of the detector to increase the detection distance, a plastic Fresnel lens is generally installed in front of the detector, which together with the amplifier circuit (The analogue amplifier boosts the strength of a signal. Amplification factors are often represented in terms of power. The most common way to quantify an amplifier’s gain is in decibels (dB), a logarithmic unit.) amplifies the signal by more than 70dB, so that the action of people within 5 to 10 meters can be measured.

Properties of the specific Passive Infra-red Sensor that I used:

Output signalThe output is the digital signal: if it detects the human body: a high level of 3.3 V will be output for 3-8 seconds. If it does not detect the human body a low level 0 V will be the output.
Detection angleabout 100°
Detection distanceabout 8 meters

How to control the sensor?

Use the MotionSensor module under the gpiozero library

gpiozero.MotionSensor(pin) # "pin" is the pin that the sensor is connected to

MotionSensor.when_motion # check if the infra-red sensor detected something

MotionSensor.when_no_motion # check if there is nothing around the infra-red sensor

Flowchart

Code

# Importing the MotionSensor module is to control and get information from the sensor
# Importing the LED module is to warn the people about the detected human
# Importing canvas and ssd1306 is for printing the imformation on the OLED
from gpiozero import MotionSensor, LED
from luma.core.render import canvas
from luma.oled.device import ssd1306

pir = MotionSensor(18)
LED_R = LED(4)
oled = ssd1306(port = 1, address = 0x3C)

# When a human is detected by the sensor, it will automatically turn the red light on and warn the people about it.
def detected():
	LED_R.on()
	print("Catch the thieve!")
	with canvas(oled) as draw:
		draw.text((0,0), "Catch the thieve!", fill = "White")

# When the danger is gone, it will turn off the red light and also indicate that the people are away.
def not_detected():
	LED_R.off()
	print("No one is there")
	with canvas(oled) as draw:
		draw.text((0,0), "No one is there", fill = "White")

pir.when_motion = detected
pir.when_no_motion = not_detected

while True:
	pass

Result

PIR (Passive Infra-Red Sensor)
Scroll to top