Go Down

Topic: MFRC522 Library Cheap RC522 rfid Reader Door Unlock Project (Read 63219 times) previous topic - next topic


Hello Omersiar,
I want to introduce myself, my name is Addison.
I offered my apartment complex to make them a card reader to open the garage door and so as I started brain storming and I determined there were a few things I wanted. Then I stumbled upon your project and it's very close to what I am hoping to accomplish. I am going to begin contributing to the project in the next week or two, I ordered hardware, just need to wait for it to get here. My only thing is that I am still pretty new to git so I am going to do my best to not make a mess of your project. I think I might start a new branch for now.

Here are some of the things I am hoping to accomplish
-Card reader (obviously)
(I am going to add support for the Sparkfun RFID readers as I need 125kHz for existing tags and new cards/keychains are cheaper) https://www.sparkfun.com/products/11827

-Database of approved users
I wanted to do it on SD card because I need upwards of 150 users, I like the way you do it with filenames and then find the filename, I want to store more info in the file: "residents name" "apartment number" and such. I don't know if they should be tab, comma or line delimited yet.

-Web page for management
Because there are so many authorized users the "Master Card" programing method isn't a good solution for my case.
I love that you have started the web interface, I want to expand on it. I want a couple separate pages. A list of users in the system, sort of as a table with the UID, Resident Name, Apartment Number etc.
I'm imagining a checkbox next to each name or simply a button where you can select to delete users from the system. (If I get really advanced you may be able to sort them by column? We'll see how good my web development skills are.)
A field at the bottom to add new users (probably separate boxes for UID, name, apt # etc)

Another page that will keep a list of every card scan on the system, which card was scanned and display the name and apt number of the person that scanned and the time of the scan. This log will be kept in a file on the SD card and will most likely be read from a real time module, I thought about using NTP but RTC may be easier to start.

The part I need to look at is how to make the web page password protected.

Any thoughts and input is greatly appreciated. Which file in which branch is the most up to date "Embedded system" file?


Hello Addison,

Thank you for your interest to this project, as I try to develop more things I see that UNO can quickly run out of flash space, unfortunately I ended up with no space left for my things. There is a wifi module that can be programmed with Arduino IDE its called ESP8266 and it provides much more programmable space, and have wireless connection out of the box. So it might be a good alternative.

And there is this project
check this out it has SD card and RTC support, and Nick is one of the most famous Arduino community member, the code is highly optimized, so give it a shot maybe you can start from there.

Code other than EEPROM ino is highly experimental


Hello Omersiar,

I loved your project, and I was looking inside the code and I tried to change it to work in the same way with 125khz, but I don't have any ideia to change the getID int.

Code: [Select]

int getID() {
  // Getting ready for Reading PICCs
  if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
    return 0;
  if ( ! mfrc522.PICC_ReadCardSerial()) {   //Since a PICC placed get Serial and continue
    return 0;
  // There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC
  // I think we should assume every PICC as they have 4 byte UID
  // Until we support 7 byte PICCs
  Serial.println(F("Lido o ID:"));
  for (int i = 0; i < 4; i++) {  //
    readCard[i] = mfrc522.uid.uidByte[i];
    Serial.print(readCard[i], HEX);
  mfrc522.PICC_HaltA(); // Stop reading
  return 1;

I Tried to adapt the getID from Brett Martin's  project, but without success.

Please do you have any clue??




Very impressed with this use of the module and code.

I have taken the example code and have adapted it to work slightly differently.

It is for use on internal doors, where we only want the doors to be access controlled at specific times.  
Typically doors would have a key switch to disable the lock - I am doing it by having separate cards / tokens. (Keys witches are expensive and they come with different keys).

  • Configured it to work with a pro-mini 3.3 volt (same voltage as the reader module) and low cost.
  • Using an array to hold the card details - this means the cards need to be pre-programmed by adding a line to the code then re-downloading to the unit (plug in a USB lead).
  • Each card / token can be one of 3 types normal / disable / privacy.
  • Door is unlocked after a reset (power failure)
  • The lock can be enabled or disabled using a disable card.
  • Input pin configured for a push to exit button.
  • Input pin configured for a disable switch.
  • Optional privacy card - stops a door being opened - a do not disturb feature.
  • Different status LED flashing depending on sequence
  • Uses the "many things at the  same time" principles to control the status led and lock timing rather than delay.

I plan to post and share the design and code once I get closer to completion.

Another use I have in mind is an in/out board - a panel with LEDs by peoples name.
People can then use their token / card to show if they are in the building or not.


Hi Omersiar,

Nice job. I ran across your project when search for some code for an RFID reader that I'm having trouble reading an "S50 White Card". I have some suggestions your "AccessControl.ino" file. I don't think you need to have "match" as a global variable. You can simplify "checkTwo" and "isMaster" as follows:

boolean checkTwo ( byte a[], byte b[] ) {
   return memcmp(a, b, 4) == 0 ? true : false;

boolean isMaster( byte test[] ) {
   return checkTwo(test, masterCard);

This will save you a few bytes of code space and be more efficient.


P.S. Description of memcmp is here.


HI Omersiar,

thank you for your posting.
I've managed to make it workinng :-0

After that I'v emodified your code so it can be controled by serial line.
I have list of keys in file, and it is easy to add/remove ID form AVR.

Added Commands
ADD   ADD one  Token
DEL    Delete one  Token
LIST   List  ALL Tokens
WIPE  Wipe  ALL Tokens



Hello Omersiar,
I just downloaded your Code from Github (AccessControl.ino)
Great job.

I want to restrict using a machine to certain user. I will add some php stuff for writing grants to a SQL-Database.
So your program ist a very good startup for me.

It took me some time to get your code working.
My problem was, that I used an empty SD-Card. But the SD-Card has to have two directories on it (/SYS and /PICCS). Otherwise the program will fail.
I suggest to implement some routines to check if these directories exists and if not, to create them automatically.



Hi Omersiar.

i want to use the SD version of your project with arduino yun.

to do this, i used the <FileIO.h> instead of <SD.h> and i changed the commands "Sd.open" with "FileSystem.open", "Sd.read" with "FileSystem.read", ecc.. i also changed the directory from "/SYS/" (and "PICCS") to "/mnt/sd/arduino/www/SYS/"  (and "/mnt/sd/arduino/www/PICCS/").

but i have some problems and i don't undestand why:

1- i need to reset the atmel32u4 after the switch-on of arduino yun otherwise the program doesn't work. i think because is necessary that the atmel sketch starts after the loading of linino.

2- although i do the reset, i have a problem when i try to enter in program mode, i read in the serial monitor "Hello Master - Entered Program Mode" but the program is "stopped"

can someone help me?? someone uses the Omer project with arduino yun

p.s. sorry for my enghlish :-)


hi Great project.
I managed to transfer it to a arduino mega working great.
Just a request to add the delete program in to the main code to be able to delete from web or from serial input of card number. also adding names to cards would be wonderful. hope you can add this to the program.


Hi sir omersiar

I like ur project very much sir and I would like to try that one but I dont know wht to do.first...

Sir how am I going to use ur codes?? I already downloaded it in github and the zip contains access control, eeprom, no serial and sd.. Wht is my first thing.to do?? Compile first the access control?.


hello sir,

i like your project very very much, I would like to ask :)
how can i save my personal data/information to Microsoft access(database) instead of EEPROM ?

thank you.


hello sir,

i like your project very much, i would like to ask if how can i save my personal information or Mifare ID's to Microsoft access(database) instead of EEPROM ? please help me. thank you.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131