Arduino RC522 RFID Door Unlock

238,475

244

194

Posted

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.

16 People Made This Project!

Recommendations

  • Science of Cooking

    Science of Cooking
  • Pocket-Sized Contest

    Pocket-Sized Contest
  • Trash to Treasure

    Trash to Treasure
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

133 Comments

I have Arduino without IC to connect Pro Mini. I am trying to connect Pro Mini to RFID
but is not responding .
Code is simple

#include
#include

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.


void setup()
{
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("Approximate your card to the reader...");
Serial.println();

}
void loop()
{
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i {
Serial.print(mfrc522.uid.uidByte[i] Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "04 42 DE 1A 9D 32 80") //change here the UID of the card/cards that you want to give access
{
Serial.println("Authorized access");
Serial.println();
delay(3000);
}

else {
Serial.println(" Access denied");
delay(3000);
}
}

From Examples of Arduino I picked up the code can
someone try and share me the code and pin connections
Arduino+Pro Mini + MFRC

hello @all.

i have a question. is it possible to chainge the code, so when i hold the chip to the reader the relaise switches on but when i take the card away it switches off ?

i nead it for a lamp that would only lit when the kard (chip) is on the reader, but when i take it away the lamp turns of (like in hotel rooms). I'm an absolute newbie in this stuff so i dont realy know how to code or do such things.

thx. :)

try to play with the function "mfrc522.PICC_IsNewCardPresent()", where mfrc522 is the instance for the initialised reader

// Look for new cards

if ( ! mfrc522.PICC_IsNewCardPresent())
return;

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
return;

hello, and thanks for this awesome project.
do you know how many cards id can save in mega2560 eeprom? or Uno?
Mega2560 have 1K eeprom,

The Mega2560 has 4k byte EEPROM (the UNO has 1k), so you can store 666 tags with 6 byte UIDs or 1000 with 4 byte UIDs

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

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

2017, 00:05.jpg2017, 00:05.jpg2017, 00:05.jpg

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.

:\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'

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"