Overview
Generally speaking, motion sensor is made of thermoelectric sensor, and it can detect body motion. The motion sensor module generally uses the BISS0001 (“Micro Power PIR Motion Detector IC”) to convert the analog signal from the sensor to digital output.
Experimental principle of this project is that, when the detection of the human body motion, GPIO output get high level and light is on; else, GPIO output would get low level and LED would be off. In this project, Python Language will help us achieve this experiment. Enjoy Raspberry Pi Python programming tour with us.
Experimental photo
Experimental Parts
Raspberry Pi board | x1 |
Motion Sensor | x1 |
LED | x1 |
Jumper wire | centain amount |
breadboard | x1 |
1KΩ resistor | x1 |
T-type GPIO Extension Board40 Pin Ribbon Cable | optional |
Circuit Graph
Motion sensor Schematic
Motion sensor Interface Layout
The two potentiometer can adjust delay time and sensitivity, as the follow picture:
Software
(1)Before Python programming, Install GPIO library and Python library file in raspberry pi:
open terminal, update the apt-get software installation package list (Note: Network must be connected), and then enter installation command to install the raspberry gpio-python package.
Follow the next commands to complete installation, after entering each commands in terminal, press “enter” to complete:
a) update software list command: sudo apt-get update
b) install python command: sudo apt-get install python-dev
c) install python-pip command (python-pip is a manager for python software package): sudo apt-get install python-pip
d) Install rpi.gpio with pip command: sudo pip install rpi.gpio
e) testing Command: sudo python
After all steps, you will see the following photo. It means it is successful to install GPIO library and Python library file. You can begin to program this project via Python
(2)Programming
You can compile code not only through connecting monitor with your Pi, also through SSH. You can choose two methods to compile the project code.
A. File editor to compile code:
1)create a new file “led.py” in any direction (such as “/home/pi/”): enter the command sudo touch led.py and then press enter
2)Open file “led.py”: enter the command sudo nano led.py and then press enter
3)paste the following code in the file “led.py”
#turns on and off a light emitting diode(LED) depending on motion sensor import RPi.GPIO as GPIO #importing the RPi.GPIO module import time #importing the time module GPIO.cleanup() #to clean up at the end of your script led_pin = 37 #select the pin for the LED motion_pin = 35 #select the pin for the motion sensor def init(): GPIO.setmode(GPIO.BOARD) #to specify which pin numbering system GPIO.setwarnings(False) GPIO.setup(led_pin,GPIO.OUT) #declare the led_pin as an output GPIO.setup(motion_pin,GPIO.IN,pull_up_down=GPIO.PUD_UP) #declare the motion_pin as an input print("-----------------------------------------------------------------------") def main(): while True: value=GPIO.input(motion_pin) if value!=0: #to read the value of a GPIO pin GPIO.output(led_pin,GPIO.HIGH) #turn on led time.sleep(2) #delay 2ms print "LED on" #print information else: GPIO.output(led_pin,GPIO.LOW) #turn off led time.sleep(2) #delay 2ms print "LED off" #print information init() main() GPIO.cleanup()
4) after compile the project, press “Ctrl” + “X” to save the code, enter “Y” to confirm saving, and press “enter” to exit the file editor
B. Command to compile code
Enter the command wget http://osoyoo.com/driver/led.py, and press “enter” to complete compiling code.
(3)Experiment Result:
Enter the following command: sudo python ./led.py, and press “enter” to run the project. When detection body motion, the LED turns on, else, the LED turns off, and the monitor shows as the photo:
DownLoad Url osoyoo.com
You must be logged in to post a comment.
Hi I am new where is the links to download this programs
which link you want to download?
Raspberry Pi 学ぶ電子工作キットに含まれている人体感知センサーモジュールはHC-SR501でしょうか?
Nk様へ
お問い合わせ、ありがとうございます。オソヨーの担当者jackと申します。
間違いなく、Raspberry Pi 学ぶ電子工作キットに含まれている人体感知センサーモジュールはHC-SR501です。
Amazonの販売リンクは下記で御座います。
初心者スターターキット for Raspberry Pi 3 2 Model B 電子工作キット (改良版)
https://www.amazon.co.jp/dp/B07567Y7JL/ref=olp_product_details?_encoding=UTF8&me=
初心者スターターキット for Raspberry Pi 3 2 Model B 電子工作キット (基本版)
https://www.amazon.co.jp/dp/B01M6ZFNSS/ref=olp_product_details?_encoding=UTF8&me=
E-メール [email protected]
電話 03-4579-7588
どうぞよろしくお願い致します。