Introduction: Arduino RC522 RFID Door Unlock

Hello all here is my demo.

Since I got my RFID reader, I just wanted create a RFID door unlock system for my apartment's door. At first, I designed the work flow above, as a Newbie, its not quite an easy task to accomplish for me, then I found similar project on Instructables and modified it for use with specific RFID Reader (MFRC522 SPI Protocol).

With this project, you can let people to unlock apartment's door without a key, or modify the code for something else to do. Simply, this project gives you an opportunity to build what you want with this particular RFID reader.

I would like to thank dronmarket for sponsoring me about RFID usage on drones.


-------- Features ----------

Unlocks a Door (controls a relay actually) using a RC522 RFID reader with SPI interface on your Arduino. You define a Master Card which acts as a Programmer then you can able to choose card holders who can able to unlock the door or not.

* Easy User Interface *

Just one RFID tag needed whether Delete or Add Tags to memory. You can choose to use Leds for output or Serial LCD module to inform users. Or you can use both, of course.

* Stores Information on EEPROM *

Information stored on non volatile Arduino's EEPROM memory to preserve Users' tag and Master Card. No Information lost if power lost. EEPROM has unlimited Read cycle but 100,000 limited Write cycle.

* Easy to Modify *

You can modify the code and use a Servo motor instead of a relay. My apartment's door lock runs on 12vAC, when 12vAC applied it unlocks the Door Lock. I am new to coding, and know how it is hard to understand whole code as a newbie, I tried to create fully commented code for newbies like me. Maybe its not complete but there are many comments.

* Security *

To keep it simple we are going to use Tag's Unique IDs. It's simple, a bit secure, but not hacker proof.

What you will need: (Minimum Setup)

1x Arduino of your choice (UNO, Nano, Pro Mini)

1x RC522 13.56MHz RFID Reader Writer (Every module with MFRC522 compatible)

1x Relay Module or Relay Circuit that you build (You can DIY or buy as module)

nx RFID Tags (Mifare 13.56 Mhz as many as users)

Variable:

1x 3.3v Voltage Regulator if you don't have any 3.3v power source. (For powering RC522 Module)

Optional:

1x Common cathode or anode RGB led or just use regular single color leds (to inform users)

1x Serial LCD Module (to inform users)

17/08/2014 UPDATE
----------------------------------------

Now you don't need to know Master RFID card's UID. Master Card can be defined when first use, just scan a card and it will become the Master Card. Also now there is a Wipe Mode to wipe every record (including master card) on EEPROM. While holding wipe button, power up your Arduino and wait 10 second without releasing the button, everything will be erased (Careful: this process can not be undone).

For more information follow this link: http://forum.arduino.cc/index.php?topic=256260

--------------------------------------------------------------------

Step 1: Software Setup

You will need MFRC522 Library from here
https://github.com/miguelbalboa/rfid

Add this library to your Arduino IDE
If you don't know how to add a Library to Arduino IDE you can follow this guide:
http://arduino.cc/en/Guide/Libraries

And grab Main Sketch here

https://github.com/omersiar/RFID522-Door-Unlock/ (latest code always be here)
Try to Verify. There should be no errors if you installed Library correctly (IDE 1.0.5-r2).

Step 2: Hardware Setup

I suggest build everything on breadboard then tweak for your exact needs, since we don't know how every door unlocks you need to modify the setup.

Connect RC522 RFID Module
Pin layout should be as follows

For not-Mega Arduinos

MOSI: Pin 11 / ICSP-4
MISO: Pin 12 / ICSP-1
SCK : Pin 13 / ISCP-3
SS : Pin 10 (Configurable)
RST : Pin 9 (Configurable)

For Arduino Mega:

MOSI: Pin 51 / ICSP-4
MISO: Pin 50 / ICSP-1
SCK : Pin 52 / ISCP-3
SS : Pin 53 (Configurable)
RST : Pin 5 (Configurable)

Connect RGB Leds and Relay (All Configurable)

Red: Pin 7
Green: Pin 6
Blue : Pin 5

Relay : Pin 4
Wipe Button : Pin 3

Step 3: You Are Almost Ready.

Upload code to the Arduino, open serial monitor experiment, tweak, and build your final setup.

When your Arduino first run it will flash Blue Led and wait you to scan a card in order to set this card as Master Card. Which will be act as programmer for users' tag.

Comments

author
omersiar made it! (author)2017-05-17

I am happy to announce new project:

https://github.com/omersiar/esp-rfid

ESP-RFID Access Control with ESP8266

Access Control demonstration using a cheap RC522 RFID Hardware and Espressif's ESP8266 Microcontroller.

Features
  • Using WebSocket protocol to exchange data between Hardware and Web Browser
  • Data is encoded as JSON object
  • Records are Timestamped (Time synced from a NTP Server)
  • Bootstrap for beautiful Web Pages
  • Built-in HTML Editor
  • Thanks to ESPAsyncWebServer Library communication is Asyncronous
