Build a Smart RFID Tap-to-Unlock System
Tap a card near the reader and watch the OLED screen say hello. This project uses an ESP32, an RC522 RFID reader, and a tiny OLED screen to build your very own smart access-card system.
Mission Overview
How does an RFID access system work?
Every RFID card has a tiny chip and antenna hidden inside it. When you hold the card near the reader, they "talk" to each other using radio waves — no wires, no touching contacts needed.
Hold the card close to the RC522 reader.
RC522 picks up the card's unique ID number.
Compares the UID to your list of allowed cards.
Displays the UID and "Access Granted" or "Denied."
Shopping List
Parts you'll need
This is a compact, beginner-friendly build with just three main modules.
Wiring Guide
Circuit connections
The RC522 talks to the ESP32 over SPI and the OLED talks over I2C — two different, but both very common, communication styles.
| RC522 Pin | ESP32 Pin | Purpose |
|---|---|---|
| SDA (SS) | GPIO 5 | Chip select |
| SCK | GPIO 18 | Clock signal |
| MOSI | GPIO 23 | Data to reader |
| MISO | GPIO 19 | Data from reader |
| RST | GPIO 4 | Reset line |
| 3.3V | 3.3V | Power (never use 5V!) |
| GND | GND | Common ground |
| OLED Pin | ESP32 Pin | Purpose |
|---|---|---|
| VCC | 3.3V | Power |
| GND | GND | Common ground |
| SCL | GPIO 22 | I2C clock |
| SDA | GPIO 21 | I2C data |
The ESP32 talks to the RC522 over SPI and to the OLED over I2C at the same time — two separate buses, one microcontroller.
Build Log
Step-by-step build instructions
Set up your breadboard
Place the ESP32 on one side of the breadboard so you have room to wire the RC522 and OLED next to it.
Wire the RC522 reader
Connect SDA, SCK, MOSI, MISO, and RST to the ESP32 pins shown in the wiring table, then power it from 3.3V — never 5V, or you may damage the module.
Wire the OLED display
Connect SDA and SCL to GPIO 21 and GPIO 22, then power it from 3.3V and GND, sharing the same ground as the RC522.
Install the libraries
In the Arduino IDE, install MFRC522, Adafruit_GFX, and Adafruit_SSD1306 from the Library Manager.
Upload the code
Copy the sketch from the next section, select your ESP32 board, and upload it over USB.
Scan a card
Open the Serial Monitor, hold a card near the reader, and note down the UID it prints — you'll add this to your "allowed" list.
Test access granted / denied
Scan the same card again to see "Access Granted" on the OLED, then try a different card to see "Access Denied."
Code Room
Arduino code for ESP32 + RC522 + OLED
This sketch reads a card's UID, shows it on the OLED, and checks it against one allowed UID stored in the code.
// Smart RFID Access System — ESP32 + RC522 + OLED // Libraries: MFRC522, Adafruit_GFX, Adafruit_SSD1306 #include <SPI.h> #include <MFRC522.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> // ---- RC522 pins ---- #define SS_PIN 5 #define RST_PIN 4 MFRC522 rfid(SS_PIN, RST_PIN); // ---- OLED setup ---- #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // ---- One allowed card UID (change to your own!) ---- String allowedUID = "3FA29C10"; void setup() { Serial.begin(115200); SPI.begin(); rfid.PCD_Init(); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); display.clearDisplay(); display.setTextColor(WHITE); display.setTextSize(1); display.setCursor(0, 20); display.println("Tap your card..."); display.display(); } void loop() { // wait for a new card if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) { return; } // build the UID string, e.g. "3FA29C10" String uid = ""; for (byte i = 0; i < rfid.uid.size; i++) { if (rfid.uid.uidByte[i] < 0x10) uid += "0"; uid += String(rfid.uid.uidByte[i], HEX); } uid.toUpperCase(); Serial.println("Card UID: " + uid); // show the result on the OLED display.clearDisplay(); display.setCursor(0, 0); display.print("UID: "); display.println(uid); display.setCursor(0, 30); if (uid == allowedUID) { display.println("ACCESS GRANTED"); } else { display.println("ACCESS DENIED"); } display.display(); rfid.PICC_HaltA(); delay(1500); }
Tip: run the sketch once, scan your card, and copy the UID printed in the Serial Monitor into the allowedUID line — that's how you "register" a new card.
Important Notes
Safety and good practice
Adult supervision recommended. Wiring, uploading code, and using a breadboard are safe for kids, but it's good to build alongside a parent, teacher, or mentor, especially the first time.
Watch the voltage. The RC522 module runs on 3.3V only — connecting it to 5V can permanently damage it, so always double-check your wiring before powering on.
Use it responsibly. This project is great for learning how real access-card systems work, like at school gates or office doors — build and test it on your own devices and never try to scan or copy someone else's card without permission.
Quick Answers
Frequently asked questions
What is RFID and how does it work?
RFID stands for Radio-Frequency Identification. A small chip and antenna inside the card wake up when they get close to a reader's radio field, then send back a unique ID number — all without any physical contact.
What's the difference between SPI and I2C?
Both are ways for a microcontroller to talk to small chips. SPI (used by the RC522) uses four wires and is very fast. I2C (used by the OLED) uses just two wires and can connect several devices on the same two lines.
Is this project okay for beginners?
Yes! It only needs a breadboard and jumper wires — no soldering required — and the libraries handle the tricky parts of talking to the RFID reader and the screen.
Can I store more than one allowed card?
Yes. Once you're comfortable with the basic code, you can replace the single allowedUID with a small list (an array) of UID strings and check the scanned card against all of them.
What else can I build with an RC522 and OLED?
The same parts make a great school attendance tracker, a library book check-out system, a locker access system, or a simple vending-machine style "credit" counter.
Comments
Post a Comment