NodeMCU and RC522 RFID reader wiring diagram

RC522 RFID Reader with NodeMCU

In previous tutorial, I have made how to use the RC522 RFID reader with arduino. In this articles, I will make a tutorial on how to use this RFID reader with an nodeMCU.

We can use the same library that made by miguel just like what we did with an arduino. The difference arethe pins. We have the different pins between NodeMCU and arduino. So how do we connect an RC522 RFID reader with an NodeMCU?

NodeMCU and RC522 RFID reader wiring diagram

NodeMCU and RC522 RFID Reader

Connect NodeMCU and RFID Reader just like the wiring diagram above. And we can start the code.

NodeMCU and RC522 RFID reader Code

We can use library made by miguel. You can download the library here, and install to arduino.

To Read the tag id or serial code you can use the code I made below. It simpler than in library example.

/* Read RFID Tag with RC522 RFID Reader
 *  Made by miliohm.com
 */
 
#include <SPI.h>
#include <MFRC522.h>

constexpr uint8_t RST_PIN = D3;     // Configurable, see typical pin layout above
constexpr uint8_t SS_PIN = D4;     // Configurable, see typical pin layout above

MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
MFRC522::MIFARE_Key key;

String tag;

void setup() {
  Serial.begin(9600);
  SPI.begin(); // Init SPI bus
  rfid.PCD_Init(); // Init MFRC522
}

void loop() {
  if ( ! rfid.PICC_IsNewCardPresent())
    return;
  if (rfid.PICC_ReadCardSerial()) {
    for (byte i = 0; i < 4; i++) {
      tag += rfid.uid.uidByte[i];
    }
    Serial.println(tag);
    tag = "";
    rfid.PICC_HaltA();
    rfid.PCD_StopCrypto1();
  }
}

Upload the code to NodeMCU and you should see the tag code every a tag is tapped on RFID reader. If it doesn’t work. Recheck the wiring, make sure that the wiring is correct and every wiring is connected.

I also make a demo code that will ring a buzzer 3 times when a right tag is tapped, and the buzzer will ring long when wrong tag is tapped. The right tag is “1193818595”. You can edit the right tag as a key in code below.

/* Read RFID Tag with RC522 RFID Reader
    Made by miliohm.com
*/

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

constexpr uint8_t RST_PIN = D3;     // Configurable, see typical pin layout above
constexpr uint8_t SS_PIN = D4;     // Configurable, see typical pin layout above

MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
MFRC522::MIFARE_Key key;

String tag;

void setup() {
  Serial.begin(9600);
  SPI.begin(); // Init SPI bus
  rfid.PCD_Init(); // Init MFRC522
  pinMode(D8, OUTPUT);
}

void loop() {
  if ( ! rfid.PICC_IsNewCardPresent())
    return;
  if (rfid.PICC_ReadCardSerial()) {
    for (byte i = 0; i < 4; i++) {
      tag += rfid.uid.uidByte[i];
    }
    Serial.println(tag);
    if (tag == "1193818595") {
      Serial.println("Access Granted!");
      digitalWrite(D8, HIGH);
      delay(100);
      digitalWrite(D8, LOW);
      delay(100);
      digitalWrite(D8, HIGH);
      delay(100);
      digitalWrite(D8, LOW);
      delay(100);
      digitalWrite(D8, HIGH);
      delay(100);
      digitalWrite(D8, LOW);
      delay(100);
    } else {
      Serial.println("Access Denied!");
      digitalWrite(D8, HIGH);
      delay(2000);
      digitalWrite(D8, LOW);
    }
    tag = "";
    rfid.PICC_HaltA();
    rfid.PCD_StopCrypto1();
  }
}