How to make an RFID door lock system with Raspberry Pi board

How to make an RFID door lock system with Raspberry Pi board

Hello and welcome back. In this project, we will learn how to make an RFID door lock system with the Raspberry Pi board. I used the Raspberry Pi model B board for that. You can use any other board for this project. If you are not familiar with this RFID module, please use the link for more information.

Also, I have assembled this project on the breadboard. But you can use a dot board or PCB for this project. Then, we can have a finished look for this project. One thing, I didn’t use a door lock in this project. But, I have added the relay module. Then, you can connect an electromagnetic door lock to the relay module. (See the picture below) Also, we need to provide a 12v external power supply to the electromagnetic door lock. Don’t worry, all of these are explained in the circuit diagram.

If you want to know how to do this project with Arduino, use this link for that.

OK, let’s do this project step by step. The required components are given below.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect the GPIO Extension board to the breadboard. And then, connect the GPIO ribbon cable to the extension board.

Step 3

Thirdly, connect the RFID module to the GPIO extension board. For that, use the circuit diagram below.

How to make an RFID door lock system with Raspberry Pi board

Step 4

Next, place the buzzer on the breadboard. And then, connect it to the extension board. Also, connect the LCD and relay module to the extension board. Please use the circuit diagram above.

Step 5

Now, connect the keyboard, mouse, monitor, ethernet cable, and SD card(OS installed) to the Raspberry Pi board.

Step 6

Then, connect the GPIO ribbon cable to the Raspberry Pi board and provide a power supply to the board.

Step 7

Ok, now let’s install the RFID library into Raspberry Pi OS. Follow the instructions below for that.

  • First, open the terminal and run the following commands one by one. At this point, the Raspberry Pi board must be connected to the Internet.
  1. sudo apt install python3-dev python3-pip

2. sudo pip3 install spidev

3. sudo pip3 install mfrc522

OK, the RFID library is ready for this project.

Step 8

Now, enable I2C and SPI communication. Because the LCD screen and RFID module required these communication methods. If you want to know whether I2C is working or not, run the following code on the terminal. Then, we can see the I2C address.

  • i2cdetect -y 1

Step 9

Now let’s create the python script for this project. Follow the below steps for that.

  • First, let’s get the RFID tag ID. For that, copy and paste the following program on the Thonny IDE. Then, save this script and click the run button.
  • Full details of this project — Download
  • No need to install I2C library. It is included in the file above. But keep these scripts in one folder.
# Include the library filese
import I2C_LCD_driver
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
from time import sleep

#Include the buzzer pin
buzzer = 19

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(buzzer,GPIO.OUT)

# Create a object for the LCD
lcd = I2C_LCD_driver.lcd()

# Create a object for the RFID module
scan = SimpleMFRC522()


try:
        print("Now place your Tag to scan")      
        lcd.lcd_display_string("Place your Tag",1,1)                                               
        scan.write("Tag ID")
        id,Tag = scan.read()                    
        print("Your Tag ID is : " + str(id))
        lcd.lcd_clear()
        lcd.lcd_display_string("Tag ID",1,5)
        lcd.lcd_display_string(str(id),2,1)
    
        GPIO.output(buzzer,GPIO.HIGH)
        sleep(0.5)
        GPIO.output(buzzer,GPIO.LOW)

finally:
        GPIO.cleanup()
        

  • Now, place the RFID tag on the RFID reader. Then, we can see the tag ID on the LCD screen and shell.

  • And then, copy and paste this ID to the main python script.
  • Full details of this project — Download
  • No need to install I2C library. But, it should be placed with python scripts.
# Include the library files
import I2C_LCD_driver
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
from time import sleep

#Include the buzzer pin
buzzer = 19

#Include the relay pin
relay = 26

#Enter your tag ID
Tag_ID = "1044051400610"

door = True

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(buzzer,GPIO.OUT)
GPIO.setup(relay,GPIO.OUT)

# Create a object for the LCD
lcd = I2C_LCD_driver.lcd()

# Create a object for the RFID module
read = SimpleMFRC522()

#Starting text
lcd.lcd_display_string("Door lock system",1,0)
for a in range (0,15):
    lcd.lcd_display_string(".",2,a)
    sleep(0.1)


while True:
    lcd.lcd_clear()
    lcd.lcd_display_string("Place your Tag",1,1)
    id,Tag = read.read()
    
    id = str(id)
               
    if id == Tag_ID:
        lcd.lcd_clear()
        lcd.lcd_display_string("Successful",1,3)
        
        if door == True:
            lcd.lcd_display_string("Door is locked",2,1)
            GPIO.output(relay,GPIO.HIGH)
            GPIO.output(buzzer,GPIO.HIGH)
            sleep(0.5)
            GPIO.output(buzzer,GPIO.LOW)
            door = False
            sleep(3)
            
            
        elif door == False:
            lcd.lcd_display_string("Door is open",2,2)
            GPIO.output(relay,GPIO.LOW)
            GPIO.output(buzzer,GPIO.HIGH)
            sleep(0.5)
            GPIO.output(buzzer,GPIO.LOW)
            door = True
            sleep(3)
                        
        
    else:
        lcd.lcd_clear()
        lcd.lcd_display_string("Wrong Tag!",1,3)
        GPIO.output(buzzer,GPIO.HIGH)
        sleep(0.3)
        GPIO.output(buzzer,GPIO.LOW)
        sleep(0.3)
        GPIO.output(buzzer,GPIO.HIGH)
        sleep(0.3)
        GPIO.output(buzzer,GPIO.LOW)
        sleep(0.3)
        GPIO.output(buzzer,GPIO.HIGH)
        sleep(0.3)
        GPIO.output(buzzer,GPIO.LOW)            

GPIO.cleanup()     
        

  • Now, save this script and click the run button.

OK, enjoy this project. The full video guide is below. So, see you in the next project or tutorial.

How to make an RFID door lock system with Raspberry Pi board

Similar Posts

Leave a Reply

Your email address will not be published.