Manish Kumar Yadav
Published

Secure Door Access Control and Email Alert System

The Secure Door Access Control and Email Alert System that aims to enhance the security of buildings or rooms by restricting access

AdvancedFull instructions provided6 hours411
Secure Door Access Control and Email Alert System

Things used in this project

Story

Read more

Schematics

Schematic

Code

Secure Door Access Control and Email Alert System

Python
# BY MANISH KUMAR YADAV

import RPi.GPIO as GPIO
import time as t
from mfrc522 import SimpleMFRC522
import smtplib
import picamera
import os
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(12,GPIO.OUT)
# enabling PWM pin
pwm=GPIO.PWM(12,50)
pwm.start(0)
# fucntion to set angle to servo motor
def SetAngle(angle):
    duty = angle / 18 + 2
    GPIO.output(12, True)
    pwm.ChangeDutyCycle(duty)
    t.sleep(1)
    GPIO.output(12, False)
    pwm.ChangeDutyCycle(0)
# checks whether particular user has entry or not
def validation():
    valid = ["ID 1", "ID 2"]    #list of valid users
    if id in valid:
        print("Entry Accepted")
        SetAngle(180)  #rotate servo to open door
        t.sleep(2)
        SetAngle(0)  #rotate servo to close door
        return "Person Entry Accepted"
    else:
        print("Entry Denied")
        return "Person Entry Denied"
# function to enable stmp server and send mail
def email(message):
    # Define email credentials and recipient
    to_email = 'to_ email'
    password = 'password'
    from_email = 'from_email'
    # Take a picture with the Raspberry Pi camera module
    camera = picamera.PiCamera()
    camera.resolution = (640, 480)
    camera.capture('/home/pi/image.jpg') # location and format
    # Create the email message
    camera.close()
    msg = MIMEMultipart()
    msg['From'] = from_email
    msg['To'] = to_email
    msg['Subject'] = message
    #open the image saved in local system and attach it to email message
    with open('/home/pi/image.jpg', 'rb') as f:
        img = MIMEImage(f.read())
        msg.attach(img)
    # Send the email
    try:
        server = smtplib.SMTP('smtp.gmail.com', 587)
        server.starttls()
        server.login(from_email, password)
        text = msg.as_string()
        server.sendmail(from_email, to_email, text)
        server.quit()
        print('Email sent successfully')
    except Exception as e:
        print('Something went wrong:', e)
# instantiating RFID module
reader = SimpleMFRC522()
while 1:
    print('Place Your Tag')
    id,text= reader.read()  #reads tag info
    m=validation()   #checks validation and gets message about access
    email(m)   #passes that received message as subject to email
    print("ID : ",id)
    print("Name : ",text)
    print('------------------')

Credits

Manish Kumar Yadav

Manish Kumar Yadav

11 projects • 12 followers
Highly skilled Electronics and Communication Engineer, adept Programmer, and creative PCB Designer.

Comments