MFRC522 RFID access control.

Hey everyone... not sure what the hell is going on here, but yesterday I wired up this RFID reader using the MFRC522 library for use with the AccessControl program, and verified it worked by setting a master card (and reading a non master tag). I have a relay wired in as well, which I couldnt figure out just how to trigger, but i could hear it click when i plugged it in or uploaded the program (leading me to believe its working as well). However, when I started up my computer this morning and plugged it in again, it wouldnt work. Just kept saying that the card wasnt recognized and/or to check connections... kept trying with no luck, so eventually I just unplugged everything and started over again. Now, the access control program works just fine and I can hear the relay click, Im just not exactly sure how to set the keycard to trigger the relay. Thanks!

I'm quite sure the problem is either in your code (which you didn't show us) or in the wiring of the hardware (which we haven't seen yet).

If you don't share this information with use you have search for the error yourself. Post a complete wiring diagram and your complete code. Also post links to the used hardware (MFRC522 is a chip, I doubt you're using the chip directly).

Ah, fair enough. My code is too long to post, but it can be found here:

https://github.com/miguelbalboa/rfid/blob/master/examples/AccessControl/AccessControl.ino

and my wiring is as follows:

RFID Uno

RST 9
SDA(SS) 10
MOSI 11
MISO 12
SCK 13

Relay Uno

  • 5v
  • GND
    S 4

LEDs Uno

Blue 5
Green 6
Red 7

Also, the RFID reader is through a bi-directional level converter. Ive gotten the access control program to successfully compile and upload, and ive been able to successfully set a master card and set/read a secondary tag, but in the serial window i cant exit out of either once i read them, and once i read them im not sure how to program it to trigger the relay (though i can hear the relay click when its given power).

But i wouldnt doubt something is wrong with my wiring if it worked yesterday, then didnt today (til i started all over again, same wiring), and now it works again.

Also, the RFID reader is through a bi-directional level converter. Ive gotten the access control program to successfully compile and upload, and ive been able to successfully set a master card and set/read a secondary tag, but in the serial window i cant exit out of either once i read them, and once i read them im not sure how to program it to trigger the relay (though i can hear the relay click when its given power).

The serial monitor should tell you what you can do. You enter programming mode by reading the master card and you leave programming mode by reading the master card again.
If you have a standard card registered and left the programming mode, reading it again should trigger the relay.

You forgot the links to the hardware, so I cannot tell you if your wiring might be correct.

But i wouldnt doubt something is wrong with my wiring if it worked yesterday, then didnt today (til i started all over again, same wiring), and now it works again.

My wild guess is that you have to long SPI bus wires so the communication with the MFRC522 is not reliable and fail from time to time. The SPI bus should not exceed 40-50cm in complete length and you should place the relay as far away as possible. Post a picture of your setup.

The serial monitor was only telling me what the card numbers were, what was master, etc... it was letting me enter program mode with the card, or i would scan the secondary card and it would read back the number, but nothing would happen after that and i couldnt get out of that part in the serial monitor... meaning once i scanned either card it wouldnt let me scan either again, or scan the other one. It also didnt trigger the relay either way. I think my wiring is correct, as the SPI bus is labeled quite clearly on the RFID reader, but i didnt know that about a maximum length, and between whats attached to the SPI bus itself and the level converter i can tell you right now my wires are definitely too long. Gonna go ahead and try to wire as directly as I can and update, thanks!

Nope. Used significantly shorter cables, still getting the same error:

"MFRC522 Software Version:0x0 (unknown), probably a chinese clone?
WARNING: Communication failure, is the MFRC522 properly connected?
SYSTEM HALTED: Check connections."

which is the same error I got when it was wired with longer wires, worked, didnt, then worked again.

Cant post a picture of my first setup because the picture is too large. It seems the second setup wasnt working because there was no power getting to the sensor, because the breadboards my boss got are just absolute garbage and the contacts were getting pushed down when i plugged anything in. Gonna try a work around and ill update.

Tried a different breadboard and shorter cables... can see the RFID reader has power, but im getting the same error.

Well what do ya know... came in this morning and didnt touch anything in my setup, just reuploaded the program and now it works. But, although its reading the cards, its not triggering the relay and its reading the scanned card number and not letting me do anything after that (scan the card again, or scan the master card to enter program mode). Trying to find a link to the hardware Im using (it came in a kit my boss bought).

Here is the hardware Im using

4bd9b2d3f6_520x500.PNG

Here is the hardware Im using

So this probably is a cheap Chinese clone so the output was right.

The serial monitor was only telling me what the card numbers were, what was master, etc... it was letting me enter program mode with the card, or i would scan the secondary card and it would read back the number, but nothing would happen after that and i couldnt get out of that part in the serial monitor... meaning once i scanned either card it wouldnt let me scan either again, or scan the other one. It also didnt trigger the relay either way. I

Post the serial output of such a session. Please also use code tags (the </> button in the editor) for this text!

No problem, will do. I also have a different model, image attached here (the brand is keyestudio). But this model wont even power on for some reason. Same setup, but the pinout is slightly different in that the pin locations of some are switched, so i modified my wiring accordingly. Cant figure out why it isnt even getting power, though. Gonna go ahead and wire back up the first one and post the serial output in a minute, though. Thanks!

