Hello;
I recently got a RC522 RFID Reader Module based on MFRC522 Datasheet
I just want create a RFID door unlock system for my apartment's door, Using miguelbalboa's
RFID library which is great and module is cheap (around 5-10$). I am inspired project from Brett Martin (His project). And I just want to publish my workings because there are some old informations about MFRC522 Library around in forum . And I am going to try comment all code lines as much as I can.
And here is the code and flow scheme.
Code on GitHub And Since i am new to coding, so any help will be appreciated.
Work Flow:
Now code does not fit here, please grab it from GitHub
Features:
Easy User Interface
Just one Master RFID tag needed whether Delete or Add Tags
You can choose to use Leds for output or
Serial LCD module to inform users. Or you can use both
Stores Information on EEPROM
Information stored on non volatile memory to preserve
Users' tag, Master Card ID will be hard coded on Arduino's Flash Memory
No Information lost if power lost. Appx. 250 Tags can be programmed
(For 7 Byte UID tags, 140 tags can be programmed)
Note: EEPROM has unlimited Read cycle but 100,000 limited Write cycle.
Security
To keep it simple we are using Tag's Unique IDs,
But since this module and Tags are cheap,
I guess their IDs not so Unique.
We are going to use an (just secure for neighbors not for hackers)
INSECURE way to Unlock a door.
And there is a note on Datasheet which mentions aboout that
Note: The use of Single Size UIDs (unique ones) might end soon,
since the number of usable IDs is limited to approximately
3.7 billion pieces only.
Also there are always security
issues if there is a "LOCK" actually.
Credits:
Omer Siar Baysal who put together this project
Idea and most of code from Brett Martin
MFRC522 Library
Based on code Dr.Leong ( WWW.B2CQSHOP.COM )
Created by Miguel Balboa (circuitito.com), Jan, 2012.
Rewritten by Søren Thing Andersen (access.thing.dk), fall of 2013
(Translation to English, refactored, comments, anti collision, cascade levels.)
Arduino Forum Member luisilva for His Massive Code Correction
http://forum.arduino.cc/index.php?topic=257036.0
http://forum.arduino.cc/index.php?action=profile;u=198897
License
You are FREE what to do with this code
Just give credits who put effort on this code
TODO:
I think since we don't use check-sum storedCard and readCard data can be 4 byte. I checked EEPROM and there was 4 byte, I need to figure it out that behavior.
EEPROM code corrected for 4 byte data. Before that we were writing 5 byte data to EEPROM which was stupid since we getting only 4 byte data from RFID Tags . Mind there are 7 byte cards too, you need to modify code for those cards. (Easy to do)
There is no way to exit Program Mode if you entered accidentally without scanning another Card,
a timeout ? or scanning master card again ?
Scanning master card again will exit program mode
No wipe mode ?? what if I lost my Card?
A universal Relay Code for everyone > Is it Possible?
When entered program mode Led cycle through Red Green Blue once, make it cycles until exiting program mode.
Now it cycles.
We are using 1 Byte for to store how many Tag records we have, and each Card ID takes 4 Bytes on EEPROM. Arduino UNO R3 (Atmega328) has 1024 Bytes on EEPROM 1024-1 = 1023 / 4 = 255 Card ID record can be stored on EEPROM. If we use more secure way, lets say 16 byte 1023 / 16 = 63 Records can be stored. I just started new secure branch on github in order to give more security to Project. Experimental
Optimize code for both 4 Byte UID and 7 Byte UID Tags? (For now just 4 Byte supported)
*************** Reserved Here For Project Updates *************************
23/07/2014 ***** Updated GitHub link, Commented some lines
25/07/2014 ***** Massive code correction from Forum Member luisilva, Now Sketch Works
There are still issues with leds corrected
Code is now more human readable (at least for newbies like me) compared to original code
26/07/2014 ***** Testing code for bugs, etc. So far, everthing works as expected
Code optimized for BOTH Common Anode or Common Cathode Leds, or just use regular Leds
Now it does not matter which led you are going to use, simply define what led you have
27/07/2014 ***** Buzzer code (not needed actually, added anyway) removed
More information about project provided with code
Now you can Exit Program Mode by scanning Master Card again if you entered accidently
Corrected EEPROM code for cards which have only 4 byte UID
01/08/2014 ***** Some minor delay corrections, minor changes Relay Code.
Code for controlling Relay not universal. You need to modify Relay Code for your needs.
When in program mode led cycles through Red Green Blue
I have been testing whole project for days, so far so good.