Security System With Motion Detection

The system is designed to detect intrusion (unauthorized entry) into a building or other area.

Step 1: Things Used in This Project

Hardware components

  • KEMET Electronics Corporation Proximity Sensor- Pyroelectric Infrared Sensor Module×1
  • Raspberry Pi Zero×1 Raspberry Pi Camera Module V2×1
  • Buzzer×1
  • LED (generic)×2
  • Arcade button×1
  • Digilent 5V 2.5A Switching Power Supply×1
  • Digilent 60W PCIe 12V 5A Power Supply×1
  • Jumper wires (generic)×10

Software apps and online services

  • Raspberry Pi Raspbian
  • OpenCV

Step 2: Idea

The system is designed to detect intrusion (unauthorized entry ) into a building or other area. This project can be used in residential, commercial, industrial, and military properties for protection against burglary or property damage, as well as personal protection against intruders

A compact, low profile project is attached to the wall of the area which has to be monitored. This project consists of a camera that will capture the image of the intruder and notify the owner. To test the real-time scenario, we deployed it on one of the jewelry shops to test how possibly it could help them and the results were pretty affirmative.

Step 3: ​Getting Started With Pyroelectric Proximity Infrared Sensors

KEMET Electronics Pyroelectric Proximity Infrared Sensor Modules use the pyroelectric proximity effect of ceramic by absorbing infrared rays emitted from the human body. This detects the natural infrared signature produced by humans. It can detect infrared rays without using lenses, allowing a detection distance up to 2 meters. By adding a KEMET proprietary lens, the detection distance can be further improved up to 5 meters. The lens is available in three different colors, to enable some design flexibility. KEMET Electronics Pyroelectric Proximity Sensor Modules in the module solution are even easier to install with the driving being already included in the package, making it just “plug and sense”.

FEATURES

  • Reflow capable SMD configuration
  • Lens not requiredWide view angle up to ±60°
  • Detection possible through glass or resin
  • Low power consumption, down in the μA range
  • Excellent radio wave performance in a high-frequency band
  • Compact and low profile (5.0 x 4.8 x 1.7mm)
  • Human presence detection sensing for energy-saving functions in a variety of applications

APPLICATIONS

  • Contactless switching
  • Office automation equipment
  • Home appliances
  • Lighting
  • Display products
  • Air-conditioners
  • TVs
  • PC monitors
  • Rice cookers
  • Smart toilets

We use the sensor with a white lens which gives a 74° view angle and the range up to 5m.

Step 4: Burn Raspbian to the SD Card

Raspbian is the Linux distribution of choice running on the Raspberry Pi. In this guide, we will be using the Lite version, but the Desktop version (which comes with a graphical environment) can be used as well.

  • Download Etcher and install it.
  • Connect an SD card reader with the SD card inside.
  • Open Etcher and select from your hard drive the Raspberry Pi .img or .zip file you wish to write to the SD card.
  • Select the SD card you wish to write your image to.
  • Review your selections and click ‘Flash!' to begin writing data to the SD card

Step 5: Interfacing With Raspberry Pi (Project Motion Dashcam)

The Block Diagram of this circuit is given.

PYRO SENSOR

To make these connections, I've used separate connectors for power, relay output, and sensor input. Each connector is soldered to the Raspberry Pi as shown below. Since the output from the pyro sensor is a digital signal, we connect the KEMET pyro sensor to the GPIO Pin 15 of Raspberry Pi.

The connection is made as shown below.

SS-430 —> Raspberry Pi

Vcc (1) —> +5V

Signal (4) —> GPIO15

GND (5)—> GND

PI-CAMERA – The Pi-camera is connected to the CSI port of the Raspberry Pi.

RELAY BOARD – We connect the Buzzer and an Emergency light using a relay circuit to the GPIO pins 23 & 24 of the Raspberry Pi.

Power Supply – The Power Supply is used to deliver the power for the Status Light, Emergency Light, and the Alarm.

The Industrial grade Light Indicators and Buzzer are used to show the status and alert signal to the security (user).

Relay Board —> Raspberry Pi

Vcc —> +5V

IN1 (Secure Light)—> GPIO23

IN2 (AlertLight & Buzzer) —> GPIO24

GND —> GND

The Industrial grade Light Indicators and Buzzer are connected to the GPIOs of the Raspberry Pi.

PUSH BUTTON The Emergency reset button is connected to the GPIO pin 14 of the Raspberry Pi.

The emergency button is used to turn off the alert manually by pressing it once. The Overall connection is shown.

Step 6: Code

GPIO of the Raspberry Pi can be accessed using the GPIO library which can be imported using the GPIO library.

The libraries such as RPi.GPIO and time are used in this project.

import RPi.GPIO as GPIO 

import time

The GPIO pin is then configured to digital input using the following lines

sensorPIN = 15

GPIO.setmode(GPIO.BCM)

GPIO.setup(sensorPIN, GPIO.IN)

GPIO Pin 15 is configured to use as digital input which reads for every 50ms. Whenever the intruder/human enters in the range, the sensor detects and produces the digital pulse.

