laitimes

Read how to use MFRC522 RFID reader

Read how to use MFRC522 RFID reader

RFID overview

RFID stands for Radio Frequency Identification. RFID uses electromagnetic fields to transmit data over short distances. RFID can be used to identify people, conduct transactions, etc... An RFID system can be used to open the door. For example, only those with the correct information on the card can enter. RFID systems use:

  • A tag is attached to the object to be identified. Each label has its own identification (UID).
Read how to use MFRC522 RFID reader

Pin wiring

Pins Wiring with Arduino Uno
SDA Number 10
SCK Number 13
MOSI Number 11
MISO Number 12
IRQ Not connected
GND earthing
RST Number 9
3.3V 3.3V
Read how to use MFRC522 RFID reader
#include <SPI.h>
#include <MFRC522.h>
 
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   // 生成MFRC522 实例
 
void setup() 
{
  Serial.begin(9600);   /
  SPI.begin();      // I  SPI 总线测试
  mfrc522.PCD_Init();   // MFRC522初始化
  Serial.println("Approximate your card to the reader...");
  Serial.println();

}
void loop() 
{
  // 等待新卡
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }

  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //显示UID
  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) == "BD 31 15 2B") //更改为使用卡的 UID
  {
    Serial.println("Authorized access");
    Serial.println();
    delay(3000);
  }
 
 else   {
    Serial.println(" Access denied");
    delay(3000);
  }
} 
           

Review the original code

Approximate the card you choose to grant access to, and you will see:

Read how to use MFRC522 RFID reader

If you use another UID to approximate another label, a reject message is displayed:

Read how to use MFRC522 RFID reader
Read how to use MFRC522 RFID reader