This is a really easy RFID door lock mechanism which is based on the Arduino Uno and the RC522 RFID sensor, which allows you to use RFID tags or cards to lock and unlock a door, drawer or cupboard. You can load as many RFID tags as you’d like onto the Arduino and add or remove tags to provide more or fewer people with access. The lock is actuated with a micro servo, which can be used along with the 3D printed lock provided in this example, or any standard bolt type lock available from your local hardware store.

This guide assumes that you’ve worked with an Arduino micro-controller before and know the basics of programming an Arduino. If you do not, follow the linked guide for more information on creating and uploading your first sketch.

Here is a summary of the build, continue reading for full step by step instructions along with the code and print files:

What You Need To Make Your Own Arduino Based RFID Lock

How To Make Your RFID Door Lock

To start off, lets connect the RFID sensor, LEDs and servo to your Arduino using a breadboard. This will enable you to test the circuits and to read the serial numbers from your tags in order to load them into the array in your code so that they open the lock.

The Circuit

The RC522 sensor is going to be connected to our Arduino using the SPI interface. We are then going to connect a green LED which will flash to show that a tag has been read and access has been granted and a red LED which will flash to indicate that a tag has been read an access has not been granted. Lastly, a micro servo will be used to open and close the locking mechanism. The LEDs and micro servo are connected using typical Arduino circuits.

Here is the circuit:

RC522 RFID Sensor Connection to Arduino

Once you’ve got the circuit connected on your breadboard, you’ll need to print and assemble your lock mechanism.

RC522 Sensor Connection To Arduino

Assembled Circuit

Building The Lock Mechanism

If you’ve got a 3D printer, the easiest way to get started with an RFID door lock is to print out the below components and servo bracket. The lock mechanism is based on this sliding lock design by Sagittario which I have scaled down to 65% of the original size.

I 3D printed the lock mechanism and servo holder using white PLC at 185C and 20% infill.

3D Printed RFID Lock

Download 3D Print Files: RFID Lock 3D Print Files

Assembled RFID Door Lock Mechanism

If you don’t have a 3D printer, you can use any standard bolt type sliding lock available from your local hardware store. You’ll just need to attach one end of the servo push rod to the bolt to actuate it. You’ll also need to build a simple servo bracket to hold the servo in place behind the lock. You can just epoxy or glue the servo in place, but a screwed on bracket is usually a bit stronger.

Uploading The Code

Once you’ve assembled your lock mechanism, you’re ready to upload your code and load your tag numbers into the array.

Here is the code:

Download the code: RFID Sensor Sketch

Before you upload your code, you’ll need to install the RFID library which is bundled with the sketch zip file. This is easily done in your Arduino IDE by clicking on Sketch -> Include Library -> Add .ZIP Library and the selecting the zipped library file.

In the code we first include the required libraries and then set up the sensor object and an array to return the read tag serial number.

The next array and its associated size is used to store the serial numbers for all of the tags which you’d like to grant access to. You’ll need to find and update these numbers using the serial monitor by uploading this code and then scanning your tags. The Serial monitor will display the tag’s serial number and then state that access is denied. Copy this number into the array accessGranted, update the array size (number of tags registered) and then re-upload the code. You could also write a short section to enable you to register a new tag by pushing a button inside the sensor component box or inside the door for example.

We then set up the servo object and it’s travel limits. You may need to make adjustments to these limits to get your servo to move through it’s full range without over-travelling in either direction.

In the setup code, we connect to the RFID sensor, define the LED pins and then run through a quick LED flash startup sequence before making sure that the lock is in the locked position. You can remove the Serial monitor output lines in the code in your final version, these are just useful for registering your tags and debugging the system when you first assemble it.

We then run through the loop which waits for a card or tag to be scanned, determines its serial number and then passes this serial number through to a function called checkAccess to verify whether the tag number can grant access or not.

The checkAccess function simply takes the read tag number and then cycles through the array of accepted numbers to see if it is an accepted tag. If a match is found then the green LED is flashed and the lock is either opened or closed, depending on the previous state. If the tag number is not found in the array then the red LED is flashed and the lock is not opened.

Adding or Removing Accepted Tags

As mentioned in the previous step, the array accessGranted is used to store the serial numbers of the accepted tags and the integer accessGrantedSize stores the number of entries in this array.

Accepted RFID Tag

To add a tag, you’ll need to scan the tag with the Serial monitor open on your PC. You’ll then get a message saying that the card has been read along with the serial number of the card and a message saying “Access Denied”. Simply copy this number into the array and update the size integer to reflect the new number of tags. Re-upload the code and you should now get an “Access Granted” message on the Serial monitor.

To remove a tag, find the tag serial number in the array (you may need to scan it as done previously) and remove it from the array. Update the array size for any tags which you remove as well.

It is fairly easy to include a push-button or two on the inside of the door or in the component box which will allow you to add or remove tags without having to update the code.

Using the Lock

You should now have a functioning RFID locking mechanism which can be easily installed onto a door, cupboard or container to restrict access to it. You can also put the sensor components into a simple container or housing to mount on the front side of the door, like this:

Assemble Components Into A Sensor Housing

RFID Card Authenticated

Sliding RFID Door Lock Mechanism

There are a couple of ways to make this lock a bit more secure if you’re actually going to be using it to secure a room or cupboard.

Start by replacing the 3D printed lock with a proper metal lock from a hardware store. Make sure that you have a solid connection between the lock and the servo and try to position the servo such that the arm is in line with the push-rod and the head of the slider when it is in the locked position. This will ensure that you can’t slip a thin object through the gap in the door and try to push the slider open, you’ll be pushing against the centre of the servo and not relying on the torque provided by the servo to keep the slider in place.

Next, place as few of the electronic components outside as possible. It is better to have the actual Arduino and servo connection inside the room or box and place only the RFID sensor and LEDs outside. It’s much more difficult to trick the Arduino into opening the lock using the RFID sensor connection than it is to simply provide a PWM signal to the servo to unlock the door.

Have you built your own RFID door lock using an Arduino? Is there anything you’d suggest doing differently?Let us know in the comments section below.

Leave a Reply

Your email address will not be published.