Arduino RC522 RFID Door Unlock

245,680

247

135

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

  • Water Contest

    Water Contest
  • Creative Misuse Contest

    Creative Misuse Contest
  • Fix It! Contest

    Fix It! Contest

135 Discussions

Atmega328 has 1024 bytes on its EEPROM, we are using first 4 bytes of PICCs.

Appx. 250 tags can be stored on most Arduino's EEPROM. You can always attach a serial EEPROM to increase EEPROM size, you may want to use SDCARD as well. There are several ways to increase number of tags to be stored

Hello, and many thanks Omersiar! I have connected FM24w256-G to my Arduino Leonardo I2C port, and succeeded to make it communicate with Arduino, i was able to write the the card id's in my eeprom. The only and ugliest issue i have is that i can't write IDs after EEPROM address 257. When i try to write after address 257 the IDs are stored starting with address 6 and the first IDs are corrupted.

In my Arduino Leonardo can store up to 60 cards, i do not know why.
Can you help me with a solution?
This is the code that i adapted to the FM24W256-G memory.

#include <SPI.h> // RC522 Module uses SPI protocol
#include <MFRC522.h> // Library for Mifare RC522 Devices
//#include <LiquidCrystal.h> //Library for Liquid Crystal LCD
#include <Wire.h>
#include <AT24C1024.h>
/*
Instead of a Relay you may want to use a servo. Servos can lock and unlock door locks too
Relay will be used by default
*/

// #include <Servo.h>

/*
For visualizing whats going on hardware we need some leds and to control door lock a relay and a wipe button
(or some other hardware) Used common anode led,digitalWriting HIGH turns OFF led Mind that if you are going
to use common cathode led or just seperate leds, simply comment out #define COMMON_ANODE,
*/

#define COMMON_ANODE
#define MAX_ADDRESS 4200

#ifdef COMMON_ANODE
#define LED_ON LOW
#define LED_OFF HIGH
#else
#define LED_ON HIGH
#define LED_OFF LOW
#endif

constexpr uint8_t redLed = 6; // Set Led Pins
constexpr uint8_t greenLed = 7;
constexpr uint8_t blueLed = 5;

constexpr uint8_t relay = 4; // Set Relay Pin
constexpr uint8_t wipeB = 3; // Button pin for WipeMode

bool programMode = false; // initialize programming mode to false

uint8_t successRead; // Variable integer to keep if we have Successful Read from Reader

byte storedCard[4]; // Stores an ID read from EEPROM
byte readCard[4]; // Stores scanned ID read from RFID Module
byte masterCard[4]; // Stores master card's ID read from EEPROM

// Create MFRC522 instance.
constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above
constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);
//LiquidCrystal lcd(0);

///////////////////////////////////////// Setup ///////////////////////////////////
void setup() {
//Arduino Pin Configuration
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
pinMode(wipeB, INPUT_PULLUP); // Enable pin's pull up resistor
pinMode(relay, OUTPUT);
//Be careful how relay circuit behave on while resetting or power-cycling your Arduino
digitalWrite(relay, HIGH); // Make sure door is locked
digitalWrite(redLed, LED_OFF); // Make sure led is off
digitalWrite(greenLed, LED_OFF); // Make sure led is off
digitalWrite(blueLed, LED_OFF); // Make sure led is off

//Protocol Configuration
Serial.begin(9600); // Initialize serial communications with PC
SPI.begin(); // MFRC522 Hardware uses SPI protocol
mfrc522.PCD_Init(); // Initialize MFRC522 Hardware
//lcd.begin(20, 4); // Initialize LCD
//If you set Antenna Gain to Max it will increase reading distance
mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);

delay(500);
Serial.println(F("Access Control Example v0.1")); // For debugging purposes
ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details
// lcd.setCursor(0, 0);
// lcd.print(F("|------------------|"));
// lcd.setCursor(5, 1);
// lcd.print("RFID System");
// lcd.setCursor(0, 2);
// lcd.print("Access Control V0.01");
// lcd.setCursor(0, 3);
// lcd.print("|------------------|");
// delay(3000);
// lcd.clear();

