MFRC552 not working

I have an Aruino UNO 3 and a MFRC522. Yesterday, I connected the Arduino's 3.3V pin with the MFRC522 3.3V and the Arduino's ground with the model's ground. Then I connected the other pins of the MFRC522 to the Arduino as a built-in example says. At first it didn't work. I can't remember what I did or if I did anything, but I got it to work. Today, I connected it again to the same pins as yesterday but it doesn't work. Here's the code:

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

#define SSPin 10
#define RSTPin 9

MFRC522 rfid(SSPin, RSTPin);

byte nuidPICC[4];
byte master[4] = {0x53, 0x65, 0x70, 0x2A};

void setup() {
  SPI.begin();
  rfid.PCD_Init();

  Serial.begin(9600);
}

void loop() {
  if (!rfid.PICC_IsNewCardPresent())
    return;

  if (!rfid.PICC_ReadCardSerial())
    return;

  for (byte i = 0; i < 4; i++) {
    nuidPICC[i] = rfid.uid.uidByte[i];
  }

  if (getAccessState(master, nuidPICC) == true) {
    Serial.println("Correct card");
  } 
  else {
    Serial.println("Wrong card");
  }
  
  rfid.PICC_HaltA();
  rfid.PCD_StopCrypto1();
}

bool getAccessState(byte accessCode[], byte newCode[]) {
  for (byte i = 0; i < 4; i++) {
    if (newCode[i] != accessCode[i]) {
      return false;
    }
  }
  return true;
}

I found online that I have to use a 1kohm resistor somewhere, but I'm not sure where to connect it. Also I'm 99% that I didn't use any resistor yesterday that it was working.

I moved your topic to an appropriate forum category @thanasisk09.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

20 minutes have passed and I was trying by modifying my code. It didn't work. I tried again with the code I tried in the start and it worked. Both the hardware and the software are the same as before. Why does it do that? Should I wait everytime like 15 minutes?

How is all this power sipplied?

The topic How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum tells what forum wants to know to help with the project.
Now it's helping You write the question.

The Uno is a 5V device. So its Voh is close to 5V. The MRFC522 is a 3.3V device. Its maximum Vih is 3.8V. Connecting the Uno's outputs directly to the MRFC522's inputs will eventually damage the MRFC522. Sometimes you get unlucky on the very first time out, and that may very well be what has happened to you.

I'm aware that there are many places on the web that say "oh, it's perfectly safe to do this", but I tend to believe the datasheet when it says that 0.5V over the supply voltage, or 3.8V, is the limit. But don't take my word for it: feel free to peruse the datasheet yourself and come to your own conclusions.

datasheet

To safely operate the MFRC522 with a 5V board, at a minimum you need voltage dividers on SCK, MOSI and RST to bring the high level signal down to 3.3V. I prefer to use active level conversion. You can do that with little more than a 74AHC125. The wiring isn't onerous. I also prefer to use a discrete 3.3V regulator rather than rely on the limited current capacity of the 3.3V output on some Uno clones.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.