Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Voltaat Arduino Ultimate Kit
60 min
Share

Getting card ID using RFID reader

RFID reader is a sensor that can read cards IDs. In this tutorial, you’ll learn how to use RFID readers to obtain card ID information.

Project Video

Overview

We will learn how to read the card ID using an RFID reader, and then display the result on your computer. One useful application of getting card ID is creating an attendance system for employers. When an employer scans their card with an RFID reader, the system saves the date and time of attendance, making it easy to keep track of employee attendance.

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
RFID Kit
Get Item
Jumper Wires - Male to Male (40 Pack)
Get Item

Steps

Wiring it Up

Connect the RFID reader to the Arduino by following the wiring diagram shown in the image below.

 Connections from the RFID reader to the Arduino:


 • RFID 3.3V pin → Arduino VCC (3.3V) pin


 • RFID RST pin → Arduino pin 9


 • RFID GND pin → Arduino GND pin


 • RFID IRQ pin → unconnected


 • RFID MISO pin → Arduino pin 12


 • RFID MOSI pin → Arduino pin 11


 • RFID SCK pin → Arduino pin 13


 • RFID SDA pin → Arduino pin 10

Coding

/*
 Voltaat learn (http://learn.voltaat.com)
 Link for full tutorial:
 RFID reader library:

 Tutorial: Getting card ID using RFID reader

 It's important to be aware that the RFID reader module runs on 3.3V, not 5V.
 Therefore, it should be connected to the 3.3V pin.

 Connections from the RFID reader to the Arduino:
 • RFID 3.3V pin → Arduino VCC (3.3V) pin
 • RFID RST pin → Arduino pin 9
 • RFID GND pin → Arduino GND pin
 • RFID IRQ pin → unconnected
 • RFID MISO pin → Arduino pin 12
 • RFID MOSI pin → Arduino pin 11
 • RFID SCK pin → Arduino pin 13
 • RFID SDA pin → Arduino pin 10
 
*/

#include "MFRC522.h"   // Include the MFRC522 RFID library

#define SS_PIN 10       // Define the SS pin for the RFID reader
#define RST_PIN 9       // Define the RST pin for the RFID reader

MFRC522 rfid(SS_PIN, RST_PIN);  // Create an MFRC522 instance

void setup() {
 Serial.begin(9600);   // Initialize serial communication
 SPI.begin();          // Initialize SPI
 rfid.PCD_Init();      // Initialize RFID reader
 Serial.println("RFID Reader Initialized");
 Serial.println("Please approximate your card to the RFID reader...");
}

void loop() {
 // Check for new RFID cards
 if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) {
   // Get the card UID
   String cardUID = "";
   for (byte i = 0; i < rfid.uid.size; i++) {
     cardUID += String(rfid.uid.uidByte[i], HEX);
     if (i < rfid.uid.size - 1) {  // Add space between bytes except for the last byte
       cardUID += " ";
     }
   }

   Serial.print("Card ID: ");
   Serial.println(cardUID);
   rfid.PICC_HaltA();  // Halt the card
   rfid.PCD_StopCrypto1(); // Stop encryption on the card
 }
}

Testing it Out

Make sure to choose the right baud rate (9600).
know when your plant needs watering

After connecting the RFID reader to the Arduino and uploading the code, open the serial monitor by clicking on its icon.

know when your plant needs watering

The serial monitor will instruct you to scan the card with the RFID reader.

know when your plant needs watering

When you scan a card with the RFID reader, the serial monitor will display its ID. You can rescan the card to view the ID again, or scan multiple cards or tags to display their IDs.

know when your plant needs watering

Resources

No items found.