//Wipe Code - If the Button (wipeB) Pressed while setup run (powered on) it wipes SDcard
if (digitalRead(wipeB) == LOW) { // when button pressed pin should get low, button connected to ground
digitalWrite(redLed, LED_ON); // Red Led stays on to inform user we are going to wipe
Serial.println(F("Buton de setrgere a memoriei apasat!"));
Serial.println(F("Ai 10 secunde pentru a opri stergerea."));
Serial.println(F("Aceasta actiune va sterge toate cardurile inregistrate in memorie!"));
bool buttonState = monitorWipeButton(10000); // Give user enough time to cancel operation
if (buttonState == true && digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM
Serial.println(F("Stergere memorie in curs"));
for (uint16_t x = 0; x < 1; x = x + 1) { //Loop end of EEPROM address
if (EEPROM1024.read(x) == 0) { //If EEPROM address 0
// do nothing, already clear, go to the next address in order to save time and reduce writes to EEPROM
}
else {
EEPROM1024.write(x, 0); // if not write 0 to clear, it takes 3.3mS
}
}
Serial.println(F("Memorie Stearsa cu succes!"));
digitalWrite(redLed, LED_OFF); // visualize a successful wipe
delay(200);
digitalWrite(redLed, LED_ON);
delay(200);
digitalWrite(redLed, LED_OFF);
delay(200);
digitalWrite(redLed, LED_ON);
delay(200);
digitalWrite(redLed, LED_OFF);
}
else {
Serial.println(F("Stergere oprita")); // Show some feedback that the wipe button did not pressed for 15 seconds
digitalWrite(redLed, LED_OFF);
}
}
// Check if master card defined, if not let user choose a master card
// This also useful to just redefine the Master Card
// You can keep other EEPROM records just write other than 143 to EEPROM address 1
// EEPROM address 1 should hold magical number which is '143'
if (EEPROM1024.read(1) != 143) {
// Serial.println(F("Nu a fost inregistrat nici un card master"));
// Serial.println(F("Scaneaza un card care va fi master"));
do {
successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0
digitalWrite(blueLed, LED_ON); // Visualize Master Card need to be defined
delay(200);
digitalWrite(blueLed, LED_OFF);
delay(200);
}
while (!successRead); // Program will not go further while you not get a successful read
for ( uint8_t j = 0; j < 4; j++ ) { // Loop 4 times
EEPROM1024.write( 2 + j, readCard[j] ); // Write scanned PICC's UID to EEPROM, start from address 3
}
EEPROM1024.write(1, 143); // Write to EEPROM we defined Master Card.
//Serial.println(F("Cardul MASTER a fost setat!"));
}
// Serial.println(F("-------------------"));
//Serial.println(F("Master Card's UID"));
for ( uint8_t i = 0; i < 4; i++ ) { // Read Master Card's UID from EEPROM
masterCard[i] = EEPROM1024.read(2 + i); // Write it to masterCard
//Serial.print(masterCard[i], HEX);
}
//Serial.println("");
//Serial.println(F("-------------------"));
//Serial.println(F("Initializare efectuata"));
//Serial.println(F("Se asteapta scanarea cardului"));
cycleLeds(); // Everything ready lets give user some feedback by cycling leds
}


///////////////////////////////////////// Main Loop ///////////////////////////////////
void loop () {
do {
successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0
// When device is in use if wipe button pressed for 10 seconds initialize Master Card wiping
if (digitalRead(wipeB) == LOW) { // Check if button is pressed
// Visualize normal operation is iterrupted by pressing wipe button Red is like more Warning to user
digitalWrite(redLed, LED_ON); // Make sure led is off
digitalWrite(greenLed, LED_OFF); // Make sure led is off
digitalWrite(blueLed, LED_OFF); // Make sure led is off
// Give some feedback
Serial.println(F("Butonul de stergere a memoriei este apasat"));
Serial.println(F("CARDUL MASTER VA FI STERS IN 10 SECUNDE!!!"));
bool buttonState = monitorWipeButton(10000); // Give user enough time to cancel operation
if (buttonState == true && digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM
EEPROM1024.write(1, 0); // Reset Magic Number.
Serial.println(F("Cardul MASTER a fost sters din memorie"));
Serial.println(F("Dati restart pentru a reprograma un nou card MASTER"));
while (1);
}
Serial.println(F("Stergerea cardului MASTER a fost oprita!"));
}
if (programMode) {
cycleLeds(); // Program Mode cycles through Red Green Blue waiting to read a new card
}
else {
normalModeOn(); // Normal mode, blue Power LED is on, all others are off
}
}
while (!successRead); //the program will not go further while you are not getting a successful read
if (programMode) {
if ( isMaster(readCard) ) { //When in program mode check First If master card scanned again to exit program mode
Serial.println(F("Card Master detectat"));

Serial.println(F("Iesire din modul programare"));
Serial.println(F("-----------------------------"));
//lcd.clear();
// lcd.setCursor(0, 0);
// lcd.print(F("Iesire din programare"));
// delay(1000);
// lcd.clear();
programMode = false;
return;
}
else {
if ( findID(readCard) ) { // If scanned card is known delete it
// Serial.println(F("Card existent, stergere..."));
deleteID(readCard);
// Serial.println("-----------------------------");
// Serial.println(F("Scaneaza un card pentru a il ADAUGA sau STERGE"));
}
else { // If scanned card is not known add it
// Serial.println(F("Card inexistent, adaugare..."));
writeID(readCard);
// Serial.println(F("-----------------------------"));
// Serial.println(F("Scaneaza un card pentru a il ADAUGA sau STERGE"));
}
}
}
else {
if ( isMaster(readCard)) { // If scanned card's ID matches Master Card's ID - enter program mode
programMode = true;
Serial.println(F("Buna MASTER - Ai intrat in modul programare"));
uint8_t count = EEPROM1024.read(0); // Read the first Byte of EEPROM that
Serial.print(F("Sunt salvate ")); // stores the number of ID's in EEPROM
Serial.print(count);
Serial.print(F(" carduri in memorie."));
Serial.println("");
// Serial.println(F("Scaneaza un card pentru a il ADAUGA sau STERGE"));
// Serial.println(F("Scaneaza cardul master pentru a iesi din modul programare"));
// Serial.println(F("-----------------------------"));
}
else {
if ( findID(readCard) ) { // If not, see if the card is in the EEPROM
Serial.println(F("Buna ziua, usa este deschisa"));
granted(100); // Open the door lock for 300 ms
}
else { // If not, show that the ID was not valid
Serial.println(F("Buna ziua, nu aveti acces"));

denied();
}
}
}
}

