Home » ESP32 and RFID-RC522 module example

ESP32 and RFID-RC522 module example

by shedboy71

In this example we will connect an RFID-RC522 module and connect to an ESP32 Wemos LOLIN32

The microcontroller and card reader uses SPI for communication . The card reader and the tags communicate using a 13.56MHz electromagnetic field. (ISO 14443A standart tags)

Features:

  • MFRC522 chip based board
  • Operating frequency: 13.56MHz
  • Supply Voltage: 3.3V
  • Current: 13-26mA
  • Read Range: Approx 3cm with supplied card and fob
  • SPI Interface
  • Max Data Transfer Rate: 10Mbit / s
  • Dimensions: 60mm × 39mm

Datasheet for the chip that used in modules can be found at:

http://www.nxp.com/documents/data_sheet/MFRC522.pdf

Layout

esp32 and rfid

esp32 and rfid

Code

Install the RFID522 library – https://github.com/miguelbalboa/rfid

This is the DumpInfo example modified

[cpp]

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

//#define RST_PIN 9 // Configurable, see typical pin layout above
//#define SS_PIN 10 // Configurable, see typical pin layout above
const int RST_PIN = 22; // Reset pin
const int SS_PIN = 21; // Slave select pin

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD – MFRC522 Card Reader details
Serial.println(F(“Scan PICC to see UID, SAK, type, and data blocks…”));
}

void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}

// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

[/cpp]

 

Output

This is the output in the serial monitor

serial monitor info mfrc522

serial monitor info mfrc522

There are many other good examples in the library

 

Links

1 set RFID module RC522 Kits S50 13.56 Mhz 6cm With Tags SPI Write & Read for arduino uno 2560

You may also like

1 comment

ESP32 giao tiếp RC522 (RFID) sử dụng ESP-IDF - ESPITEK 5th September 2019 - 3:51 am

[…] Các thư viện nguồn mở giúp lập trình ESP32 giao tiếp RC522 (RFID)  sử dụng ESP-IDF còn hạn chế, chủ yếu là các thư viện dùng trên Arduino IDE như: Arduino – RC522, ESP32-RC522 […]

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.