Hello friends, hope you all are fine and having fun with your lives. Today’s post is about interfacing of RFID module RC522 with Arduino. RC522 is very simple yet effective module. It is an RFID module and is used for scanning RFID cards. Its a new technology and is expanding day by day. Now-a-days it is extensively used in offices where employees are issued an RFID card and their attendance is marked when they touch their card to rfid reader. We have seen it in many movies that when someone places ones card over some machine then door opens or closes. In short, its a new emerging technology which is quite useful.
I recently get a chance to work on a project in which I have to use RFID reader to scan cards. In this project I have used it for for student attendance so I thought to share it on our blog so that other engineers could get benefit out it.
Let’s first have a little introduction of RFID and then we will look into how to interface RC522 with Arduino. RFID is the abbreviation of Radio frequency identification. RFID modules use electromagnetic fields to transfer data between card and the reader. Different tags are attached to objects and when we place that object in front of the reader, the reader reads that tags.Another benefit of RFID is that it doesn’t require to be in a line of sight to get detected. As in barcode, the reader has to be in the line of sight to the tag and then it can scan but in RFID there’s no such restriction. So, let’s get started with Interfacing of RFID RC522 with Arduino.
You should also read:
Interfacing of RFID RC522 with Arduino.
Now let’s start with the interfacing of RFID RC522 with Arduino. There are many different RFID modules available in the market. The RFID module, which I am gonna use in this project, is RFID-RC522. Its quite easy to interface and works pretty fine. This module has total 8 pins as shown in the below figure:
- SDA
- SCK
- MOSI
- MISO
- IRQ
- GND
- RST
- 3.3V
It normally works on SPI protocol, when interfaced with Arduino board. Interfacing of Arduino and RC522 module is shown in below figure:
- The pin configuration is as follows:
- Now, I suppose that you have connected your RFID module with Arduino as shown in above figure and table, which is quite simple. You just need to connect total 7 pins, IRQ is not connected in our case.
- Now next step is the coding, so first of all, download this Arduino library for RFID RC522 module.
Note:
- Its a third party library, we haven’t designed it, we are just sharing it for the engineers.
Download Arduino Library for RFID
- Now coming to the final step. Upload the below code into your Arduino UNO.
#include <SPI.h>
#include <MFRC522.h>#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN);void setup()
{SPI.begin();
mfrc522.PCD_Init();
}void loop() {
RfidScan();
}void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? ” 0″ : ” “);
Serial.print(buffer[i], HEX);
}
}void RfidScan()
{
if ( ! mfrc522.PICC_IsNewCardPresent())
return;if ( ! mfrc522.PICC_ReadCardSerial())
return;
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
}
- Now using this code, you can read the RFID no of your card quite easily. Now the main task is to use that number and distinguish them so for that I changed the dump_byte_array function a little, which is given below:
#include <SPI.h>
#include <MFRC522.h>#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN);
int RfidNo = 0;void setup()
{SPI.begin();
mfrc522.PCD_Init();
}void loop() {
RfidScan();
}void dump_byte_array(byte *buffer, byte bufferSize)
{
Serial.print(“~”);
if(buffer[0] == 160){RfidNo = 1;Serial.print(RfidNo);}
if(buffer[0] == 176){RfidNo = 2;Serial.print(RfidNo);}
if(buffer[0] == 208){RfidNo = 3;Serial.print(RfidNo);}
if(buffer[0] == 224){RfidNo = 4;Serial.print(RfidNo);}
if(buffer[0] == 240){RfidNo = 5;Serial.print(RfidNo);}
Serial.print(“!”);
while(1){getFingerprintIDez();}
}void RfidScan()
{
if ( ! mfrc522.PICC_IsNewCardPresent())
return;if ( ! mfrc522.PICC_ReadCardSerial())
return;
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
}
- Now using the first code I get the card number for all RFID cards and then in second code I used these numbers and place the check now when first card will be placed it will show 1 on the serial port and so on for other cards.
- So, what you need to do is to use the first code and get your card number and then place them in second code and finally distinguish your cards.
- Quite simple and easy to work.
- Hope I have explained it properly but still if you get any problem ask me in comments.
Hi, I keep getting the errors Arduino: 1.6.6 (Windows 10), Board: “Arduino/Genuino Uno”
RFID_01:22: error: stray ‘\342’ in program
Serial.print(buffer[i] < 0x10 ? � 0" : � “);
^
RFID_01:22: error: stray '\200' in program
RFID_01:22: error: stray '\235' in program
RFID_01:22: error: missing terminating " character
C:\Users\skiidoggy\Documents\Arduino\RFID_01\RFID_01.ino: In function 'void loop()':
RFID_01:16: error: 'RfidScan' was not declared in this scope
RfidScan();
^
C:\Users\skiidoggy\Documents\Arduino\RFID_01\RFID_01.ino: In function 'void dump_byte_array(byte*, byte)':
RFID_01:23: error: expected ':' before 'Serial'
Serial.print(buffer[i], HEX);
^
RFID_01:23: error: expected ')' before ';' token
Serial.print(buffer[i], HEX);
^
exit status 1
stray '\342' in program
i have the same problem. it is showing error “stray ‘342’ in program”.
I had the same problem and found that there is an issue with the font or something during the copy/paste process in regards to the double quotes. So, just remove the 4 double quotes and type them again in your code which should resolve that problem!
This is caused by using Cut and Paste on the code, to following characters are incorrectly copied:
Serial.print(“!”);
should be
Seria.print(“!”);
Note the ” ” the ones copied are unicode characters and cause the error ‘\342’
Is it possible to connect multiple readers to a single arduino? If so how can that be done. I can get one to work just find, once I introduce another I get no response.
Hi,
Yes you canconnect multiple RFID with Arduino. In this case you need to add a virtual SPI port. Add me on Skype and we will discuss it in detail. My skype id is theeenggprojects.
Thanks.
I can not download , please link active
thanks very helpful
I have the same problem. It just takes you to the same website.
Hi! First of all, thanks for the project! I’m trying to start ‘playing’ with Arduino and this RFID module was the chosen one to be the first. I’ve uploaded the code to my UNO but I’m not able to see the card numbers anywhere. Tried to use the Serial Monitor, but nothing happens. How/Where can I see this? Thanks in advance!
You should use the first code given in the article. This code will give you the RFID value of card in your Serial Monitor. In the second code, place that card value in the code and it will place the check.
where exactly in the 2nd code do i put the card no received from the first code?
HI SIR…. I CONT DOWNLOAD THE RFID LIBRARY FILE IN PROTEUS ….PLZ HELP ME
did you solved or not yet ?! because i have the same here
can anyone suggest pin configuration for arduino nano for rfid 522?
in setup I added
Serial.begin(9600); // vince added
Otherwise I got nothing out.
Also made additional changes to help readablity
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
// Serial.print(buffer[i] < 0x10 ? ” 0″ : ” “);
Serial.print(buffer[i] println
}
Serial.println(); // vince added
}
void RfidScan()
{
if ( ! mfrc522.PICC_IsNewCardPresent())
return;
if ( ! mfrc522.PICC_ReadCardSerial())
return;
Serial.println(“MFRC55 buffer”); // vince added
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
}
sir is there any way of scanning of multiple rfid tags with rc522 and arduino uno?
if yes plz tell me the way and code….plz
hello mister, my name is Sony, i cant download header for this program, can you help me?
is there any possibility of scanniing 2 tags simultaneously with rc522?i want to scan multiple tags at a time……
I never tried but i think yeah you can do it, it takes usec to scan so it will be like one after another but real quick.
I got error:’getFingerprintIDez’ was not declared in this scope
while(1){getFingerprintIDez();}
I am new in this AdrIUno
Cheers
Why doesn’t the download button work? If somebody gave the link it would be helpful.
The download link is down, please link active. Thank’s!
where is the library , only page reload when i click on the download button
I need wifi 60 relay controll circuit
with cod
can you help me ????????
Yeah add me on Skype and we will discuss it out.
In your second code can please tell me that where to place the id of my tag ?
Hi, i have this error message; can you help me?, please
Arduino:1.8.3 (Windows 10), Tarjeta:”Arduino/Genuino Uno”
C:\Users\Juan Figueroa!\Documents\Arduino\LECTOR\lector2\lector2.ino: In function ‘void dump_byte_array(byte*, byte)’:
lector2:29: error: ‘getFingerprintIDez’ was not declared in this scope
while(1){getFingerprintIDez();}
I got error:’getFingerprintIDez’ was not declared in this scope
while(1){getFingerprintIDez();}
unable to find you on skype
exit status 1
‘getFingerprintIDez’ was not declared in this scope
what to do for this
Arduino: 1.8.4 (Windows 10), Board: “Arduino/Genuino Uno”
C:\Users\admin\Documents\Arduino\sketch_aug31a\sketch_aug31a.ino:2:21: fatal error: MFRC522.h: No such file or directory
#include
^
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno.
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
this error is coming while verifying this code, can u help me with this
Please help me to get the link for downloading RFID reader module library for proteus isis. I’m waiting your response. Thank you.
Please help me to get the link for downloading RFID reader module library for proteus isis. I’m waiting your response.
Hi sir I tried to interface it with gsm sim 900a
,but I am unable to send two message to two different number it’s just send to one number in case of first tag being read,so how can I send in case of each tag being read send SMS to specific number
umm there is no download content
i click the button and it duplicates this site
how to write a no. on the card? ((If its the second code i am unable to figure out hoe you wrote so on the card)) Please help me out!
Hai, i am new to this field. I want to ask how to do this project on proteus because the rc522 component was absent in the proteus lib. Anyone know where to download the rc522 for proteus?
Hi,
It’s quite difficult to design RC522 in Proteus so you have to work on hardware directly. 😛
Thanks.
I am a student and I am looking for the rfid library rc522 for proteus
Hi,
We haven’t designed it yet.
Thanks.
DUINOTECH RFID-RC522
+
ARDUINO UNO v3
PINOUT:
RC522 UNO
VCC 5v
RST pin ~5 (digitial PWM~)
GND GND
MISO pin 12
MOSI pin 11
SCK pin 13
NSS pin 10
Install Library MRFC522
have used most of the included example sketches successfully.
I accidentally used 5v instead of 3.3v due to bad print on the UNO board
and found that it didnt work on 3.3v after HOWEVER: I had tried two seperate
USB lilypad ARDUINO’s and a NANO at 3.3v and all to no avail. 5v was the first time
I saw it work and only time.
Pan0ptiK:DCN3T
hi! is it possible to use the rfid as an input device then the ouput will be sent through sms by a gsm module?if yes, how will the code be?thanks!