while True:               

	if GPIO.input(sensorPIN): # if sensorPIN == 1        

	print "Intruder Alert !!!"    
	
else:        

	print "No intruder"    

	time.sleep(0.05)         # wait 50 milliseconds

Although the above code worked, I had a few false triggering. After going through the documentation from KEMET, The SS-430 produces two output pulses of 200msec per detection. This can be interpreted by the Raspberry pi using the following code:

import RPi.GPIO as GPIO
import time
sensorPIN = 15
GPIO.setmode(GPIO.BCM)
GPIO.setup(sensorPIN, GPIO.IN)
pulse = 0
PyroRead = 0
IR_threshold = 198000
IR_sensed = 0
start_time = 0
end_time = 0
try:
while True:
while(IR_sensed < 2):
            start_time = time.time()
            GPIO.wait_for_edge(sensorPIN, GPIO.FALLING)
            GPIO.wait_for_edge(sensorPIN, GPIO.RISING)
            GPIO.wait_for_edge(sensorPIN, GPIO.FALLING)
            end_time = time.time()
            PyroRead = round((end_time - start_time)*1000000)
            print(PyroRead)

if(PyroRead > IR_threshold):
                IR_sensed += 1
        pulse = pulse + 1
        print(pulse)
        print("Intruder Alert !!!")
        PyroRead = 0
        IR_sensed = 0
        time.sleep(1)         # wait 1 second
finally:
    print("clean up")
    # GPIO.cleanup([sensorPIN])
    GPIO.cleanup() # cleanup all GPIO

Now the sensor can determine the presence of the human within the specified range and view angle.

After a lot of struggles and effort, I have created a library to interface KEMET's pyro sensor with the Raspberry Pi.

The picamera library is installed using the following command

sudo apt-get install python-picamera

Next, we interface the Raspberry Pi Camera Module V2 to the Raspberry Pi. We import picamera library to interface the camera with the raspberry pi. We have set the resolution of the camera at 1024 x 768 so that the images are captured at a lower resolution. This allows us to reduce memory usage and to send the images.

import picamera

with picamera.PiCamera() as camera:
	camera.resolution = (1024, 768)

From the above example, the picture of the intruder is captured by the device which has to be transmitted to the master (owner). First, we add the Smtplib package allows us to set up the Gmail server. Install an SMTP service with the command

sudo apt-get install ssmtp

Make sure that Allow less secure apps setting is turned on for allowing Gmail SMTP Access Authentication.

import glob
import smtplib
import os

These four modules are used to send the emails from a Raspberry Pi:

from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.utils import formatdate
from email import encoders

We need to add the receiver's email and sender's email address and password, in our case both, are the same email as shown below:

sender = '[email protected]'
password = ' Replace the pass '
receiver = '[email protected]'

By making several adjustments to the code, you can change the Subject, sender address, receiver address, and the content of the body. The images are sorted and the latest image is sent via Gmail (SMTP).

We have also added two relay circuit and a manual reset push button to the circuit. These are treated as normal GPIO to indicate or to inform the status of the theft alert using LED and Buzzers.

# Set pins 23, 24 to be an output pin and set initial value to low (high), since relay ckt is pull-down mechanism
Green = 23
Red = 24
GPIO.setup(Green, GPIO.OUT, initial=GPIO.HIGH) 
GPIO.setup(Red, GPIO.OUT, initial=GPIO.HIGH) 

# Set pin 14 to be an input pin
reset_button = 14
GPIO.setup(reset_button, GPIO.IN)

while True:           
if GPIO.input(sensorPIN): # if sensorPIN == 1
        GPIO.output(23, GPIO.HIGH) # Turn off Green
        GPIO.output(24, GPIO.LOW) # Turn on Red
if !GPIO.input(reset_button):
            break
else:
        GPIO.output(23, GPIO.LOW) # Turn on Green
        GPIO.output(24, GPIO.HIGH) # Turn off Red
    sleep(0.05)         # wait 50 milliseconds

Step 7: Enclosure

  • I had used the raspberry pi zero enclosure for this project.
  • A small section is needed to attach the SS-430 pyro sensor to the project. I have adhered the sensor to the Indicator firmly as shown.
  • Make sure that the required wires/connects are soldered to the raspberry pi. This is a crucial part to meet the size of the device. I have used the terminal block connector to make the common connections. One end of the wires is soldered to the Raspberry Pi.
  • Now Insert the device inside the enclosure and It would look something like this

 

Voila! The connection is done and we are equipped to test it.

Step 8: Working of the Project

To test the real-time scenario, we deployed it on one of the jewelry shops to test how possibly it could help them and the results were pretty affirmative.

If you faced any issues in building this project, feel free to ask me. Please do suggest new projects that you want me to do next.

Give a thumbs up if it really helped you and do follow my channel for interesting projects. 🙂

Share this video if you like.

Happy to have you subscribed: https://www.youtube.com/c/rahulkhanna24june?sub_confirmation=1

Source: Security System With Motion Detection


About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Scroll to Top