0

So I bought a RFID-RC522 module with a blue tag and a white card, and I searched for tutorials and found this library that I used it.

and here is my code :

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

#define SAD 10
#define RST 9

MFRC522 nfc(SAD, RST);

void setup() {
  SPI.begin();
  // Read a fast as possible. There is a limit for how long we are
  // allowed to read from the tags.
  Serial.begin(115200);

  Serial.println("Looking for MFRC522.");
  nfc.begin();

  // Get the firmware version of the RFID chip
  byte version = nfc.getFirmwareVersion();
  if (! version) {
    Serial.print("Didn't find MFRC522 board.");
    while(1); //halt
  }

  Serial.print("Found chip MFRC522 ");
  Serial.print("Firmware ver. 0x");
  Serial.print(version, HEX);
  Serial.println(".");
}

byte keyA[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, };
byte keyB[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, };

void loop() {
  byte status;
  byte data[MAX_LEN];
  byte serial[5];
  int i, j, pos;

  // Send a general request out into the aether. If there is a tag in
  // the area it will respond and the status will be MI_OK.
  status = nfc.requestTag(MF1_REQIDL, data);

  if (status == MI_OK) {
    Serial.println("Tag detected.");
    Serial.print("Type: ");
    Serial.print(data[0], HEX);
    Serial.print(", ");
    Serial.println(data[1], HEX);

    // calculate the anti-collision value for the currently detected
    // tag and write the serial into the data array.
    status = nfc.antiCollision(data);
    memcpy(serial, data, 5);

    Serial.println("The serial nb of the tag is:");
    for (i = 0; i < 3; i++) {
      Serial.print(serial[i], HEX);
      Serial.print(", ");
    }
    Serial.println(serial[3], HEX);

    // Select the tag that we want to talk to. If we don't do this the
    // chip does not know which tag it should talk if there should be
    // any other tags in the area..
    nfc.selectTag(serial);

    // Assuming that there are only 64 blocks of memory in this chip.
    for (i = 0; i < 64; i++) {
      // Try to authenticate each block first with the A key.
      status = nfc.authenticate(MF1_AUTHENT1A, i, keyA, serial);
      if (status == MI_OK) {
        Serial.print("Authenticated block nb. 0x");
        Serial.print(i, HEX);
        Serial.println(" with key A.");
        // Reading block i from the tag into data.
        status = nfc.readFromTag(i, data);
        if (status == MI_OK) {
          // If there was no error when reading; print all the hex
          // values in the data.
          for (j = 0; j < 15; j++) {
            Serial.print(data[j], HEX);
            Serial.print(", ");
          }
          Serial.println(data[15], HEX);
        } else {
          Serial.println("Read failed.");
        }
      } else {
        // If we could not authenticate with the A key, we will try
        // the B key.
        status = nfc.authenticate(MF1_AUTHENT1B, i, keyB, serial);
        if (status == MI_OK) {
          Serial.print("Authenticated block nb. 0x");
          Serial.print(i, HEX);
          Serial.println(" with key B.");
          status = nfc.readFromTag(i, data);
          if (status == MI_OK) {
            for (j = 0; j < 15; j++) {
              Serial.print(data[j], HEX);
              Serial.print(", ");
            }
            Serial.println(data[15], HEX);
          } else {
            Serial.println("Read failed.");
          }
        } else {
          Serial.print("Access denied at block nb. 0x");
          Serial.println(i, HEX);
        }
      }
    }

    // Stop the tag and get ready for reading a new tag.
    nfc.haltTag();
  }
  delay(2000);
}

and I connected the module like this :

===================================
|   RFID-RC522   |  Arduino Uno   |
___________________________________
|      SDA       |       10       |
|      SCK       |       13       |
|      MOSI      |       11       |
|      MISOI     |       12       |
|      RQ        |     Skipped    |
|      GND       |       GND      |
|      RST       |        9       |
|      3.3V      |       3.3V     |
===================================

and when I virify and uplaod the code, the RFID-RC522 module turned the light D1 to On (red light) and in the serial it show :

Looking for MFRC522.
Didn't find MFRC522 board.

and when i try to scan the card or the tag nothing happened in the serial, I searched in google and i found that Arduino uno 3.3V pin is too weak, so i changed the 3.3V to 5V, and click in reset button of arduino uno board and check the serial and it showed :

Looking for MFRC522.
Found chip MFRC522 Firmware ver. 0xFF.

But still not scaning the tag or the card (also tried another tag and another card that i bought them from the same seller and still not working)

any help please, and thanks

3
  • use an external power supply that can deliver the necessary current ... please review the RFID-RC522 module datasheet for minimum power requirement
    – jsotola
    Sep 11 at 17:39
  • What is external power? a battery ? or resistor... and thanks for reply Sep 11 at 20:53
  • a resistor is not a power supply ... do not use the Arduino to supply power... use anything that is able provide the required voltage to the RFID reader at the necessary current level ... 5 Vdc power supply is probably the most suitable
    – jsotola
    Sep 11 at 20:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.