Site Guide

Find your way around the Engineering Club.

Know what you need? Search for a component, concept or project.

Around the site

Start

Labs

TestingExperimental

Build

Club

LearnExperimental

Go a little deeper

Entry points to larger collections. Use Search for individual records.

Learning paths & reference

Inside PiCrawlerExperimental

Inside Inventory

← Mega Components

ELEGOO MEGA · LESSON 21

RC522 RFID Module

Read a tag’s UID, with the supplied UID-writing experiment kept as a separate option.

Use Mega SPI pins and distinguish reading an identifier from writing a tag.

Choose a variant

Read UID only

Parts List

  • ELEGOO Mega 2560 R3 is a 5 V ATmega2560 AVR board with many I/O pins and four hardware UARTs for control systems with several peripherals. Long ELEGOO-branded Mega PCB with USB-B and barrel connector, ATmega2560 marking, extended side headers and a large double-row digital header at the end. Read printed Mega labels; its SPI hardware placement is not the same numeric pins as an Uno.
  • A USB-A to USB-B cable carries USB power and, when its data conductors are present, a host/device data link. USB-A plug and square USB-B plug. Inspect the plug shape; micro-USB is not USB-C, and USB-B is the squarer device connector.
  • An 830-contact solderless breadboard joins inserted leads through hidden spring strips so circuits can be rebuilt without solder. Full-size rectangular board, center channel, numbered five-hole terminal groups and side power rails. Counted contact holes are not component units.
  • An RC522-compatible reader uses 13.56 MHz near-field coupling to communicate with supported passive RFID cards and fobs. Flat carrier with a large rectangular printed antenna loop, MFRC522/RC522 marking and a signal header. Match input/output pin legends to the configured host interface.
  • A passive RFID card stores an identifier and tag-dependent data for contactless reader experiments. Flat white plastic card without exposed contacts. Neither enclosure identifies the silicon.
  • 100 nF nonpolar ceramic capacitor stores electric-field energy. Local IC decoupling and short high-frequency supply disturbances are appropriate uses when voltage and circuit requirements are checked. Small non-polar disc, often marked 104; 104 means 100 nF, not 104 pF. Read the value and rating rather than estimating from body size.
  • Male-to-male jumper leads make removable point-to-point connections for low-current prototype signals. Pins at both ends; count individual leads rather than ribbon groups. Check intact insulation and snug contacts before use.
  • Male-to-female jumper leads make removable point-to-point connections for low-current prototype signals. Pin at one end and socket at the other. Check intact insulation and snug contacts before use.
  • The AstroAI meter measures electrical quantities through selectable probe circuits; its exact model, fuse arrangement and safety category remain unverified. AstroAI-branded handheld display with rotary selector and COM/voltage/current sockets. Read the actual model number and socket legends before choosing its manual.
  • ?
    1 ×TI CD74HC4050E non-inverting level converter, PDIP-16
    Unconfirmed · Availability and exact identity unconfirmed.
  • ?
    1 ×TI SN74AHCT125N TTL-input buffer, PDIP-14
    Unconfirmed · Availability and exact identity unconfirmed.
  • ?
    1 ×Regulated 3.3 V DC supply rated at least 250 mA, with output leads
    Unconfirmed · Availability and exact identity unconfirmed.

Assembly

  1. Disconnect all power; build the two-buffer interface from the table, not the direct 5 V signal wires in the original picture.
  2. Verify the separate 3.3 V reader rail and common ground before powering it; then connect USB.
  3. Open Monitor at 9600 baud and present a compatible tag close and parallel to the antenna.
Illustration © ELEGOO. All rights reserved.
Illustration © ELEGOO. All rights reserved. Open full-size ↗

Reviewed connections