author
ÖzgürO3 made it! (author)2017-01-20

Hi there. i made it and it works great. Thanks

2017, 00:05.jpg2017, 00:05.jpg2017, 00:05.jpg
author
JayM196 made it! (author)JayM1962017-02-19

Hello, did you just copy and pasted the code to the arduino? it is my first time using github and i have no idea if it's a part by part from a package of code.

author
P.J.P1 made it! (author)2017-01-09

I get a SD intialtion failed in my com 4

image.jpg
author
RudraNarayanG made it! (author)2016-11-27

:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:276: error: use of enum 'PICC_Type' without previous declaration

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:276: error: expected primary-expression before '{' token

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:276: error: expected ';' before '{' token

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:291: error: use of enum 'StatusCode' without previous declaration

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:291: error: expected primary-expression before '{' token

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:291: error: expected ';' before '{' token

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:338: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:356: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:357: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:358: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:359: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:360: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:361: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:362: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:367: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:369: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:370: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:371: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:372: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:373: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:374: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:375: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:376: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:377: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:378: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:383: error: 'StatusCode' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:386: error: expected ';' before '(' token

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:387: error: 'PICC_Type' does not name a type

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:390: error: expected ';' before '(' token

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:396: error: 'PICC_Type' has not been declared

C:\Users\rc\Documents\Arduino\libraries\mfrc522/MFRC522.h:415: error: 'StatusCode' does not name a type

sketch_nov27a.ino: In function 'void loop()':

sketch_nov27a:19: error: 'Rfid' was not declared in this scope

sketch_nov27a:20: error: 'Return' was not declared in this scope

sketch_nov27a:23: error: 'PICC_Type' is not a member of 'MFRC522'

sketch_nov27a:23: error: expected `;' before 'piccType'

sketch_nov27a:27: error: 'PiccType' was not declared in this scope

sketch_nov27a:27: error: expected `)' before '!' token

sketch_nov27a:29: error: expected primary-expression before '.' token

sketch_nov27a:31: error: 'Return' was not declared in this scope

sketch_nov27a:34: error: 'STRING' was not declared in this scope

sketch_nov27a:34: error: expected `;' before 'Strid'

sketch_nov27a:35: error: expected primary-expression before '.' token

sketch_nov27a:36: error: expected primary-expression before '=' token

sketch_nov27a:37: error: 'Rfid' was not declared in this scope

sketch_nov27a:37: error: expected primary-expression before '.' token

sketch_nov27a:38: error: 'i' was not declared in this scope

sketch_nov27a:38: error: expected primary-expression before '.' token

sketch_nov27a:39: error: expected unqualified-id before '(' token

sketch_nov27a:39: error: expected `)' before '!' token

sketch_nov27a:41: error: 'strID' was not declared in this scope

sketch_nov27a:49: error: 'class MFRC522' has no member named 'PICC_HaltA'

author
scottrevoman333 made it! (author)scottrevoman3332016-11-29

I got this error too, I was frustrated as all get out, the fix is simple but not stated update your Arduino IDE to version 1.6, this fixed my problem, you can find it by googling "arduino ide" then if you need to add the RFID-Master to the library, under Arduino interface click "File->Example->MRFC522->AccessControl" Then be sure to select your Arduino Board, COM Port, and Processor if needed and upload "AccessControl" Sketch. I WAS DOING THIS AS I WAS WRITING THIS AND IT WORKS!!!! YES,YES,YES,YES SO HAPPY, Open serial monitor and you will scan master card, then scan it again and it will allow you to add a new rfid, then scan master again to close setup, then scan added rfid and it should read out "welcome, you may pass"

author
hong quangV made it! (author)2016-11-25

can you give me the code,tks

nhok010398@gmail.com

author
TranNguyen made it! (author)2016-11-11

You can design additional system components to LCD display

author
DioF3 made it! (author)2016-11-02

can you give me the code and circuit diagram?

diofbrn@gmail.com
thanks

author
nhattinh92 made it! (author)2016-10-21

How if i want lock by lock button without included time delay. Pls help me ....

author
siugtt made it! (author)2016-10-13

can you share the code to me,thx

email: forgttip1@gmail.com

author
mustafahamza8 made it! (author)2016-08-27

hiiii, i need your code, please send me :)

eng.mustafa.hamza.mh@gmail.com

author
HArveyL8 made it! (author)2016-08-15

deanhutchmary@gmail.com send me the code . Thanks. I need it for final year project..

author
DeepThought77 made it! (author)DeepThought772016-08-20
author
NicolasZ11 made it! (author)2016-08-13

Do you have a schematic I could see?

author
DN6 made it! (author)2015-11-04

I made it and used a servo instead of a relay, if anyone wants the code.

I also hooked up the RC522 3.3v pin to the 3.3v pin on my arduino, so i didn't need any transformer :D

WIN_20151104_17_09_50_Pro.jpg
author
AroyoA made it! (author)AroyoA2016-06-28

