what is the RFID module and how an RFID module works with Arduino

what is RFID module and how an RFID module works with Arduino?

what is RFID module and how an RFID module works with Arduino

        Hello, Welcome to another valuable article brought to you by SriTu Hobby. Today we are going to talk about what is RFID module and how an RFID module works with Arduino. We can see this technology in different places. That is, examples include identifying people in factories, controlling admissions, searching books in libraries, obtaining employee attendance, and the security system. Also, you can use this technology to create security systems, door lock systems.

What is RFID technology?

RFID is simply called Radio Frequency Identification. That is, to identify radio frequencies. Also, the RFID module is designed using this technology. Different types of RFID modules are given below.

Different types of RFID modules

These RFID modules consist of two main parts.

RFID tagwhat is RFID module and how an RFID module works with Arduino

RFID readerwhat is RFID module and how an RFID module works with Arduino

How to work RFID module

We first talked about how this RFID technology works according to radio frequencies. This RFID reader includes a radio frequency module. Also, the antenna coil included here produces a high-frequency electromagnetic field. This RFID tag is made up of an antenna and electronic microchip. This electronic microchip in the RFID Tag produces a voltage in the antenna coil of the RFID Reader due to the induction of the electromagnetic field generated when it is placed near an RFID Reader. For this reason, an RFID Reader can detect an RFID Tag.

The RFID module we use today is as follows.what is RFID module and how an RFID module works with Arduino

This RFID tag was created using the MIFARE protocol, 1kb of memory, and a microchip for logical purposes. They have an operating frequency of 13.56 MHz and a range of 10cm. Also, this value may vary depending on the antenna in the RFID Tag. Then, if we talk about RFID Reader, it contains an IC called MFRC522. It also uses the SPI protocol to connect to the Arduino board.

PIN structure of this RFID module
what is RFID module and how an RFID module works with Arduino

OK, let’s learn how to connect the RFID module with Arduino step by step. For that, the required components are given below.

Step 1

Firstly, identify these components.

Arduino Nano board

RFID modulewhat is RFID module and how an RFID module works with Arduino

LED bulb

Buzzer

180-ohm resistor

Jumper wires

Breadboard

Step 2

Secondly, connect these components. To do this, use the circuit diagram below.what is RFID module and how an RFID module works with Arduino

Step 3

Thirdly, let’s scan the UIDs related to the RFID tags. To do this, use the program below.

MFRC522 library — Download

/*RFID tag scan code
 * http://srituhobby.com
 */
 
#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;
  }

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

Code explanation

Firstly, the SPI bus and MFRC522 libraries are included.

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

Secondly, the RST and SDA pins are defined.

#define RST_PIN 9
#define SS_PIN 10

Next, an object is created for this library. Also, it includes PINs above.

MFRC522 mfrc522(SS_PIN, RST_PIN);

In the setup function, the serial monitor, SPI bus, and RFID library are started. Also, RFID tags information is printed on the serial monitor.

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

The loop function includes RFID tag read codes.

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

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

Step 4

OK, now select board and port. Afterward, upload this code to the Arduino board.now select board and port. Afterward, upload this code to the Arduino board

now select board and port. Afterward, upload this code to the Arduino board
now select board and port. Afterward, upload this code to the Arduino board
now select board and port. Afterward, upload this code to the Arduino board

Step 5

Next, run your serial monitor and place your RFID tags one by one on the RFID reader. I have used two RFID tags. Next, copy these RFID tag UIDs to another location. These are required for the next program. place your RFID tags one by one on the RFID reader

place your RFID tags one by one on the RFID reader
place your RFID tags one by one on the RFID reader
place your RFID tags one by one on the RFID reader

Step 6

OK, now let’s create the main program for this project. It is as follows.

  • The complete program of this project – Download
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
#define Buzzer 2
#define LED1 3
#define LED2 4

MFRC522 rfid(SS_PIN, RST_PIN);

byte led1 = 0;
byte led2 = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("Please put your card..");
  SPI.begin();
  rfid.PCD_Init();
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(Buzzer, OUTPUT);
}

