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.
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.
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.
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:
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.
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.
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.)
2) Zip (.zip) each folder.
3) Copy the .zip files to your Arduino folder.
4) Open Arduino and add Keypad.zip: : Sketch menu > Include Library > Add .ZIP Library.
5) Add keypad library: Sketch menu > Include Library > Keypad.
Codes to test LCD:
LiquidCrystal_I2C lcd(0x27,16,2);// Set the LCD address to 0x27 for a 16 chars and 2 line display
lcd.begin();// initialize the LCD
lcd.backlight();// Turn on the blacklight and print a message.
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.
Figure 5: Connection between Arduino, LCD, and Keypad
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”.
Figure 7: Connection between Arduino, LCD, and RFID
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.
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.
If you’re not familiar with Sketchup, I recommend you go through some SketchUp tutorials here.
Figure 10: Housing case (top view)
Figure 11: Housing case (bottom view)
When I designed the box, I took these dimensions into consideration:
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)
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.
Figure 12: Complete housing case with modules placed inside
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!