RC522 with arduino,RFID with Arduino,RC522 arduino,Arduino rc522

Interfacing of RFID RC522 with Arduino

2.5K Views
40
700
60
25
60
PCBWay

RC522 with arduino,RFID with Arduino,RC522 arduino,Arduino rc522
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:

RC522 with arduino,RFID with Arduino,RC522 arduino,Arduino rc522

  • 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:
RC522 with arduino,RFID with Arduino,RC522 arduino,Arduino rc522
  • The pin configuration is as follows:
RC522 with arduino,RFID with Arduino,RC522 arduino,Arduino rc522
  • 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.

  • 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.

Comments

41

Join the conversation

Reply1

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

2 replies
Reply2.1
Replying to rahulvishwakarma

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!

Reply3

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.

1 reply
1 reply
Reply5

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!

1 reply
1 reply
1 reply
Reply8

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);
}

1 reply
1 reply
Reply18

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();}

Reply21

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

Reply22

Please help me to get the link for downloading RFID reader module library for proteus isis. I'm waiting your response. Thank you.

Reply24

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

Reply27

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?

1 reply
1 reply
Reply29

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