Smart doormat for capturing thieves

Published Dec 13, 2021
 2 hours to build
 Beginner

In a home, this doormat can detect the entry of humans and capture their image silently and send to the user.

display image

Components Used

Raspberry Pi 4B
Raspberry Pi 4BRaspberry Pi 4B
1
Breadboard
Breadboard
1
Camera Module Raspberry Pi
Camera Module Raspberry Pi
1
Tactile Switches
Tactile Switches 12 x 12 mm 12 mm 100 gf Short Crimped Black Through Hole SPST
1
Description

                                Smart Doormat for finding thieves 

        Normally we use CCTV cameras for our home security which is more costly and took more storage. So our team designed a smart Doormat that will detect the human entry and takes a picture instantly. This will be more efficient than CCTV in both performance as well as in cost.

Components Used

  1. Raspberry pi 4
  2. Pi Camera
  3. Push Button
  4. Jumper wires and Bread board

Project Methodology

  1.  Connecting push Button

                          We can connect push Button with raspberry pi via GPIO PINS .One terminal of push button is connect to the ground(pin number 6) and the next terminal is connected to GPIO pin 2(pin number 3) of raspberry pi.

Circuit diagram for push button

Now we successfully completed our push button circuit. 

We connected our circuit , then what?... Yes now it's time to coding...

Raspberry pi has it's own module to work with buttons, so first of import these module into our Python code.

from picamera import PiCamera
from gpiozero import Button

This two line of code will import Pi Camera ,Button module form picamera , gpiozero library respectively.

Next we are assigning two variables in the name of 'camera' and 'button'.

camera= PiCamera()
button= Button(2)

Next we will use while loop to take control of push Button for multiple time.

while True:
   try: 
        button.wait_for_press()
        camera.capture('/home/pi/My coding/Coding_pic/frame%03d.jpg'% frame)'
        frame+=1

For each while loop it store it's particular image.

Now we are going to send email to the user to alert.

from picamera import PiCamera
from time import sleep
from gpiozero import Button
from email import encoders
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.base import MIMEBase
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
import smtplib
import os

camera = PiCamera()
button = Button(2)
camera.start_preview()
frame = 1
while True:
    try:
        button.wait_for_press()
        camera.capture('/home/pi/My coding/Coding_pic/frame%03d.jpg'% frame)

        fromaddr = "Your from address"
        toaddr = "Your to address"


        msg = MIMEMultipart()


        msg['From'] = fromaddr


        msg['To'] = toaddr


        msg['Subject'] = "Alert!"


        body = "Someone enter restricted area."


        msg.attach(MIMEText(body, 'plain'))


        filename = 'frame%03d.jpg'%frame
        attachment = open(("/home/pi/My coding/Coding_pic/frame%03d.jpg"%frame), "rb")


        p = MIMEBase('application', 'octet-stream')


        p.set_payload((attachment).read())


        encoders.encode_base64(p)

        p.add_header('Content-Disposition', "attachment; filename= %s" % filename)


        msg.attach(p)


        s = smtplib.SMTP('smtp.gmail.com', 587)


        s.starttls()


        s.login(fromaddr, "Your mail password") #for security purpose we not revealed our mail and password


        text = msg.as_string()


        s.sendmail(fromaddr, toaddr, text)


        s.quit() 
        
        
        frame += 1
        
    except KeyboardInterrupt:
        camera.stop_preview()
        break

This is the complete code.

After running this code, the user get the Alert message if anyone enter into his/her home..

 

 

Codes

Downloads

Circuit diagram file Download

Institute / Organization

St Josephs institute of technology
Comments
Ad