Arduino ProjectsEsp32 ProjectsEsp8266 Projects
RC-522 RFID Interfacing With ARDUINO, ESP8266 & ESP32
RC-522 RFID Interfacing With ESP32
Introduction
Hi, In this tutorial, we will Interfacing The RC-522 RFID Module To Arduino Nano, ESP8266 And ESP32 Microcontroller.
We will explain Step By Step Like How You Add a library In Arduino IDE Software and How You Find out The card Number In The Serial Monitor is Very Easy Just Flow The article and do the same.
- RC522 RFID Modules work on 13.56MHz which is based on the MFRC522 controller which NXP Semiconductor designs.
- The RC522 module supports SPI and I2C communication protocols.
- Here we use the SPI communication Interface with the Arduino, ESP8266 & ESP32 Board. This module operates on a +3.3V/13-26mA Power Supply.
- The RFID reader automatically goes to power save mode after its operation is complete and it takes a 10-13mA standby current.
We can use this RFID for inventory management, attendance system, access control system, Door Lock Systems, etc.
if you are interested in more RFID Based Projects
Bill of Materials
S.N | Component | Quantity | LINK To BUY |
1 | RC-522 RFID Module | 1 | |
2 | Arduino Nano | 1 | |
3 | ESP8266 | 1 | |
4 | ESP32 | 1 |
Circuit Diagram
RC-522 RFID With Arduino Nano Board
RC-522 RFID With ESP8266 Board
RC-522 RFID With ESP32 Board
Source Code
The first is required to add Library Fist MRFC522
Code For Arduino Nano with RFID
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#include <SPI.h> #include <MFRC522.h> byte ReadCard[4]; int ScanDone; MFRC522 mfrc522(10, 9); MFRC522::MIFARE_Key key; void setup() { Serial.begin(9600); SPI.begin(); mfrc522.PCD_Init(); Serial.println("RFID initiated."); Serial.println("Please Tab your Card to the RFID Reader"); do { ScanDone = scan_UID(); } while (!ScanDone); } void loop() { scan_UID(); } int scan_UID() { if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } if ( ! mfrc522.PICC_ReadCardSerial()) { return; } Serial.print("Hi, Your Card UID is: "); for (int i = 0; i < mfrc522.uid.size; i++) { ReadCard[i] = mfrc522.uid.uidByte[i]; Serial.print(ReadCard[i], HEX); } Serial.println(""); mfrc522.PICC_HaltA(); } |
Code For ESP8266 With RFID
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#define SS_PIN 4 //D2 #define RST_PIN 5 //D1 #include <SPI.h> #include <MFRC522.h> MFRC522 mfrc522(SS_PIN, RST_PIN); int statuss = 0; int out = 0; void setup() { Serial.begin(9600); SPI.begin(); mfrc522.PCD_Init(); } void loop() { if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } if ( ! mfrc522.PICC_ReadCardSerial()) { return; } Serial.println(); Serial.print(" UID tag :"); String content= ""; byte letter; for (byte i = 0; i < mfrc522.uid.size; i++) { Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); Serial.print(mfrc522.uid.uidByte[i], HEX); content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); content.concat(String(mfrc522.uid.uidByte[i], HEX)); } content.toUpperCase(); Serial.println(); if (content.substring(1) == "xx xx xx xx") { Serial.println(" Access Granted "); Serial.println(" Welcome to"); delay(1000); Serial.println(" justdoelectronics "); Serial.println(); statuss = 1; } else { Serial.println(" Access Denied "); delay(3000); } } |
Code For ESP32 With RFID
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
#include <SPI.h> #include <MFRC522.h> #define SS_PIN 21 #define RST_PIN 22 MFRC522 rfid(SS_PIN, RST_PIN); MFRC522::MIFARE_Key key; byte nuidPICC[4]; void setup() { Serial.begin(9600); SPI.begin(); rfid.PCD_Init(); for (byte i = 0; i < 6; i++) { key.keyByte[i] = 0xFF; } Serial.println(F("........................")); Serial.print(F("Using the following key:")); printHex(key.keyByte, MFRC522::MF_KEY_SIZE); } void loop() { if ( ! rfid.PICC_IsNewCardPresent()) return; if ( ! rfid.PICC_ReadCardSerial()) return; Serial.print(F("PICC type: ")); MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak); Serial.println(rfid.PICC_GetTypeName(piccType)); if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI && piccType != MFRC522::PICC_TYPE_MIFARE_1K && piccType != MFRC522::PICC_TYPE_MIFARE_4K) { Serial.println(F("Your tag is not of type MIFARE Classic.")); return; } if (rfid.uid.uidByte[0] != nuidPICC[0] || rfid.uid.uidByte[1] != nuidPICC[1] || rfid.uid.uidByte[2] != nuidPICC[2] || rfid.uid.uidByte[3] != nuidPICC[3] ) { Serial.println(F("A new card has been detected.")); for (byte i = 0; i < 4; i++) { nuidPICC[i] = rfid.uid.uidByte[i]; } Serial.println(F("The NUID tag is:")); Serial.print(F("In hex: ")); printHex(rfid.uid.uidByte, rfid.uid.size); Serial.println(); Serial.print(F("In dec: ")); printDec(rfid.uid.uidByte, rfid.uid.size); Serial.println(); } else Serial.println(F("Card read previously.")); rfid.PICC_HaltA(); rfid.PCD_StopCrypto1(); } void printHex(byte *buffer, byte bufferSize) { for (byte i = 0; i < bufferSize; i++) { Serial.print(buffer[i] < 0x10 ? " 0" : " "); Serial.print(buffer[i], HEX); } } void printDec(byte *buffer, byte bufferSize) { for (byte i = 0; i < bufferSize; i++) { Serial.print(buffer[i] < 0x10 ? " 0" : " "); Serial.print(buffer[i], DEC); } } |
If you Interested in More ESP32 Projects