Overview

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.

Experimental photo

DSC_5470

Experimental Parts

PI
Raspberry Pi3 x1
Digital-Motion-Sensor
Motion Sensor x1
18
Buzzer sensor x1
19
Jumper wires

Circuit Graph

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.

Untitled Sketch_buzzer

Motion Sensor Schematic

schematic

Motion sensor Interface Layout

The two potentiometer can adjust delay time and sensitivity, as the follow picture:

adjust

Software

1) Enter the following command to compile the code, and press “enter” to complete compiling code:

sudo wget --no-check-certificate   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

the downloaded code are actually as following:

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 detect():
         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()
detect()

GPIO.cleanup()

Experiment Result:

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

2017-03-23-064257_1824x984_scrot