What is the rifd? How you can use in your projects?

Introduction

The radio frequency identification is a method to memorize and retrieve the remote data thanks to electronic chip.

Theses electronics chip contains an unique identifier for each.

This technology of idenitfication can be used to identify :

  • Object, with a bar code for example
  • people, integrated on the passport, transport card or paiement card

A system of radio identification is composed of two entities which communicating together:

 

  • A tag, called tag radio is coded qui numerical data.
  • One RFID reader, also called interrogator

Installation of RFID library

To control your RFID reader, you have to install the library RFID on Arduino IDE. This is the link to download the library : RFID.

Once downloaded, you have to upload it on Arduino IDE. To do that you have to click on “sketch”, then “include library” and “add library”. Choose the folder you have just downloaded:

Once the library downloaded, you can begin to upload the program on the Arduino card.

Display the information of the tag or UID card

In this circuit we will how to display the informations of the tag or UID card on the serial monitor.

Here is the circuit:

This sketch has be done with fritzing. Here is the link for the part if you want to do the circuit by yourself.

To read the tag when it is detected by the RFID reader, you have to copy the following program:

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

#define Reset_PIN   9     //  Pin for the setup of the rfid's reset 
#define Liaison_SPI    10    // Pin for the SPI liaison Pin 
// We initialize the library with the parameter of pin Reset and SPI pin.
MFRC522 mfrc522(Liaison_SPI, Reset_PIN);   
MFRC522::MIFARE_Key key;

void setup() {
  Serial.begin(9600);  // We initialize the serial monitor 
  while (!Serial);     // While the serial monitor is open we do nothing
  SPI.begin();         // We initialize the SPI liaison 
  mfrc522.PCD_Init();  // We initialize the RFID card 
  Serial.println(F("Approach your tag  or UID card to the RFID reader !"));
  
}

void loop() {
  
  // We search if there are other cards
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    delay(50);
    return;
  }
  
  // A new card is now selected 
  
  Serial.print(F("Reading of the UID card or tag"));
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  } 
  Serial.println();
  delay(2000);
}

This is what we can see by approaching the tag to the RFID reader:

Display the information of the tag or UID card

To change the identity of the UID card, the circuit is the same as the previous one (to read the card).

Here is the new program to write a new identity on the card:

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

#define RST_PIN   9     // The pin to setup the reset of the RFID 
#define SS_PIN    10   // Pin  for the SPI liaison 

MFRC522 mfrc522(SS_PIN, RST_PIN);   

/* We create a new UID */
#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}

MFRC522::MIFARE_Key key;

void setup() {
  Serial.begin(9600);  // We initialize the connection with serial monitor 
  while (!Serial);     // We do nothing as long as the serial monitor is open 
  SPI.begin();         // Initialization of the SPI liaison 
  mfrc522.PCD_Init();  // Initialization of the RFID card.
  Serial.println(F("Approach the UID card to your RFID reader !");
  
  // We choose the hexadecimal digits of the UID number
  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }
}

void loop() {
  
   // We search if there are new cards !
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    delay(50);
    return;
  }
  
   // The new card is now selected 
  
    Serial.print(F("Reading of the UID card:"));
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  } 
  Serial.println();

  // We add the new UID
  byte newUid[] = NEW_UID;
  if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
    Serial.println(F("We write on the new card."));
  }
  

  mfrc522.PICC_HaltA();
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    return;
  }
  
  Serial.println(F("Here is the new UID :"));
  mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
  
  delay(2000);
}
Here is what you can have by adding the new UID:

Make a security door system

We will see now how to make a security door system with two leds : first he red led is turn on and when the tag or UID card is approached to the RFID reader , the red LED is turn off and the green LED is turn on.

Here is the program you have to upload on your Arduino card:

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

#define Reset_PIN   9     // Pin to setup the reset of the Rfid 
#define Liaison_SPI    10    // Pin for the SPI liaison 
const int red_led = 3;
const int green_led = 4;

MFRC522 mfrc522(Liaison_SPI, Reset_PIN);   
MFRC522::MIFARE_Key key;

void setup() {
  Serial.begin(9600);  // We initialize the connection with the serial monitor
  while (!Serial);     // We do nothing as long as the serial monitor is open 
  SPI.begin();         // We initialize the SPI liaison Initialisation de la liaison SPI.
  mfrc522.PCD_Init();  // We initialize the Rfid card 
  Serial.println(F("Approach your card or tag to the RFID reader"));
  pinMode(red_led, OUTPUT);
  pinMode(green_led, OUTPUT);
  digitalWrite(red_led, HIGH); //  We turn on the red led as long as the tag or UID card is not approached
  
}

void loop() {
  
  // We search if there are new cards 
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    delay(50);
    return;
  }
  
  // The new card is now selected 
  
  Serial.print(F("Reading of the UID card or tag:"));
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    digitalWrite(red_led, LOW); // We turn off the red led when the tag or UID card is read 
    digitalWrite(green_led, HIGH); // We turn on the green led  
  } 
  Serial.println();
  delay(2000);
}