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
- Raspberry pi 4
- Pi Camera
- Push Button
- Jumper wires and Bread board
Project Methodology
- 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.
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..