This project introduces how to design a body motion detective security system with raspberry pi. The Experimental principle of this project is that, when the detection of the body motion, Raspberry Pi GPIO output get high level voltage and buzzer sound.
Raspberry Pi3 x1
Motion Sensor x1
Buzzer sensor x1
Note: Please note that reversing +/- or incorrectly connecting can destroy your raspberry Pi. The buzzer you get may have different solder pin as the following graph, please prevail in kind.
Motion Sensor Schematic
Motion sensor Interface Layout
The two potentiometer can adjust delay time and sensitivity, as the follow picture:
1) Enter the following command to compile the code, and press “enter” to complete compiling code:
sudo wget http://osoyoo.com/driver/motionsensor-test.py
You could modify the code throught the following ways.
enter the following command to create a new file named motionsensor-test.py and save this file at direction: /home/pi, and then press enter
sudo nano motionsensor-test.py
modify the following code in the file motionsensor-test.py , after compiling the project, press “Ctrl” + “X” to save the code, enter “Y” to confirm saving, and press “enter” to exit the file editor.
import RPi.GPIO as GPIO import time M_pin = 18 #select the pin for motionsensor B_pin = 26 #select the pin for buzzer def init(): GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(M_pin,GPIO.IN) GPIO.setup(B_pin,GPIO.OUT) pass def buzzer(): while GPIO.input(M_pin): GPIO.output(B_pin,GPIO.LOW) time.sleep(0.5) GPIO.output(B_pin,GPIO.HIGH) time.sleep(0.5) def detct(): for i in range(101): if GPIO.input(M_pin): print "Someone is closing!" buzzer() else: GPIO.output(B_pin,GPIO.HIGH) print "Nobody!" time.sleep(2) time.sleep(5) init() detct() GPIO.cleanup()
Enter the following command to run python program, and press “enter” to run the project. When detection body motion, you will hear buzzer sound, and the monitor shows as the photo:
sudo python ./motionsensor-test.py