Make Your Own Arduino RFID Door Lock

arduino rfid door lock

arduino rfid door lock

Tired of being locked out when you lose or forget your keys? Well, I have the perfect solution for you! Today we will build an Arduino RFID door lock. I wanted to find an easy and secure way to lock a door, without having to buy an expensive locking device. We will learn about radio frequency identification (RFID) and make use of wireless communication.

What is RFID?

“RFID stands for Radio-Frequency IDentification. […] The RFID device serves the same purpose as a bar code or a magnetic strip on the back of a credit card or ATM card; it provides a unique identifier for that object. And, just as a bar code or magnetic strip must be scanned to get the information, the RFID device must be scanned to retrieve the identifying information.” – ©Technovelgy – where science meets fiction.

RFID is used in this project to read data from the RFID tags and send the information to the non-volatile memory of the MCU. The ID read from the tags is compared with the stored information, and if it matches, then the door unlocks/opens.

 

Hardware

  • Arduino Nano
  • RFID RC522
  • Piezo Buzzer
  • 2x LED
  • 2x 330 Resistor
  • Keypad 4×4
  • Adapter I2C for LCD
  • LCD16X2BL

 

Software

 

Wiring the LCD to the Arduino

The LCD has 16 pins which is too much for an Arduino Nano, that’s why it’s important to have an I2C adapter. This allows running the display from only 2 signal pins on the Arduino. It is helpful because of the small number of pins that will have to be controlled from the MCU.

arduino rfid door lock

Figure 1: LCD pins

The LCDs have a parallel interface, meaning that the MCU has to manipulate several interface pins at the same time to control the display. The table below gives a description for each of the pins:

arduino rfid door lock

Figure 2: Pin specification

 

First, we will make the connections between LCD and I2C. To do that, we need an I2C LCD display adapter (LCD1602). The adapter converts the 16 x 2 character LCD display into a serial I2C LCD that can be controlled via Arduino by just 2 wires.

 

arduino rfid door lock

Figure 3: Connections between Arduino and LCD

 

Next, we’ll add library “<LiquidCrystal_I2C.h>” in Arduino IDE. The library allows us to connect the LCD to the Arduino. The built-in LiquidCrystal_I2C library makes it easy to display characters on the LCD.

 

You can download the LiquidCrystal_I2C.h here.

 

Please follow the steps below to install a new library into your Arduino IDE.

 

1) First, download the files from Github. (I’ll be downloading Keypad library.)
arduino rfid door lock

2) Zip (.zip) each folder.

arduino rfid door lock

 

 

3) Copy the .zip files to your Arduino folder.

arduino rfid door lock

 

 

4) Open Arduino and add Keypad.zip: : Sketch menu > Include Library > Add .ZIP Library.

arduino rfid door lock

 

 

5) Add keypad library: Sketch menu > Include Library > Keypad.

arduino rfid door lock

 

Codes to test LCD:

 

 

arduino rfid door lock

Figure 4: LCD connected to Arduino Nano

 

Connecting the Keypad

Now, on to the keypad! We will connect the keypad in order to display the numbers on the LCD that we input from the keypad.

Keypad.h is a library which allows the Arduino to read a matrix type keypad.

I used a 4×4 keypad in this tutorial.

 

The table shows the connection between the Arduino board and the keypad. The keypad pins are connected to Arduino’s digital output pins. Pin D6 was used for the buzzer because it was a PWM pin.

Keypad pin Arduino pin
1 D2
2 D3
3 D4
4 D5
5 A0
6 D7
7 D8

 

arduino rfid door lock

Figure 5: Connection between Arduino, LCD, and Keypad

 

 

arduino rfid door lock

Figure 6: LCD and Keypad connected to Arduino

Wiring the RFID

Next, we will add the RFID. In this case, the RFID board uses a SPI communication protocol, where the Arduino will be acting as a master and the RFID reader as a slave. The card reader and the tags are designed to communicate using a frequency equal to 13.56MHz.

This is an important step because it helps us to read data from the card and it will decide if the ID corresponds to the information stored in the EEPROM. If it matches, it will give us access and display “Unlocked”. Otherwise, the LCD will display “Blocked”.

 

arduino rfid door lock

Figure 7: Connection between Arduino, LCD, and RFID

 

arduino rfid door lock

Figure 8: Arduino, LCD, and RFID

 

Adding a buzzer & LEDs

Next step is to add a buzzer and 2 LEDs to simulate a controlled access system. Please review the wire diagram below (Figure 9). The buzzer is set so that it buzzes whenever we gain access (unlocked). The red LED is always on when it is locked, but the green LED will come on when it is unlocked.

In order to protect the modules, I decided to 3D print the housing box/case. If you don’t have a 3D printer, you can just use a plastic case that allows you to fit all of the components inside. This is very helpful because the modules will be placed inside and the only parts outside of the box will be the LEDs, keypad, and LCD.

arduino rfid door lock

Figure 9: Wire diagram showing connection between Nano, LCD, Keypad, RFID, and buzzer

 

Building The Housing Case/Box

For this project, I wanted to create a custom case to house all of the components neatly and keep them free of damage.

I have designed a box using SketchUp, which has a user-friendly interface with simple buttons like Eraser, Lines, and Tape Measure Tool.

The dimensions of the box is 120x125x37 mm.

arduino rfid door lock

If you’re not familiar with Sketchup, I recommend you go through some SketchUp tutorials here.

 

arduino rfid door lock

Figure 10: Housing case (top view)

 

arduino rfid door lock

Figure 11: Housing case (bottom view)

 

When I designed the box, I took these dimensions into consideration:

  • Top view:
    • 2 openings for the LEDs (5.2 mm)
    • 1 opening for LCD (42.2×7.3 mm)
    • 1 opening for cable (16×10.5 mm)
  • Bottom view:
    • 1 opening for keypad (27×10 mm)

 

After I measured the dimensions of the components, I designed a box that’s rather compact. Feel free to change the design to your preference.

arduino rfid door lock

Figure 12: Complete housing case with modules placed inside

 

Code diagram

arduino rfid door lock

Full Code  

Conclusion

So, we managed to build a low-cost Arduino RFID door lock. It was an interesting project for me because I made it for my personal use. Moreover, building such a device will provide you not only the satisfaction of doing something useful, but also a lot of knowledge and an initiation in the first steps of custom electronics. Dealing with a wide range of boards will be definitely very challenging. The project presents a lot of interesting tasks, such as:

  • Working with other Arduino libraries
  • Understanding the use of EEPROM
  • Working with multiple communications like I2C, SPI

Click here to see Part 2 of this article, where we enable unlocking from a smartphone! Check out our Arduino projects section for other fun and challenging Arduino projects!