How to Use ESP8266 with RFID RC522 13.56MHz Module
How to Use ESP8266 with RFID RC522 13.56MHz Module
This tutorial covers wiring NodeMCU ESP8266 with the RFID RC522 13.56MHz module to read card UID values. Suitable for door lock systems or attendance tracking projects.
Required Components
- NodeMCU ESP8266 V2 (CP2102)
- RFID RC522 13.56MHz module
- Micro USB cable for computer connection
- Breadboard 830 points
- Jumper wires (M-M, M-F, F-F)
- RFID card or key tag supporting 13.56MHz
Circuit Wiring ESP8266 to RC522
Connect wires according to the table below
| ESP8266 | RC522 |
|---|---|
| 3V3 | 3V3 |
| GND | GND |
| D0 | RST |
| D8 | SDA |
| D7 | MOSI |
| D6 | MISO |
| D5 | SCK |
Note: RC522 uses SPI communication, so connect ESP8266 SPI pins correctly.
Install MFRC522 Library
- Open Arduino IDE
- Go to Sketch > Include Library > Manage Libraries
- Search for “MFRC522”
- Click Install on MFRC522 by GithubCommunity
Code to Read RFID Card UID
#include <SPI.h>
#include <MFRC522.h>
// Define pins connected to RC522
#define SDA_PIN D8 // GPIO15
#define RST_PIN D0 // GPIO16
MFRC522 rfid(SDA_PIN, RST_PIN);
void setup() {
Serial.begin(115200);
SPI.begin(); // Start SPI communication
rfid.PCD_Init(); // Initialize RC522
Serial.println("ESP8266 + RFID RC522 Ready");
Serial.println("Tap card or key tag to read UID");
}
void loop() {
// Check for new card presence
if (!rfid.PICC_IsNewCardPresent()) {
return;
}
// Read card data
if (!rfid.PICC_ReadCardSerial()) {
return;
}
// Print UID value
Serial.print("UID: ");
for (byte i = 0; i < rfid.uid.size; i++) {
Serial.print(rfid.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println();
// Stop reading card
rfid.PICC_HaltA();
}
Upload and Test Steps
- Open Serial Monitor in Arduino IDE
- Change baud rate to 115200
- Place RFID card or key tag near the RC522 module
- Observe the UID value displayed on Serial Monitor
Reference Video
Summary
Using ESP8266 with RC522 is straightforward. Just connect SPI pins correctly, install the library, and upload the code. Each card has a unique UID that you can use to build authorized card checking logic for your projects.
อยากทำโปรเจคแบบนี้?
รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน
If you need Arduino project service or urgent IoT development, see full service details on the home page
จ้างทำโปรเจคเลย