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 and buzzer sound.
Motion Sensor x1
some jumper wires
Note: Please 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 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
2)paste the following code in the file motionsensor-test.py
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()
3) After compiling the project, press “Ctrl” + “X” to save the code, enter “Y” to confirm saving, and press “enter” to exit the file editor
4) Enter the following command to compile the code(as the last 3 steps), and press “enter” to complete compiling code:
sudo sudo wget http://osoyoo.com/driver/motionsensor-test.py
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