Arduino RFID Lock Tutorial
Arduino RFID Lock Tutorial
by educ8s
Dear friends welcome to another Instructable. This is UID of the tag is equal to a predefined value that is
Nick from educ8s.tv and today we are going to learn stored in Arduino’s memory, then in the display we
how to use this RFID Reader with Arduino in order to are going to see the “Unlocked” message. If the
build a simple lock system. Unique ID of the card is not equal to the predefined
value, the Unlock message won’t appear. Cool isn’t
For the first time, we are going to use RFID tags with it?
Arduino. I have built a simple project which reads the
Unique ID (UID) of each RFID tag we place close to There is a lot to cover, so let's get started!
the reader and displays it on this OLED display. If the
https://www.youtube.com/watch?v=So83sH6-jwM
Optional Parts:
Powerbank http://educ8s.tv/part/Powerbank
Each RFID tag has a small chip inside. If I place a That’s the UID that we display on the OLED display.
flashlight under this RFID card you can see the small Except from this UID, each tag can store data. In this
chip and the coil that surrounds it. This chip does not type of cards we can store up to 1K of data!
have a battery in order to get power. It receives power Impressive isn’t it? We won’t use this functionality
from the reader, this device, wirelessly using this big today but will do so in a future Instructable. Today, all
coil. The reader can read an RFID card like this one we are interested in is to identify a specific card by its
from a distance up to 20mm! UID. The cost of the RFID reader and these two RFID
cards is around $4.
The same chip exists in keychain RFID tags as well.
https://www.youtube.com/watch?v=A9EwJ7M7OsI
The connection with the Arduino Uno board is very IRQ Unconnected
simple. At first, let’s connect the power of both the
reader and the display. MISO Digital Pin 12
In order the project code to compile we need to include some libraries. First of all, we need the MFRC522 Rfid
library. In order to install it, go to Sketch -> Include Libraries -> Manage libraries. Search for MFRC522 and install
it. We also need the Adafruit SSD1306 library and the Adafruit GFX library for the display. Install both libraries with
the same procedure. The Adafruit SSD1306 library needs a small modification. Go to the Arduino -> Libraries
folder, open the Adafruit SSD1306 folder and edit the Adafruit_SSD1306.h library. Comment line 70 and
uncomment line 69. Our display has a resolution of 128x64, that’s what we are defining here. Now we are ready to
take a quick look at the code.
At first, we declare the value of the RFID tag that we want the Arduino to recognize. It is an array of integers.
rfid.PCD_Init();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
After this, in the loop function, we check for a tag on the reader every 100 ms.
If there is a tag on the reader we read its UID and we print it on the display. Next, we compare the UID of the tag
we just read, with the value that is stored in the code variable. If the values are the same, we display the UNLOCK
message, else we don’t display this message.
if(match)
{
Serial.println("\nI know this card!");
printUnlockMessage();
}else
{
Serial.println("\nUnknown Card");
}
Of course, you can modify this code in order to store more than 1 UID values in order the project to recognize
more RFID tags.
This is just an example. As always you can find the code of the project attached to this Instructable.
As you can see with a very low cost we can add an In a future video, we will also try to write and read
RFID reader to our projects. We can easily build a data from an RFID tag. At this point, I would love to
security system with a reader like this one or build hear your opinion about this RFID card reader. Do
more fun projects. you plan to use it in any of your projects? Please post
any comments or ideas in that comments section
My main intention is to build some interactive games below, thanks!
for kids using this RFID reader and a lot of RFID tags.
Nice tutorial ! i made it for two rfid cards. Thanks and keep it going !