[PYTHON] Detects people with motion sensor module

Trigger

I "It would be interesting if there was a mechanism to move when people passed by" I "Human sensor sells quite cheaply"

What you have prepared

・ Raspberry Pi ·Human Sensor ・ Jumper wire ·bread board ·LED

The motion sensor looks like this

IMG_3180.jpg IMG_3179.jpg

It seems that the cover can be removed (I think it is better not to remove it too much) It was sold at Sengoku Densho in Akihabara for about 800 yen. (It may be cheaper on Amazon)

If you look at the manufacturer's site, the range in which the sensor responds is ・ 3-7m ・ 120 ° starting from the sensor (https://www.seeedstudio.com/PIR-Motion-Sensor-Large-Lens-version.html)

The back side looks like this IMG_3184.jpg When any movement is detected, the voltage of the OUT terminal becomes High. It may be interesting to input a signal with GPIO of Raspberry Pi etc. and use it as a trigger for something

procedure

Connect

Connect to LED and test if sensor works This time I did it directly without connecting a resistor properly (If you care, you may want to add a resistor)

human_sensor.png
Terminal color access point
Vcc Red 5 V voltage source
OUT yellow LED anode
GND black GND

When you actually illuminate the LED with the sensor signal, it looks like this (sorry for being confused) IMG_3194.jpg

Quite responsive
Next, connect to GPIO of Raspberry Pi This time connect like this

Terminal color access point
Vcc Red 5 V voltage source
OUT yellow GPIO 16
GND black GND

Program to detect the signal input by GPIO

Write a program in python that just detects the input state of GPIO

human-sensor.py


# -*- coding:utf-8 -*-
import time
import RPi.GPIO as GPIO

sensor_pin = 16

GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor_pin, GPIO.IN)


while True:
    if( GPIO.input(sensor_pin) == 0 ):
        print ("OFF")
    
    else:
        print("ON")
        
    time.sleep(1)

When I run the program ...

root@raspberrypi:/home/pi# python3 human-sensor.py 
ON
ON
OFF
OFF
OFF
OFF
OFF
ON
ON
OFF
ON
ON
ON
OFF
ON
ON
OFF
ON
ON

I was able to acquire the GPIO input value according to the detection of the motion sensor.
In the future, I would like to combine it with something to make something interesting.

Referenced site

・ Sensor manufacturer's site https://www.seeedstudio.com/PIR-Motion-Sensor-Large-Lens-version.html

Thank you very much

Recommended Posts

Detects people with motion sensor module
Play with PIR sensor module [DSUN-PIR]
Improved motion sensor made with Raspberry Pi
Use PIR motion sensor with raspberry Pi
Equation of motion with sympy
Play with ASE MD module