FromToNote
External regulated 3.3 V / GNDReader 3.3V/GND and 4050 pins 1/8Share GND with Mega; do not use its 50 mA 3.3 V rail for an uncharacterized reader load.
Mega D52 → 4050 pin 3; pin 2 → reader SCK5 V → 3.3 VClock
Mega D51 → 4050 pin 5; pin 4 → reader MOSI5 V → 3.3 VHost data
Mega D53 → 4050 pin 7; pin 6 → reader SDA/SS5 V → 3.3 VSelect
Mega D5 → 4050 pin 9; pin 10 → reader RST5 V → 3.3 VReset
Reader MISO → AHCT125 pin 2; pin 3 → Mega D503.3 V → 5 VAHCT125 pin 14=5 V, pin 7=GND, pin 1=GND
4050 unused inputs 11/14 → GND; outputs 12/15 openPins 13/16 are NCUse CD74HC4050E, not an inverting 4049
AHCT125 pins 4/10/13 → 5 V; pins 5/9/12 → GNDUnused outputs 6/8/11 openDisable unused channels
100 nF across each buffer’s VCC and GNDPlace close to the ICLeave reader IRQ open; all pin numbers are PDIP top view

Source-reviewed wiring. Hardware not bench-tested; firmware uploads have not been performed.

Code

Download complete PlatformIO project
ZIP includes platformio.ini, src/main.cpp, and bundled libraries (MFRC522).

Extract the ZIP, then open its lesson-21-read-uid-project/workspaces/lesson-21-read-uid folder in VS Code. Keep the adjacent third-party folder in place.

PlatformIO configuration
platformio.ini
[env:mega]
platform = atmelavr@5.3.0
board = megaatmega2560
framework = arduino
monitor_speed = 9600
lib_deps =
  file://../../third-party/MFRC522

Open PlatformIO Monitor at 9600 baud after Upload. Close Monitor before another Upload if the port is busy.

main.cpp
// Adapted from ELEGOO's MFRC522 example, originally public-domain Tom Clement code.
#include <Arduino.h>
#include <SPI.h>      // Mega hardware SPI: MOSI=51, MISO=50, SCK=52.
#include <MFRC522.h>  // Talks to the 13.56 MHz reader; this is not secure authentication.
const uint8_t SS_PIN = 53;   // Reader SDA means SPI chip select here, not I2C data.
const uint8_t RST_PIN = 5;
MFRC522 reader(SS_PIN, RST_PIN);  // Constructor order is select, reset.
void printUid() {
  Serial.print(F("Card UID:"));
  // A UID can have more than four bytes; print every byte reported by the library.
  for (uint8_t i = 0; i < reader.uid.size; ++i) {
    Serial.print(reader.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(reader.uid.uidByte[i], HEX);  // HEX displays a byte as hexadecimal.
  }
  Serial.println();
}
void setup() {
  Serial.begin(9600);
  SPI.begin();
  reader.PCD_Init();
  Serial.println(F("Read UID only; UID is not authentication"));
}

void loop() {
  // || means OR. Return if no new tag is present or selecting it failed.
  if (!reader.PICC_IsNewCardPresent() || !reader.PICC_ReadCardSerial()) {
    delay(50); return;
  }
  printUid();
  reader.PICC_HaltA();  // Finish with this tag; remove/re-present it to read again.
  reader.PCD_StopCrypto1();
}

Source: SOURCE_RECONCILED. Compile: COMPILE_VERIFIED. Hardware: NOT_TESTED. Upload: NOT_PERFORMED.

Expected behavior

Read option: Card UID followed by hexadecimal bytes; remove and re-present a tag to read again. Write option: a compatible changeable card reports success and is reselected for a memory dump; ordinary tags may reject the write. UID matching alone is not secure authentication.

Experiments & Challenges

  • Use the read-only program to compare two compatible kit tags; leave the write option for its explicitly compatible test card.

Troubleshooting

  • No tag: check 13.56 MHz ISO14443A compatibility, 3.3 V power, buffer supplies and Mega SPI 50/51/52/53.