0% found this document useful (0 votes)
23 views

RF Tag

This document provides an example code for reading RFID tags with an Arduino and MFRC522 RFID reader module. The code includes importing the necessary SPI and RFID libraries, defining the pin connections, initializing the RFID reader in setup, and a loop to read the card serial number when a tag is detected and print it to the serial monitor. The code is then expanded to also control an output pin for access control, flashing an LED and printing a message when the detected serial number matches a predefined authorized tag ID.

Uploaded by

anurag kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

RF Tag

This document provides an example code for reading RFID tags with an Arduino and MFRC522 RFID reader module. The code includes importing the necessary SPI and RFID libraries, defining the pin connections, initializing the RFID reader in setup, and a loop to read the card serial number when a tag is detected and print it to the serial monitor. The code is then expanded to also control an output pin for access control, flashing an LED and printing a message when the detected serial number matches a predefined authorized tag ID.

Uploaded by

anurag kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MFRC522 With Arduino Wiring Diagram

https://miliohm.com/mfrc522-rfid-reader-with-arduino-tutorial-the-simplest-way-to-read-rfid-tag/

Libraries used: RFID

After downloading the two libraries above, we can start the code. And here’s the
example code of how to read the RFID tag and print that to the serial monitor.

#include <SPI.h>

#include <RFID.h>

#define SS_PIN 10

#define RST_PIN 9

RFID rfid(SS_PIN, RST_PIN);

String rfidCard;
void setup() {

Serial.begin(9600);

Serial.println("Starting the RFID Reader...");

SPI.begin();

rfid.init();

void loop() {

if (rfid.isCard()) {

if (rfid.readCardSerial()) {

rfidCard = String(rfid.serNum[0]) + " " + String(rfid.serNum[1])


+ " " + String(rfid.serNum[2]) + " " + String(rfid.serNum[3]);

Serial.println(rfidCard);

rfid.halt();

In this example, we will use a tag with the serial number “119 38 185 95” as the right tag.
Or the key. You can edit this serial number in the code below.

#include <SPI.h>
#include <RFID.h>
#define SS_PIN 10
#define RST_PIN 9
RFID rfid(SS_PIN, RST_PIN);

String rfidCard;

void setup() {
Serial.begin(9600);
Serial.println("Starting the RFID Reader...");
SPI.begin();
rfid.init();
pinMode(8, OUTPUT);
}

void loop() {
if (rfid.isCard()) {
if (rfid.readCardSerial()) {
rfidCard = String(rfid.serNum[0]) + " " + String(rfid.serNum[1]) + " " +
String(rfid.serNum[2]) + " " + String(rfid.serNum[3]);
Serial.println(rfidCard);
if (rfidCard == "99 234 79 166") {
digitalWrite(8, HIGH);
delay(100);
digitalWrite(8, LOW);
delay(100);
digitalWrite(8, HIGH);
delay(100);
digitalWrite(8, LOW);
delay(100);
digitalWrite(8, HIGH);
delay(100);
digitalWrite(8, LOW);
delay(100);
Serial.println("Access Granted");
}
else if (rfidCard == "115 14 213 67") {
digitalWrite(8, HIGH);
delay(100);
digitalWrite(8, LOW);
delay(100);
digitalWrite(8, HIGH);
delay(100);
digitalWrite(8, LOW);
delay(100);
digitalWrite(8, HIGH);
delay(100);
digitalWrite(8, LOW);
delay(100);
Serial.println("Access Granted");
} else {
digitalWrite(8, HIGH);
delay(2000);
digitalWrite(8, LOW);
Serial.println("Access Denied");
}
}
rfid.halt();
}
}

You might also like