After changing sensors back to the first one and reuploading the code, all the serial windows says is

Access Control Example v0.1
MFRC522 Software Version: 0x92 = v2.0
--------------------------
Master Card's UID
BFF95273
--------------------------
Everything is ready
Waiting PICCs to be scanned

except now neither the card nor the secondary tag will scan

Sorry, just a stupid mistake on my part... when rewiring to the level converter I forgot there needed to be power lines on both sides and a power line to the sensor. After rewiring both sensors (to make sure i didnt make this mistake twice) the second sensor still doesnt work at all or even power up, and the second still outputs what I posted above, except after scanning a tag it also includes the line

Scanned PICC's UID:
EA76352F

...which is the secondary tags UID, or else if i used the master card it prompts the entry to program mode. But just like the issue i was having before, once i scan a card in program mode nothing happens and it doesnt let me do anything else, except now itll at least let me exit program mode by scanning the master card again (when before it wouldnt even let me exit) unless i scan the secondary tag first, then it outputs the line I just posted above (Scanned PICC's UID...)

Quick edit so im not spamming: Now itll enter program mode but wont let me exit sometimes, or wont even scan at all. Not sure whats going on for it to be so unpredictable...

Hello there!

I while ago I was gifted an electronics kit and had the same RFID card in it. I actually wanted to do the same thing you did where an accepted non-master card read would do something (mine was update an LCD screen).

First off, I also used to get the "chinese clone" message. My card did not come with leads soldered to it, so I soldered pin headers to it so I could slide it into a breadboard. I have never gotten the error message again. So check the soldering connections and let me know.

Second, in the AccessControl code, there is a function called "void granted( uint16_t setDelay)", which is entered when an accepted non-master card is read. In this part of the code, you can add some commands to turn on and off the digital pin connected to your relay. A few lines above the function, there is an if statement that calls the "granted" function. You can also put the commands there.

bos1714:
Hello there!

I while ago I was gifted an electronics kit and had the same RFID card in it. I actually wanted to do the same thing you did where an accepted non-master card read would do something (mine was update an LCD screen).

First off, I also used to get the "chinese clone" message. My card did not come with leads soldered to it, so I soldered pin headers to it so I could slide it into a breadboard. I have never gotten the error message again. So check the soldering connections and let me know.

Second, in the AccessControl code, there is a function called "void granted( uint16_t setDelay)", which is entered when an accepted non-master card is read. In this part of the code, you can add some commands to turn on and off the digital pin connected to your relay. A few lines above the function, there is an if statement that calls the "granted" function. You can also put the commands there.

Oh, awesome! Yeah, Im doing this for a new job (making the leap from working in manufacturing to becoming a front and back end developer/programmer) and my boss bought like 4 or 5 different arduino kits, most with RFID readers/cards in them. After some more trial and error I took out the first one and tried a third sensor (of the same type as the first) and it worked pretty much immediately.

I double checked the solder on the first one and they look okay, except theres a little excess solder next to the SDA pin that could be an issue, but im also not sure if it may have just been because i didnt know it needed 3.3v logic at first and i just wired it up directly, may have messed it up before i really even got started, though im not sure why the second (different type) would be so faulty because it looks clean. Though i do know there are different types of security cards and there are nuances to these sensors, so maybe it has something to do with that.

But thanks so much! Now that I know to single out those lines/statements thats sure to help me along tremendously. Much appreciated!

Edit: seems i got ahead of myself once again, as it was hanging up in the same spot (waiting for card) then stopped working altogether and now im getting the same message. More troubleshooting... but thanks again for the other info, thats just what i needed when i get it working.

I know this is a stupid question, but my knowledge of hardware is next to none- could the setup between the 5v usb power supply, voltage divider, sensor, and relay be causing a voltage drop? I found some stuff saying that multiple relays could do that, but could one plus other stuff do it? It seems the issue is with a faulty connection, having played around with it more on a breadboard.

So, ive narrowed down the hardware issue to one of three things... either poor contact on the breadboard i was using, the 5v usb power supply wasnt enough (so now im using a 9v battery in addition), or there was something wrong with the board i was using (tried the first two and still had issues, but when changing my setup to a new board its been working consistently even between sensors). So now the hardware part is out of the way.

Im still not sure I understand how to trigger the relay, though. Ive located the lines in the code that were mentioned above, but to me they look like they should already be triggering the relay for the allotted amount of time, however the relay is always on (and when I scan a card i dont get any sort of confirmation message that access has been granted, it only ever reads back the card UID to me). Also, this could be because when I try to enter program mode with the master tag to set other PICCs, once i scan the secondary tag/card it just reads the number back to me, it doesnt let me exit program mode or do anything else past that, just gives me the same message as if it were just reading the card/tag. Thanks!

Sorry, but does anyone know why the program would hang up at this point? Cant figure it out for the life of me

Have you tried to connect just the RFID card and verify that it is working? Adding the relay may cause the circuit to behave is a way different than what you may expect.