Use PIR motion sensor with raspberry Pi

Overview

Programmatically get dynamics detected / not detected from RaspberryPi2 and PIR Motion Sensor.

Premise

--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. ``

Preparation

pip3 installation

sudo apt install python3-distutils
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py

Installation of RPi.GPIO

sudo apt install python3-dev
pip3 install RPi.GPIO

Connection of sensor and raspberry Pi

Refer to the following GPIO PIN Assignment Obtained from Official Connect with a jumper wire as shown below. スクリーンショット 2020-06-28 21.27.06.png

--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 IMG_20200628_213324.jpg

rasqberryPi side IMG_20200628_213316.jpg

Get the value with the sensor

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

Use PIR motion sensor with raspberry Pi
Improved motion sensor made with Raspberry Pi
Use vl53l0x with Raspberry Pi (python)
Use the Grove sensor on the Raspberry Pi
GPGPU with Raspberry Pi
DigitalSignage with Raspberry Pi
Use Majoca Iris elongated LCD with Raspberry Pi
Use Grove-Temperature & Humidity Sensor (DHT11) on Raspberry Pi
A memo to simply use the illuminance sensor TSL2561 with Raspberry Pi 2
Mutter plants with Raspberry Pi
Using the digital illuminance sensor TSL2561 with Raspberry Pi
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
[For beginners] I made a motion sensor with Raspberry Pi and notified LINE!
Use NeoPixel on Raspberry Pi
Check! Get sensor data via Bluetooth with Raspberry Pi ~ Preparation
I tried using the DS18B20 temperature sensor with Raspberry Pi
[Raspberry Pi] Stepping motor control with Raspberry Pi
Servo motor control with Raspberry Pi
Serial communication with Raspberry Pi + PySerial
OS setup with Raspberry Pi Imager
Play with PIR sensor module [DSUN-PIR]
Try L Chika with raspberry pi
Detects people with motion sensor module
Try moving 3 servos with Raspberry Pi
Using a webcam with Raspberry Pi
Periodically log the value of Omron environment sensor with Raspberry Pi
Measure SIM signal strength with Raspberry Pi
Pet monitoring with Rekognition and Raspberry pi
Hello World with Raspberry Pi + Minecraft Pi Edition
Get BITCOIN LTP information with Raspberry PI
Try fishing for smelt with Raspberry Pi
Try Object detection with Raspberry Pi 4 + Coral
Power SG-90 servo motor with raspberry pi
Working with sensors on Mathematica on Raspberry Pi
Make a wash-drying timer with a Raspberry Pi
Infer Custom Vision model with Raspberry Pi
Operate an oscilloscope with a Raspberry Pi
Create a car meter with raspberry pi
Inkbird IBS-TH1 value logged with Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
Use BME280 temperature / humidity / barometric pressure sensor from Python on Raspberry Pi 2
Note: I want to do home automation with Home Assistant + Raspberry Pi + sensor # 1
Use python on Raspberry Pi 3 to light the LED with switch control!
Get GrovePi + sensor value with Raspberry Pi and store it in kintone
Logging the value of Omron environment sensor with Raspberry Pi (USB type)
Media programming with Raspberry Pi (preparation for audio)
I tweeted the illuminance of the room with Raspberry Pi, Arduino and optical sensor
I tried L-Chika with Raspberry Pi 4 (Python edition)
Raspberry Pi backup
Enjoy electronic work with GPIO on Raspberry Pi
Power on / off your PC with raspberry pi
CSV output of pulse data with Raspberry Pi (CSV output)
Observe the Geminids meteor shower with Raspberry Pi 4
Get CPU information of Raspberry Pi with Python
Raspberry + am2302 Measure temperature and humidity with temperature and humidity sensor
Get temperature and humidity with DHT11 and Raspberry Pi
Stock investment analysis app made with Raspberry Pi
Logging Inkbird IBS-TH1 mini values with Raspberry Pi
Try to use up the Raspberry Pi 2's 4-core CPU with Parallel Python
Connect to MySQL with Python on Raspberry Pi
Use Raspberry Pi Python to TMP36 analog temperature sensor and MCP3008 AD converter