///////////////////////////////////////// Access Granted ///////////////////////////////////
void granted ( uint16_t setDelay) {
//lcd.clear();
//lcd.setCursor(5, 0);
//lcd.print("Buna ziua!");
// lcd.setCursor(0, 1);
// lcd.print("!Usa este deschisa!");

digitalWrite(blueLed, LED_OFF); // Turn off blue LED
digitalWrite(redLed, LED_OFF); // Turn off red LED
digitalWrite(greenLed, LED_ON); // Turn on green LED
digitalWrite(relay, LOW); // Unlock door!
delay(setDelay); // Hold door lock open for given seconds
digitalWrite(relay, HIGH); // Relock door
delay(100); // Hold green LED on for a second and clear display
// lcd.clear();
}

///////////////////////////////////////// Access Denied ///////////////////////////////////
void denied() {
// Print denied message on display //
// lcd.clear();
// lcd.setCursor(5, 0);
// lcd.print("Buna ziua!");
// lcd.setCursor(2, 1);
// lcd.print("!Nu aveti acces!");

digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
digitalWrite(redLed, LED_OFF); // Make sure blue LED is off
delay(100);
digitalWrite(redLed, LED_ON); // Make sure blue LED is on
delay(100);
digitalWrite(redLed, LED_OFF); // Make sure blue LED is off
delay(100);
digitalWrite(redLed, LED_ON); // Make sure blue LED is on
delay(100);
digitalWrite(redLed, LED_OFF); // Make sure blue LED is off
delay(100);
digitalWrite(redLed, LED_ON); // Make sure blue LED is on
delay(100);
digitalWrite(redLed, LED_OFF); // Make sure blue LED is off
delay(100);

// lcd.clear();
}


///////////////////////////////////////// Get PICC's UID ///////////////////////////////////
uint8_t 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("UID-ul cardului scanat:"));
for ( uint8_t i = 0; i < 4; i++) { //
readCard[i] = mfrc522.uid.uidByte[i];
Serial.print(readCard[i], HEX);
}
Serial.println("");
mfrc522.PICC_HaltA(); // Stop reading
return 1;
}

void ShowReaderDetails() {
// Get the MFRC522 software version
byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print(F("MFRC522 Software Version: 0x"));
Serial.print(v, HEX);
if (v == 0x91)
Serial.print(F(" = v1.0"));
else if (v == 0x92)
Serial.print(F(" = v2.0"));
else
Serial.print(F(" (unknown),probabil este o copie chinezeasca?"));
Serial.println("");
// When 0x00 or 0xFF is returned, communication probably failed
if ((v == 0x00) || (v == 0xFF)) {
Serial.println(F("WARNING: Comunicatia a fost intrerupta, verificati conexiunea cititorului!"));
Serial.println(F("SISTEM OPRIT: SUNATI LA NUMARUL DE TEL: 0711.123456."));
// Visualize system is halted
digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
digitalWrite(redLed, LED_ON); // Turn on red LED
while (true); // do not go further
}
}

///////////////////////////////////////// Cycle Leds (Program Mode) ///////////////////////////////////
void cycleLeds() {
digitalWrite(redLed, LED_ON); // Make sure red LED is off
digitalWrite(greenLed, LED_ON); // Make sure green LED is on
digitalWrite(blueLed, LED_ON); // Make sure blue LED is off
delay(100);
}

//////////////////////////////////////// Normal Mode Led ///////////////////////////////////
void normalModeOn () {
digitalWrite(blueLed, LED_ON); // Blue LED ON and ready to read card
digitalWrite(redLed, LED_OFF); // Make sure Red LED is off
digitalWrite(greenLed, LED_OFF); // Make sure Green LED is off
digitalWrite(relay, HIGH); // Make sure Door is Locked

}

