I recently purchased a PIR Detector HV-SR501 and here is a simple program to use it in Python with a Raspberry Pi 3.
Let's look at the wiring:
CAUTION: Verify on the PIR sensor's board that it has to be wired as displayed, the pinout on the PIR sensor is, on some models, inverted compared to the picture.
Once wired, below is a Python program that reads from the Raspberry Pi 3's GPIO ping #11 and prints every second if a movement has been detected.
import RPi.GPIO as GPIO
import time GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.IN) while True: i=GPIO.input(11) if i==0: print time.ctime(),": no mouvement detected" else: print time.ctime(),": !!!!!!!!!! mouvement detected !!!!!!!!!!" time.sleep(1) You can change the two resistances on the other side of the PIR sensor using a screw driver to vary the delay and sensibility of the sensor.
7 Comments
|
Archives
July 2021
Categories
All
|