hiiii, i need your code, please send me :)

Aroyoapelu@gmail.com

author
Wahiddil Hyatt made it! (author)Wahiddil Hyatt2016-07-26

if u got the code, please share with me hyattatan@gmail.com

thank you

author
DN6 made it! (author)DN62016-01-14

Please don't post any more emails on here, it's a serious security concern I have not thought of before. Get the code from the Github, I made a pull request.

author
DN6 made it! (author)DN62016-01-05

I've made a pull request on Github everyone, it's there now!

author
DN6 made it! (author)DN62015-11-04

Oh and I might add a 8x8 matrix later depends if i can implement the code. :D

author
DN6 made it! (author)DN62015-12-18

Wow, so many replies! Sorry I haven't gotten back to you all yet, but I will tonight, haven't gotten the code from my old hard drive yet. :)

author
omersiar made it! (author)omersiar2015-12-18

You may want to contribute to code on GitHub, Pull Requests are always welcomed. Thank you.

author
DN6 made it! (author)DN62016-01-05

Yeah, I definetely will, making a pull request ASAP

author
kjubyer made it! (author)kjubyer2015-12-28

can you give me the code and circuit diagram?
kazijubyer@gmail.com
thanks

author
smithj938 made it! (author)smithj9382015-12-26

Would you be able to email me your code?

smthj938@gmail.com

Thanks

author
firefarter10 made it! (author)firefarter102015-11-09

Hey could i see your code?

email: firefarter10@gmail.com

author
DN6 made it! (author)DN62015-11-21

I just sent you the code, should be waiting in your inbox.

author
muzino_ made it! (author)muzino_2015-12-19

DNG, I really, really, really would like to have the code too please.

muzino55@gmail.com

Thanks.

author
muzino_ made it! (author)muzino_2015-12-24

please someone send me the code
muzino55@gmail.com

author
MitchellI1 made it! (author)MitchellI12015-12-16

Hi could You Please send me the code

email : mitchell123411123@gmail.com

author

could you please send me the code

email: rodrigongw@hotmail.com?

author
I GODOFMINECRAFT4I made it! (author)I GODOFMINECRAFT4I2015-12-24

Hey could i see your code?

email: xgodofminecraftx@gmail.com

author
MitchellI1 made it! (author)MitchellI12015-11-28

Hi Could You Please Send Me The Code As well

Email: mitchell123411123@gmail.com

author

could you please send me the code

email: rodrigongw@hotmail.com?

author
MitchellI1 made it! (author)MitchellI12015-12-16

Sorry I Dont Have The Code Yet But When I Get It Ill Send It To You

author
MrKevCrafter. made it! (author)MrKevCrafter.2015-12-02

Hi, can you send me the code, too ? And i have a question. In the code from omersiar from this website is a bit of ethernet and i want to know, if it is important or for what is that ? And for what is the sd pin and do i need that ? Sorry, if my english is bad but iam german and really at the beginning by programming arduinos. Email:kevin.eilers1999@googlemail.com

Thanks!

author

could you please send me the code

email: rodrigongw@hotmail.com?

author
nielsdecock made it! (author)nielsdecock2015-12-15

could you please send me the code

email: niels-1997@hotmail.com

thnx

author
silentshel02 made it! (author)silentshel022015-12-09

could you please send me the code

email: andrews_sheldon02@hotmail.com

thnx

author

could you please send me the code

email: rodrigongw@hotmail.com?

author

could you please send me the code

email: rodrigongw@hotmail.com?

author
Wahiddil Hyatt made it! (author)2016-07-26

can u give me the codes that u have done?

author
Uddipta206UdDReX made it! (author)2016-07-10

Can i use same cone and library for 125MHz RFID Module?
Or in RC522 RFID Module can i use 125MHz card?

author
eko pratamas made it! (author)2016-06-15

how to add code epprom RFID to LCD and kaypad??

author
eko pratamas made it! (author)2016-06-13

can you send me a code?

eko.pratama.setiyawan@gmail.com

author
RizqiK1 made it! (author)2016-05-16

Hi.. I will fill my UID number in my program. but it doesnt work (unsigned char master[4] = {113, 25, 162, 230 };) in example 5 number

can you send me a code?

patiunus9@gmail.com

sorry i have bad English

author
RizqiK1 made it! (author)2016-05-16

Hi.. I will fill my UID number in my program. but it doesnt work (unsigned char master[4] = {113, 25, 162, 230 };) in example 5 number

can you send me a code?

patiunus9@gmail.com

sorry i have bad English

author
Kittypanlover made it! (author)2016-05-14

hi, i need some help i'm trying to add an sd entrace log with IR counter and i need some help is for my grade project, i'm using an arduino mega i don't really know how to do an sd loggin D: someone could help me with the code?

author
saige hill made it! (author)2016-04-24

my RFID HAS

-VCC
-RST

GND

-MISO

-MOSI

-SCK

-NSS

-IRQ

wich is SS