Security Access using MFRC522 RFID Reader with Arduino
This blog post shows a simple example on how to use the MFRC522 RFID reader. I’ll do a quick overview of the specifications and demonstrate a project example using an Arduino.
RFID means radio-frequency identification. RFID uses electromagnetic fields to transfer data over short distances. RFID is useful to identify people, to make transactions, etc…
You can use an RFID system to open a door. For example, only the person with the right information on his card is allowed to enter. An RFID system uses:
- tags attached to the object to be identified, in this example we have a keychain and an electromagnetic card. Each tag has his own identification (UID).
- two-way radio transmitter-receiver, the reader, that send a signal to the tag and read its response.
- Input voltage: 3.3V
- Price: approximately 3$ (check best price on Maker Advisor)
- Frequency: 13.56MHz
Here’s the library you need for this project:
- Download the RFID library here created by miguelbalboa
- Unzip the RFID library
- Install the RFID library in your Arduino IDE
- Restart your Arduino IDE
|Pin||Wiring to Arduino Uno|
Caution: You must power this device to 3.3V!
Reading Data from a RFID tag
After having the circuit ready, go to File Examples MFRC522 DumpInfo and upload the code. This code will be available in your Arduino IDE (after installing the RFID library).
Then, open the serial monitor. You should see something like the figure below:
Approximate the RFID card or the keychain to the reader. Let the reader and the tag closer until all the information is displayed.
This is the information that you can read from the card, including the card UID that is highlighted in yellow. The information is stored in the memory that is divided into segments and blocks as you can see in the previous picture.
You have 1024 bytes of data storage divided into 16 sectors and each sector is protected by two different keys, A and B.
Write down your UID card because you’ll need it later.
Upload the following code.
In the piece of code above you need to change the if (content.substring(1) == “REPLACE WITH YOUR UID”) and type the UID card you’ve written previously.
Now, upload the code to your Arduino and open the serial monitor.
Approximate the card you’ve chosen to give access and you’ll see:
If you approximate another tag with another UID, the denial message will show up:
I hope you found this tutorial useful.
Share this post with a friend that also likes electronics!
You can contact me by leaving a comment. If you like this post probably you might like my next ones, so please support me by subscribing my blog.