RFID–Radio Frequency Identification

RFID–Radio Frequency Identification

RFID overview

1.The composition of RFID

RFID is mainly composed of a reader or writer and a transponder. The reader or writer is to read and write the transponder. For example, the most common, vehicle card reader. A transponder is an information storage medium in which data can usually be stored for a long period of time. This data can be manipulated by the reader. Transponders come in many different categories depending on the attributes.

2.The working principle of RFID

RFID uses electromagnetic waves for communication. More common in our daily life is the passive transponder. This transponder has no built-in power supply, it is passive and needs to be close to the reader or writer to get enough power supply by the emitted electromagnetic waves for communication. Correspondingly, there’s active transponder which has its own power supply and has no requirement for external power. It can actively send out communication requests.

In addition to the hardware support, RFID requires normal protocol support, such as the common ISO/EC 14443A protocol. Under the constraints of the software protocol, the transponder and the reader or writer can communicate directly.

3.The advantages and disadvantages of RFID

Advantages of RFID are as follows:

  1. RFID equipment has strong anti-interference ability and is hard to damage;
  2. RFID response has a long service life;
  3. Large reading distance;
  4. The data in the transponder can be encrypted;
  5. Large data storage capacity;
  6. The storage information can be modified.

Disadvantages of RFID are as follows:

  1. Data flooding: the data read from the RFID transponder is not all useful, which will inevitably have an impact on the control system;
  2. There is no global standard: countries that use different standards may be unable to operate RFID data, the corresponding QR code does not have this problem, however;
  3. Security issues: Private data in RFID transponders may be read without knowledge;
  4. May be used with malicious purpose: for example, in 2006, there were reports of RFID buffer overflow vulnerability, which may cause the airport terminal information leakage;
  5. High temperature damage: most of the current transponders glue the integrated circuit in the base material, which may causes loose connection at high temperatures.

RFID hardware

1.The hardware of the RFID consists of a reader or writer and a transponder (usually an electronic tag). There are many ways to communicate between the reader or writer and the transponder. Often, which are mutually incompatible, mainly because of the different working frequency bands. The commonly used radio frequency identification bands and their characteristics are shown in the table:

The transponder we use is the MIFARE 1KB passive tag. It operates at 13.56 MHz and follows the ISO/IEC 14443A standard. The reader or writer is MFRC522, which also supports the ISO/IEC14443A/MIFARE standard.

2.RFID reader or writer.

3.RFID transponder.

4.MIFARE 1KB smart card data organization form.

a.Sector Trailer

Sector Trailer is composed of Key A, Key B of 6 Bytes , and Access Bits of 4 Bytes.

Their specific functions are as follows:

Key A: Any time when reading Key A, it will return data 0; Key B is for security verification, it can be used as user data and can be read under some access conditions

Key B: Key B is for security verification, it can be used as user data and can be read under some access conditions.

Access bit: access bit is used to specify the access right of each block of the sector;bit 9 can be used as user data.

b. Manufacturer data

The 0th block of the sector 0 is a special block that stores the manufacturer data. This block is a read-only block and is write protected. Changes to the access bits will not affect the properties of the block.

c. The data block

The 16 bits of 3 blocks (0 sectors only have 2 blocks) in all sectors can be used to store data. These data can be configured as read or write or value block. Value block can be used to implement electronic payment functions (allowing reading, writing, adding, reducing, restoring, and transmitting commands). Value blocks are organized in a fixed format, as shown in the table:

 

The definitions of value and address in the table are as follows.

  1. Value: indicates a 4Byte has a symbolic value, and negative numbers are represented by a complement. For data integrity and security, a value is stored three times in the form of the original code and the complement;
  2. Address: indicates a 1Byte address, which can be used to store the storage address of a block. Also, for data integrity and security, the address is stored four times in the form of the original code and the complement. The value increase, decrease, recovery, and transfer operations will not affect the value of the address, only by writing command can it be modified.

The circuit diagram connection

The MFRC522 supports three types of interfaces. The third-party RFID uses the SPI interface, and the four control lines are described as below:

  1. SCK: serial clock;
  2. MOSI: host (Arduino) output, slave (MFRC522) input;
  3. MISO: host input, slave output;
  4. NSS: slave selection (active low).

The charging system

The implementation of the charging system is very simple, the idea is as follows

  1. Use the key for verification;
  2. Execute the deduction operation;
  3. Output balance;

The code implements the charging system is as follow:

/***********************************************************
File name:  Adeept_RFID.ino
Description:  
RFID is a wireless communication technology that is commonly used in 
automatic identification and target tracking. 
It can operate on target data without contact, 
such as the common public transportation payment 
system and access control system.

Website: www.adeept.com
E-mail: support@adeept.com
Author: Felix
Date: 2019/07/01 
***********************************************************/

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

#define SS_PIN 10
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);        // creat MFRC522 object

void setup() {
  Serial.begin(9600);        //initialize the serial port
  SPI.begin();                //initialize SPI bus
  mfrc522.PCD_Init();        //initialize reader-writer
  Serial.println("Public transport charge system."); //output the payment system message
}

void loop() {
//  int amount=0;
//  char yon;

  //detect if the chip is detected
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  //select a card to operate on
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }

    byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
    if(piccType != MFRC522::PICC_TYPE_MIFARE_MINI
    && piccType != MFRC522::PICC_TYPE_MIFARE_1K
    && piccType != MFRC522::PICC_TYPE_MIFARE_4K){
      Serial.println("Don not works with this cards.");
      return;
    }

  //set the key variable to FFFFFFFFFFFFh
  MFRC522::MIFARE_Key key;
  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }

  //use the fifth data block of the card
  byte valueBlockA = 5;
  byte status;

  //use Key B to verify
  status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, valueBlockA, &key, &(mfrc522.uid));
  if (status != MFRC522::STATUS_OK) {
    Serial.print("Failed,please try again.");
    return;
  }
//perform fee deduction poeration(the amount here is 1)
  status = mfrc522.MIFARE_Decrement(valueBlockA,1);
  if(status != MFRC522::STATUS_OK){
    Serial.print("Failed,please try again.");
    return;
  }
  status = mfrc522.MIFARE_Transfer(valueBlockA);
  if(status != MFRC522::STATUS_OK){
    Serial.print("Failed,please try again.");
    return;
  }

  byte buffer[18];
  byte size = sizeof(buffer);

  //read and output the balance
  status = mfrc522.MIFARE_Read(valueBlockA, buffer, &size);
  long value = (long(buffer[3])<<24) | (long(buffer[2])<<16) | (long(buffer[1])<<8) | long(buffer[0]);
  Serial.println("Success!");
  Serial.print("Balance:"); 
  Serial.println(value, DEC);
  //change card activation status
  mfrc522.PICC_HaltA();
  //stop encrypted transmission
  mfrc522.PCD_StopCrypto1();
}

Usually, the deduction information is displayed on the LED of the vehicle reader. The above example code outputs it to the serial monitor. After downloading the above code to the Arduino development board, open the serial monitor and wait for the output of the public transportation. charging system.

After it prompts the message, the card is ready to be used. As shown in the figure, the result after 5 times of swiping.

It can be seen that the balance is 95 yuan. And system works very well.

Leave a Reply