Programmatically get dynamics detected / not detected from RaspberryPi2 and PIR Motion Sensor.
--The model of raspberryPi is raspberryPi2 modelB v1.1 --The motion sensor is PIR motion sensor --The language used is python3
Raspberry Pi OS (32-bit) Lite
Minimal image based on Debian Buster
Version:May 2020
Release date:2020-05-27
Kernel version:4.19
--The raspberry Pi is running. --Since there is always a moving object in the detection range, it is abnormal that there is no moving object. Assuming that the sensor is always detecting moving objects, It is a program that detects that the object is no longer detected (the object is stopped). ʻE.g. Detects a fan that is always running. ``
--The sensor cannot continue to detect moving objects. What is the detection timing of the sensor? It seems that there are cases where even if there is a moving object, it is not detected. Therefore, it is assumed that some action will be taken when no moving object is detected more than a certain number of times. ʻE.g. Detects the absence of moving objects 20 times or more. ``
sudo apt install python3-distutils
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
sudo apt install python3-dev
pip3 install RPi.GPIO
Refer to the following GPIO PIN Assignment Obtained from Official Connect with a jumper wire as shown below.
--Raspberry Pi No. 2 5V power and sensor VCC --GRD of raspberry Pi 6 ground and sensor --raspberry Pi 12 GPIO 18 and sensor out
Sensor side
rasqberryPi side
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
#Specify GPIO 18
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
count = 0
while True:
sleep(1)
#When the sensor detects a moving object, 1 is returned.
if GPIO.input(18) == 1:
count = 0
print("yes")
#If 1 is not returned and exceeds 20 times, yabeeeee is output.
else:
count += 1
print("no good")
if count > 20:
print("yabeeeee")
else:
pass
Recommended Posts