Introduction: Arduino RFID Lock.
Arduinos are amazing multi-purpose tools that can be used for most projects, with the most common restraint being your own creativity. This instructable will help you discover one of the numerous facets of the Arduino. The RFID chip. This project has the extreme flexibility as it can be used in locking doors, locking technology, and it can even simply be used to help teach the fundamentals of the Arduino. The RFID reader works by reading a code it receives from the RFID chip and comparing it to a bank of UID's, if it is a match the Arduino will run the unlock part of the program(It doesn't have to unlock anything). This project will go over the basics the RFID reader, the coding, the assembly, and how to add your own twist to things. I personally used this project to create a RFID locked bedroom door.
-7 Male to Female breadboard jumper wires
OPTIONAL SUPPLIES FOR DOOR LOCK
-16 breadboard jumper wires
-Sliding lock (3D printed seems to work best)
Step 1: The Coding of the RFID Reader
The first step just so happens to be the most complicated. Coding an RFID reader takes serious knowledge of the Arduino c+ language. I ended up needing to use this code as well to help me iron out all of the inconsistencies within my project. To help you avoid these difficulties I will include a link to download a fully functional code, right here.
if (content.substring(1) == "xx xx xx xx" ) //change here the UID of the card/cards that you want to give access
After the program reads the UID of the chip, it will compare it to the UID entered in the if statement (the UID, in this case, being xx xx xx xx). If the UID is a match it will run any program you enter into the if statement. My if statement was used to print a message stating the RFIDs acceptance, and then unlocking a door. It looks like this.
digitalWrite (2, LOW) ;
digitalWrite (2, HIGH) ;
This coding tells the arduino to print 'Authorized access' into the console. It then leaves space for another message below. The final three lines tells the arduino to take power away from pin 2 and then restore it after 3 seconds.
Serial.println(" Access denied"); delay(3000);
If the UID does not match up then the program runs this else statement, which does nothing but print 'Access denied' into the console.
If you choose to use the downloaded code the only thing you will need to do is change the assigned pins for the ss and rst, depending on your Arduino model. The code will have a built in guide to help you customize the coding to fit your device.
How to download the code.
Step 1- Download the program on your computer
Step 2- Open the arduino libraries by following this path in your file explorer. Documents > Arduino > Libraries
Step 3- Drag and drop the RFID_masters folder you just downloaded into the arduino library.
Step 4- Open up the arduino IDE
Step 5- Go to the files drop down menu and follow this path. File > Examples > MFRC522 > ReadUidMultiReader
Step 2: Assembly
The assembly of the RFID chip to the Arduino will vary slightly from board to board. Every variation of pin mode will be available within the downloadable code, but I will provide the pins that would be used for the Arduino Mega below.
SDA - 53
SCK - 52
MOSI - 51
MISO - 50
GND - GND
RST - 5
3.3V - 3.3V
This list goes in order of left to right (i.e., SDA being the left most, 3.3V being the right most).
Connecting the the RFID to the Arduino is exactly as it appears in the photo above. You simply need to take 7 male to female breadboard jumpers. Use the female end to connect to the pins on the reader, then connect the male end to the corresponding pin on the Arduino board.
The rest of the assembly will depend on how you have decided to apply this project. For example, I added a servo motor to the Arduino, connecting it to a 5V pin and connecting it to pin 2 after setting it as an output pin in the coding. Your project may end here or you may continue on by creating a RFID locked computer, or RFID ID. If using this project for the purpose of teaching the basics of the Arduino or coding, you could create a variation of the downloadable code that is missing some parts of the coding, allowing the students to complete the program in some way. All in all the point of this project is too create a spring board into your creativity. Because you are given the RFID lock, I hope your creativity will allow you to find new way of implementation.