How can MRC522 RFID Reader Interface to Arduino Uno?



In today's post. I am going to tell you about a very important device. Its name is an RFID device. Learn all about RFID today. What is RFID? How does RFID work? And where is it used and how to interface RFID with Arduino? We will understand everything in an easy language. RFID device has made our life a lot easier. RFID is being used in every field today, from opening the door of a  house to buying goods in the mall. With the discovery of RFID, you can easily open the door of your home, gate or door office, or any object, and you have a special access power. You must have seen that whenever you go to the mall to buy goods and after buying goods.
Recently articles post:- 

Description:- 

RFID is a wireless technology, the complete form of RFID is Radio Frequency Identification. Rfid uses Electromagnetic fields to transfer data for the short term to identify a particular object.

Rfid consists of 2 main parts RFID RC255 reader and RFID tag.

Rfid reader generates the electromagnetic wave and recognizes the information of an object from that generated electromagnetic wave. That means identifying the information hidden in the RFID tag and sending the signal through the microcontroller or processor. For example, if you want to open the door, then you need the right password, if the RFID card has the right password, then the RFID reader will easily open the door by matching the right password of the RFID card.

RFID Card Transfer the data to the RFID reader.

RFID RC255 Reader:- It consists RC255 chip which controls the whole process of the Rfid RC255 reader. It has a 13.56MHZ oscillator which is used for communication between the RFID reader and RFID tag and it has an antenna, whose job is to generate an electromagnetic field and to identify the data hidden in the RFID card from that electromagnetic wave. There is two communication in the RFID reader. It can transmit radio and receive. The RFID reader sends a signal to the tag and then reads the tag's data and response.

RFID Tag:- There are two types of RFID tags, one is of key type and the other is of electromagnetic type. it is a chip inside both types of cards and data is stored inside the chip. Rfid card is a passive element. This means that no power supply is required to run the RFID card. When the tag is close to the RFID reader, then the coil in the tag gets power through the radio wave generated from the RFID reader and then the data inside the chip is received by the RFID reader through the radio wave. And each tag has its own UID.

Specification:- 

1. Frequency range is 13.56MHZ.
2. Data transfer protocols are SPI, I2C, and UART.
3. Operating voltage is 2.5v to 3.3v.
4. Operating current is 13mA to 26mA.
5. Sleep mode(Power down) is 10uA.

RC522 RFID Module Pinout:-

The RC522 RFID reader has a total of 8 pins and their pins are as follows.
 
VCC:- Operating voltage is given in the Vcc pin. Can provide a voltage of 2.5v to 3.3v in it and can give voltage by connecting a 3.3v pin of Arduino. We just have to keep in mind that a 5v supply is not to be given in this pin, if a 5v supply goes out in this pin then the RC255 RFID module can be damaged.

GND:- GND pin is connected to the GND pin of Arduino.

RST:- RST pin is used to reset and power down and turn off the oscillator and input pins are disconnected.

IRQ:- IRQ pin is an interrupt pin for alert microcontroller or processor. When an RFID tag is detected.

MISO/SCL/TX:- MISO pin is master-in-slave-out. When the SPI interface is enabled. And serial clock can use when the I2C interface is enabled. As serial data transmit when UART is enabled.

MOSI:- MOSO pin is master-out-slave-in. When spi interface is enabled.

SCK:- SCK pin synchronized data transmission for output devices.

SS/SDA/RX:- SS pin is serial input when SPI interface is enabled. As serial data can use when the I2C interface is enabled. And serial data receive pins can use when the UART interface is enabled.


RC255 RFID Library Download:-

1.)Download the RFID library
2.)Unzip the RFID library.
3.)Install the RFID library in Arduino ide.

Pin Wiring:-

RC255 RFID   -     Arduino Uno or Arduino Nano
      SDA        -       D10
      SCK        -       D13
      MOSI      -       D11
      MISO      -       D12
      IRQ        -       Not Connected
      GND       -       GND
      RST        -       D8
      3.3v       -       3.3v

Circuit Connection:-     



SDA pin of RFID is connected to digital pin D10 of Arduino Uno. SCk pin of RFID is interfaced to the D13 pin of Arduino and the MOSI pin is connected to the D11 pin of Arduino. MISO pin is connected to the D12 pin of Arduino. IRQ pin of RFID is not needed because the RFID library is not supported. GND pin is connected to the GND pin of Arduino and rst pin is connected to any digital pin for example here RST pin is connected to the D8 pin of Arduino Uno. 3.3v pin is connected to the 3.3v power supply of Arduino.

Reading Information from the Rfid tag:-

Go to the file>Example>Dumpinfo>Upload the code to the Arduino Uno Board.

CODE:-

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9          
#define SS_PIN          10   
     
MFRC522 mfrc522(SS_PIN, RST_PIN);  

void setup() {
Serial.begin(9600);
while (!Serial);
SPI.begin();
mfrc522.PCD_Init();
delay(4);
mfrc522.PCD_DumpVersionToSerial();
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}

void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}

        // Select one of the cards


if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

Open the serial monitor. You will see something as follows below.




RFID tags or key chains close to the RFID reader then after a few times displayed some data on the serial monitor.

This is all information you can read from the RFID cards and including the UID number. You can see all information on each RFID tag in the serial monitor. And also UID number of card in blue color marked. All this data is stored in a chip of RFID tags but the most important is the UID number. Each RFID card is to own a UID number. So note down the UID number.

After writing down the UID number from the RFID card. For example, the UID number of the key chain is 73 4C F3 8BThen open the other code and write down the UID and upload the code. 

#include <SPI.h>
#include <MFRC522.h>
 
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   
 
void setup() 
{
  Serial.begin(9600);  
  SPI.begin();      
  mfrc522.PCD_Init();  
  Serial.println("Approximate your card to the reader...");
  Serial.println();
}
void loop() 
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "73 4C F3 8B") 
  {
    Serial.println("Authorized access");
    Serial.println();
    delay(3000);
  }
 
 else   {
    Serial.println(" Access denied");
    delay(3000);
  }

When the right card is close to the RFID reader then some message is shown on the serial monitor.



And When the wrong card is close to the RFID reader then some message is shown on the serial monitor.

You can easily access or be denied through your card like that.



Post a Comment

0 Comments