//////////////////////////////////////// Read an ID from EEPROM //////////////////////////////
void readID( uint8_t number ) {
uint8_t start = (number * 4 ) + 2; // Figure out starting position
for ( uint8_t i = 0; i < 4; i++ ) { // Loop 4 times to get the 4 Bytes
storedCard[i] = EEPROM1024.read(start + i); // Assign values read from EEPROM to array
}
}

///////////////////////////////////////// Add ID to EEPROM ///////////////////////////////////
void writeID( byte a[] ) {
if ( !findID( a ) ) { // Before we write to the EEPROM, check to see if we have seen this card before!
uint8_t num = EEPROM1024.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards
uint8_t start = ( num * 4 ) + 6; // Figure out where the next slot starts
num++; // Increment the counter by one
EEPROM1024.write( 0, num ); // Write the new count to the counter
for ( uint8_t j = 0; j < 4; j++ ) { // Loop 4 times
EEPROM1024.write( start + j, a[j] ); // Write the array values to EEPROM in the right position
}
successWrite();
Serial.println(F("SUCCES! ID-ul cardului a fost salvat in memorie!"));
}
else {
failedWrite();
Serial.println(F("EROARE! ID-ul cardului nu poate fi salvat."));
}
}

///////////////////////////////////////// Remove ID from EEPROM ///////////////////////////////////
void deleteID( byte a[] ) {
if ( !findID( a ) ) { // Before we delete from the EEPROM, check to see if we have this card!
failedWrite(); // If not
Serial.println(F("Failed! There is something wrong with ID or bad EEPROM"));
}
else {
uint8_t num = EEPROM1024.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards
uint8_t slot; // Figure out the slot number of the card
uint8_t start; // = ( num * 4 ) + 6; // Figure out where the next slot starts
uint8_t looping; // The number of times the loop repeats
uint8_t j;
uint8_t count = EEPROM1024.read(0); // Read the first Byte of EEPROM that stores number of cards
slot = findIDSLOT( a ); // Figure out the slot number of the card to delete
start = (slot * 4) + 2;
looping = ((num - slot) * 4);
num--; // Decrement the counter by one
EEPROM1024.write( 0, num ); // Write the new count to the counter
for ( j = 0; j < looping; j++ ) { // Loop the card shift times
EEPROM1024.write( start + j, EEPROM1024.read(start + 4 + j)); // Shift the array values to 4 places earlier in the EEPROM
}
for ( uint8_t k = 0; k < 4; k++ ) { // Shifting loop
EEPROM1024.write( start + j + k, 0);
}
successDelete();
Serial.println(F("Cardul a fost sters cu succes din memorie!"));
}
}

///////////////////////////////////////// Check Bytes ///////////////////////////////////
bool checkTwo ( byte a[], byte b[] ) {
for ( uint8_t k = 0; k < 4; k++ ) { // Loop 4 times
if ( a[k] != b[k] ) { // IF a != b then false, because: one fails, all fail
return false;
}
}
return true;
}

///////////////////////////////////////// Find Slot ///////////////////////////////////
uint8_t findIDSLOT( byte find[] ) {
uint8_t count = EEPROM1024.read(0); // Read the first Byte of EEPROM that
for ( uint8_t i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry
readID(i); // Read an ID from EEPROM, it is stored in storedCard[4]
if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM
// is the same as the find[] ID card passed
return i; // The slot number of the card
}
}
}

///////////////////////////////////////// Find ID From EEPROM ///////////////////////////////////
bool findID( byte find[] ) {
uint8_t count = EEPROM1024.read(0); // Read the first Byte of EEPROM that
for ( uint8_t i = 1; i < count; i++ ) { // Loop once for each EEPROM entry
readID(i); // Read an ID from EEPROM, it is stored in storedCard[4]
if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM
return true;
}
else { // If not, return false
}
}
return false;
}

Hi Omersiar,

Please can you give me / teach me for integrating an serial EEPROM in this project? I'm new to Arduino, and i want to make a door-lock system based on your project for the garbage house in the residential neighborhood where i live. For this i use Arduino Leonardo, MFRC522, a relay and an electromagnetic bolt and i need an external memory that will allow to store +600 keys because we are 600 people living inside the neighborhood.

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. :)

1 reply

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,

1 reply

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

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'

1 reply

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"

can you give me the code,tks

nhok010398@gmail.com

You can design additional system components to LCD display

0
None
DioF3

1 year ago

can you give me the code and circuit diagram?

diofbrn@gmail.com
thanks

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

0
None
siugtt

1 year ago

can you share the code to me,thx

email: forgttip1@gmail.com