Introduction: RFID Door Locking Mechanism With an Arduino
In this Instructable, we'll be connecting an RC522 RFID sensor to an Arduino Uno in order to make an RFID access controlled simple locking mechanism for a door, drawer or cabinet. Using this sensor, you'll be able to use an RFID tag or card to lock and unlock a sliding bolt type lock mechanism which can easily be mounted onto a door or drawer.
The locking mechanism in this Instructable is 3D printed, but you can use any commonly available sliding bolt type lock as well. The lock is actuated using a micro servo.
This Instructable 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.
In order to build your own RFID locking mechanism, you'll need the following:
- Arduino Uno (Or Other) – Buy Here
- Arduino Power Supply – Buy Here
- RC522 RFID Sensor – Buy Here
- Breadboard & Jumpers for Testing – Buy Here
- Micro Servo – Buy Here
- 2 x LEDs - Buy Here
- 2 x 220Ω Resistors - Buy Here
- 3D Printer & Filament (Optional for Lock) – This One Used
- Container or Housing For Sensor & Electronics
Step 1: 3D Print & Assemble the Lock Mechanism
First we'll assemble the lock mechanism, this consists of a 3D printed sliding lock and a micro servo with a servo arm.
You can also use a sliding bolt type lock which you'll need to connect the servo arm to.
The lock mechanism is based on this sliding lock design by Sagittario which I have scaled down to 65% of the original size.
Download 3D Print Files: RFID Lock 3D Print Files
I 3D printed the attached files using white PLA at 185C and 20% infill.
The mechanism and servo holder have screw holes to allow you to easily attached it to a cupboard, cabinet or drawer. You can also use hot glue or double sided tape to attached it less permanently.
Step 2: Assemble the Electrical Components
Connect the electrical components as shown in the schematic. I assembled them onto a breadboard first in order to test the components and load the ID numbers for the two tags which I wanted to allow access to.
The green and red LEDs are not required, they just provide a good indication that the tag is being read properly once the system is in a housing.
Step 3: Upload the Code
The full code description and download link can be found here - Arduino Based RFID Lock Mechanism Code
The link to just download the code is here - RFID Lock Code
Before you run the code, you'll need to install the RFID library which is bundled with the code in the above download.
The code essentially waits for a tag to be scanned. Once a tag is scanned, it passes the scanned ID to a function which checks if the scanned tag's ID number is in an array of accepted tags and then either grants access, flashes the green LED and unlocks or locks the mechanism depending on the previous state or denies access and flashes the red LED.
Step 4: Adding a Tag
The code includes an output to the Serial monitor on your PC. When you first run it, you'll need to register your tags which you'd like to grant access to. This is done by scanning the tag and recording the tag ID shown on your serial monitor. This number can then be added to the accessGranted array in order to grant access to the tag. The size of the array should also be increased or decreased accordingly.
Re-upload the code with the new array and you should now be able to scan your tag and it will flash green and either lock or unlock your mechanism depending on the previous state of the lock.
Step 5: Installing the Lock
In order to make the lock more usable, I installed it into a plastic container/housing with the LEDs visible on the front above the sensor area. The lock was then mounted onto the inside of the door.
If you'd like to make the system a bit more secure then you'll want to separate the sensor module from the Arduino and rather mount the Arduino on the inside of the door as well. It is much more difficult to reproduce the signal from the sensor module to the Arduino than it is to reproduce an PWM signal to the servo to open the lock.
If you'd like more information on the build of the locking mechanism and a in depth description of the code, have a look at the full build write up here - Arduino Based RFID Door Lock
Good luck with your build!