Free Shipping over ₹1199

ESP32-S3 RFID with Arduino IDE

Introduction

The MFRC522 is a popular RFID module that communicates via SPI to read RFID/NFC tags.
It is widely used in access control, attendance systems, and automation projects.
The ESP32-S3 DevKit-N16R8 supports SPI communication, making it easy to interface with the MFRC522 and read tag data.
In this tutorial, we’ll connect the MFRC522 RFID reader to the ESP32-S3 and read RFID tag data for further processing.

Required Components

  • ESP32-S3 Board
  • RFID Module with tags
  • Jumper wires
  • Breadboard

Pinout

Circuit Diagram / Wiring

  • RFID SENSOR VCC → 3.3V (ESP32-S3)
  • RFID SENSOR GND → GND (ESP32-S3)
  • RFID SENSOR SDA  → GPIO 10 (ESP32-S3)
  • RFID SENSOR SCK  → GPIO 36 (ESP32-S3)
  • RFID SENSOR MOSI → GPIO 35 (ESP32-S3)
  • RFID SENSOR MISO  → GPIO 37 (ESP32-S3)
  • RFID SENSOR RST  → GPIO 9 (ESP32-S3)

Code / Programming

  • Install Required Library (via Arduino Library Manager).
  • Go to the “Libraries” tab on the left-hand side of the screen.
  • Click on the “Library Manager” button (book icon) at the top of the Libraries tab.
  • In the Library Manager window, type “MFRC522” in the search bar.
  • Locate the “MFRC522” library click on the “Install” button next to it.
  • Wait for the library to be installed, and you’re ready to use the MFRC522 library in your projects.
/*
Filename: esp32s3_rfid_reader_uid.ino  
Description: Reads RFID card using MFRC522 module and prints UID via Serial Monitor on ESP32-S3 DevKit-N16R8  
Author: www.oceanlabz.in  
Modified: 1/4/2025
*/

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

// Recommended SPI Pins for ESP32-S3 (can be changed)
#define RST_PIN 9    // Reset pin for MFRC522
#define SS_PIN 10      // SDA / Slave Select (adjusted to avoid default I2C pins 20/21)

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

void setup() {
  Serial.begin(115200);
  delay(1000);
  
  SPI.begin(36, 37, 35, SS_PIN);  // SCLK=36, MISO=37, MOSI=35, SS=10
  mfrc522.PCD_Init();
  
  Serial.println("Place your RFID card near the reader.");
}

void loop() {
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
    Serial.print("UID tag: ");
    for (byte i = 0; i < mfrc522.uid.size; i++) {
      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
      Serial.print(mfrc522.uid.uidByte[i], HEX);
      Serial.print(" ");
    }
    Serial.println();
    mfrc522.PICC_HaltA();  // Stop reading this card
    mfrc522.PCD_StopCrypto1();  // Stop encryption (recommended cleanup)
  }
}

Explanation

  • mfrc522.PCD_Init() initializes the MFRC522 reader using SPI.
  • When a card is detected, its UID is read and printed on the Serial Monitor.
  • mfrc522.PICC_HaltA() ends communication after UID is read.

Troubleshooting

  • Use available SPI pins: MOSI (GPIO 35), MISO (GPIO 37), SCK (GPIO 36), and choose a valid SDA (SS) and RST like SDA = GPIO 10, RST = GPIO 9.
  • Confirm the card/tag is 13.56 MHz and held close to the reader (2–5 cm).
  • Power the MFRC522 with 3.3V only (not 5V), and check Serial Monitor baud rate = 115200.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Need Help?