Creating a RFID Door Latch With Arduino
by KEV_123456 in Circuits > Arduino
7391 Views, 48 Favorites, 0 Comments
Creating a RFID Door Latch With Arduino
This is an RFID(otherwise known as Radio-Frequency Identification) door latch, made to unlock then lock a door/cabinet/locker when the corresponding RFID tag is scanned.
This is a project I have been working on for about 2 weeks, and I will show you how to make it in this instructable. There is wood construction in this project and I will briefly discuss it. I am not good with wood or construction but it is a model to show the project mounted.
There are also 3d print files in this that are necessary and I will discuss them when it comes up. The 3d files are not my own and I discovered them on Makerbot Thingiverse https://www.thingiverse.com/ & the DIY Life https://www.the-diy-life.com/.
Proper credit will be given to the original creators when the 3d files are discussed.
Supplies
The Supplies are as follows:
- Arduino Uno x1
- Male to Female jumper wires
- Male to Male jumper wires
- Breadboard x1
- MFRC522 RFID reader x1
- RFID tag/card x1
- 16 x 2 Liquid Crystal display x1
- Potentiometer x1
- Access to a 3d printer and filament
- Micro servo x1
- servo push rod x1 https://www.amazon.com/Hockus-Accessories-Multiple-Adjustable-Connecting/dp/B07V2H39X2?th=1(this link is a picture to one if there is confusion)
Wiring the Arduino to the Micro Servo, LCD, and the RFID Reader
Tinkercad can show the wiring for the LCD and the Micro servo but not the RFID. For the RFID I will tell you specifically which pin to go where.
use the RFID photo as a reference
3.3v goes to the 3.3v on the Arduino
RST goes to 9
GND goes to GND on the breadboard
skip IRQ
MISO goes to 12
MOSI goes to 11
SCK goes to 13
SDA goes to 10
3d Print Files
For the 3d print files, the LCD Screen bezel is created by TheMakersWorkbench https://www.thingiverse.com/thing:651963
The RFID reader holder is made by DZSY https://www.thingiverse.com/thing:3853458
The lock was made by Sagittario and then modified by Michael Klements and the micro servo holder was created by Michael Klements, RFID Lock 3D Print Files
You could also use a metal slide lock from the department store as well.
Code
To begin downloading the libraries, code, and view your RFID cards UID, use the video above that I created to see how to do it. I am using Arduino create for education, so this doesn't apply to Arduino IDE, also lower your volume because it is a bit loud.
After following its instructions, in the serial monitor after scanning your RFID card, you will see a code like 39 AA E3 B3. This is your RFID card's UID.
#include <SPI.h> #include <MFRC522.h> #include <Servo.h> #include <LiquidCrystal.h>
Here are what the libraries would look like in your code.
#define SS_PIN 10 #define RST_PIN 9 #define SERVO_PIN 8 Servo myservo; #define ACCESS_DELAY 2000 #define DENIED_DELAY 1000 MFRC522 mfrc522(SS_PIN, RST_PIN);// Create MFRC522 instance. LiquidCrystal lcd(6,7,5,4,3,2);
This is defining the pins for the RFID module, the Mini Servo pins, and the LCD pins.
void setup() { Serial.begin(9600); // Initiate a serial communication SPI.begin(); // Initiate SPI bus mfrc522.PCD_Init(); // Initiate MFRC522 lcd.begin(16, 2); lcd.print("Scan RFID Card"); myservo.attach(SERVO_PIN); myservo.write( 75 ); // starting degree the motor will be at Serial.println("Put your card to the reader..."); Serial.println(); }
This code is initiating a serial communication, SPI bus, and the MFRC522(RFID module)
the LCD turns on and then starts on the grid (16,2), displaying "Scan RFID Card".
the Mini servo begins and moves to degree 75, while the serial monitor prints, "Put your card to the reader."
void loop() { // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) { return; } //Show UID on serial monitor lcd.clear(); lcd.begin(16, 2); lcd.print("UID tag :"); String content= ""; byte letter; for (byte i = 0; i < mfrc522.uid.size; i++)
{ lcd.setCursor(0,1); lcd.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); lcd.print(mfrc522.uid.uidByte[i], HEX); content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); content.concat(String(mfrc522.uid.uidByte[i], HEX)); } lcd.clear(); lcd.begin(16,2); lcd.print("Message : "); content.toUpperCase();
if (content.substring(1) == "39 AA E3 B3") //change here the UID of the card { lcd.clear(); lcd.setCursor(1,0); lcd.print("Access Granted"); myservo.write( 158 ); // the degree the motor will be at delay(7500); // how long the motor will stay at 158 myservo.write( 75 ); // goes back to 75 degrees lcd.clear(); lcd.print("Scan RFID Card"); // says Scan RFID Card again setup();
this is looking for the UID of the RFID card and when it is found the Cursor goes to (1,0), printing Access Granted while moving the Mini Servo to degree 158, keeping it there for about 7 1/2 seconds then going back to 65 degrees, clearing the LCD, then printing "Scan RFID card" again.
} else { lcd.clear(); lcd.setCursor(1,0); lcd.print(" Access Denied"); delay(4000); // displays Access Denied for about 4 seconds lcd.clear(); delay(DENIED_DELAY); lcd.print("Scan RFID Card"); setup(); } }
This part is when an RFID card is scanned but it is not an approved UID so "Access Denied" is displayed for about 4 seconds, then the LCD clears and says "Scan RFID Card" and the whole process restarts
In summary, this code is looking for a card while displaying "Scan RFID Card". when the incorrect card is scanned, then the words "Access Denied" are displayed for about 4 seconds and the motor doesn't move. When the correct Card is scanned the motor will open a certain amount of degrees to unlock the lock for about 7 seconds, displaying "Access Granted" then it will lock again, continuing to display "Scan RFID Card".
Downloads
Wood Construction(model)
This is a model to show what the layout could look like on a door, with the front having the doorknob, 3d print RFID case, LCD screen bezel, and a random piece of metal that serves as the door stopper.
The backside has the 3d printed lock, micro servo holder, the hole where the LCD screen goes, Arduino, mini breadboard, and the negative and positive part of a breadboard that I ripped out.
Conclusion
So, there we go! You have made a functional RFID Security door latch for your cabinet, door, or locker.
If you wish to use this for actual security make sure to use a metal door latch from a Home improvement company, like Home Depot, also make sure to keep the LCD and the RFID module well protected and secure to prevent tampering.