void loop() {
  if ( ! rfid.PICC_IsNewCardPresent())
    return;
  if ( ! rfid.PICC_ReadCardSerial())
    return;

  Serial.print("NUID tag is :");
  tone(Buzzer, 700);
  delay(200);
  noTone(Buzzer);
  String ID = "";
  for (byte i = 0; i < rfid.uid.size; i++) {
    Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(rfid.uid.uidByte[i], HEX);
    ID.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
    ID.concat(String(rfid.uid.uidByte[i], HEX));
    delay(300);
  }
  Serial.println();
  ID.toUpperCase();

  if (ID.substring(1) == "" && led1 == 0 ) {
    digitalWrite(LED1, HIGH);
    Serial.println("LED1 is ON..");
    led1 = 1;
  } else if (ID.substring(1) == "" && led1 == 1 ) {
    digitalWrite(LED1, LOW);
    Serial.println("LED1 is OFF..");
    led1 = 0;
  } else if (ID.substring(1) == "" && led2 == 0 ) {
    digitalWrite(LED2, HIGH);
    Serial.println("LED2 is ON..");
    led2 = 1;
  } else if (ID.substring(1) == "" && led2 == 1 ) {
    digitalWrite(LED2, LOW);
    Serial.println("LED2 is OFF..");
    led2 = 0;
  } else {
    Serial.print("Wrong card!Please put correct card!");
  }
}

Code explanation

Firstly, it includes the SPI Bus Library and the MFRC 522 Library. Also, RST, SDA, Buzzer, and LED pins are defined.

#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
#define Buzzer 2
#define LED1 3
#define LED2 4

Secondly, an object is created for this library. Also, it includes RST and SDA PINs.

MFRC522 mfrc522(SS_PIN, RST_PIN);

In the setup function, the serial monitor, SPI bus, and RFID library are started. Also, the LED and buzzer pins are set as OUTPUT pins.

void setup() {
Serial.begin(9600);
Serial.println(“Please put your card..”);
SPI.begin();
rfid.PCD_Init();
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(Buzzer, OUTPUT);
}

In loop functions, the main code of this project is included. The first part of this code reads the RFID tag. Then, these RFID tag UIDs are inserted into a string variable.

if ( ! rfid.PICC_IsNewCardPresent())
return;
if ( ! rfid.PICC_ReadCardSerial())
return;

Serial.print(“NUID tag is :”);
tone(Buzzer, 700);
delay(200);
noTone(Buzzer);
String ID = “”;
for (byte i = 0; i < rfid.uid.size; i++) {
Serial.print(rfid.uid.uidByte[i] < 0x10 ? ” 0″ : ” “);
Serial.print(rfid.uid.uidByte[i], HEX);
ID.concat(String(rfid.uid.uidByte[i] < 0x10 ? ” 0″ : ” “));
ID.concat(String(rfid.uid.uidByte[i], HEX));
delay(300);
}
Serial.println();
ID.toUpperCase();

Next, the second part of this code tests this UID using the IF condition. Also, we need to paste the previously copied RFID tag UIDs into this code. For that, use your RFID tag UIDs. Also, we need to paste the previously copied RFID tag UIDs into this code

if (ID.substring(1) == “15 75 FE 28” && led1 == 0 ) {
digitalWrite(LED1, HIGH);
Serial.println(“LED1 is ON..”);
led1 = 1;
} else if (ID.substring(1) == “15 75 FE 28” && led1 == 1 ) {
digitalWrite(LED1, LOW);
Serial.println(“LED1 is OFF..”);
led1 = 0;
} else if (ID.substring(1) == “2A A5 E9 81” && led2 == 0 ) {
digitalWrite(LED2, HIGH);
Serial.println(“LED2 is ON..”);
led2 = 1;
} else if (ID.substring(1) == “2A A5 E9 81” && led2 == 1 ) {
digitalWrite(LED2, LOW);
Serial.println(“LED2 is OFF..”);
led2 = 0;
} else {
Serial.print(“Wrong card!Please put correct card!”);
}

Step 7

Lastly, select board and port, Afterward, upload this code to the Arduino board.

select board and port, Afterward, upload this code to the Arduino board
select board and port, Afterward, upload this code to the Arduino board
select board and port, Afterward, upload this code to the Arduino board

OK, enjoy this tutorial. The full video guide is given below. So, we will meet in the next tutorial.

what is the RFID module and how an RFID module works with Arduino

Similar Posts

Leave a Reply

Your email address will not be published.