Rfid door lock with 100 tags... how to do it?

Hi, gues , I try to use this code and its working very well.
But this way the maximum number of tags that I can use is 45, but I need to use more like 120 or so...
btw. Im using Arduino Nano, relay RFID reader, for door lock for my buildng
How can I do it... when I put more serials than 45 its stop reading them properly... what should I change pls I'm not much in coding I appreciate any help
RFID.ino (4.0 KB)
the code is not mine its from this gay
(Arduino Based RFID Door Lock - Make Your Own - YouTube)

thanks

What does he say about using 100 tags?

I wrote tohim but there is no answer yet so..

Then is is time to make his code your code and try to modify it for 100 tags.

1 Like

the code is published for public as a tutorial... so every one can use it and learn, and I never sad that is mine

String accessGranted [2] = {"310988016", "19612012715"}; //RFID serial numbers to grant access to
int accessGrantedSize = 2;

This is where you put your numbers and the number of numbers? What goes wrong when you put in more than 45 numbers?

Sorry, My fault.

In the English speaking world, "making something your own" means for you to learn all about how and why the program works, just as if you WERE the one who authored it. Then you can make modifications that are sensible and will work.

add one tag to the array,
modify the the size of the array from 44 to 45
AND modify the value in
int accessGrantedSize = 44;
to
int accessGrantedSize = 45;

Thanks for your reply...
I understend what you are saying, and I alredy done that and its not working...
U Put 60 serial numbers in to array, I change the size to 60 like this:

String accessGranted [60] = {"310988016",............. "19612012715"}; //60 serial numbers from the tags
int accessGrantedSize = 60;

and when I upload the sketch in serial monitor RFID reader won't read the serial tags , or after the first read triggers the relay to open and close it self constantly and I cant control it.

I think it is something with the maximum number of serials that I can use it with Arduino Nano.

I also try put serials in two "String accessGranted" like "String accessGrantedA [30]" and "String accessGrantedB [30]" I got the same result... the relay goes crazy and serials won't read

Copy and paste all of the messages you get in Serial Monitor when the program doesn't work.

44 tags-working
Serial Monitor message:
Place card/tag near reader...
Card found
The card's ID number is : 4148315903
Access Granted

45 tags-not working the relay triggers all the time on/off cycle
Serial Monitor message:
Place card/tag near reader...
Card found
The card's ID number is :
Access Granted

45 tags-not working the relay triggers all the time on/off cycle
Serial Monitor message:
Place card/tag near reader...
Card found
The card's ID number is :
Access Denied

also I try to upload the sketch on Arduino Uno the same thing happened... so I think its not memory thing or I'm wrong?

Maybe you are running out of memory?
You may need to use progmem and/or EEPROM.
Copy the message from the IDE when you upload the program.

Also go into preferences, instead of Compiler Warnings: None, select either All, or More, then click OK and restart the IDE.

1 Like

C:\Program Files (x86)\Arduino\libraries\RFID\RFID.cpp: In member function 'void RFID::halt()':
C:\Program Files (x86)\Arduino\libraries\RFID\RFID.cpp:501:17: warning: variable 'status' set but not used [-Wunused-but-set-variable]
unsigned char status;
^~~~~~
Sketch uses 6964 bytes (21%) of program storage space. Maximum is 32256 bytes.
Global variables use 1460 bytes (71%) of dynamic memory, leaving 588 bytes for local variables. Maximum is 2048 bytes.

This increases my suspicion that you're running out of memory; not right away, but as soon as you start using String class, you start to introduce dynamic memory techniques that cause problems. Others may disagree, but I'd strongly suggest you move to using cstrings instead of String, your life will be simpler. The Nano and Uno, and, I think, even the Mega suffer terribly with String, because there's no memory cleanup going on behind the scenes.
Add your code to your next post in this thread, using code tags, so we can take a look.

1 Like
//The DIY Life
//Michael Klements
//27 January 2020
//https://www.the-diy-life.com/arduino-based-rfid-door-lock-make-your-own/#google_vignette

#include <SPI.h>
#include <RFID.h>


RFID rfid(10, 9);       //D10:pin of tag reader SDA. D9:pin of tag reader RST
unsigned char status;
unsigned char str[MAX_LEN]; //MAX_LEN is 16: size of the array


String accessGranted [62] = {
"3111361314312",/*101*/
"71413141314312",/*102*/
"1021511314312",/*103*/
"6110111314312",/*104*/
"156341315312",/*105*/
"8210101314312",/*106*/
"105610612313",/*107*/
"10121381314312",/*108*/
"313921314312",/*109*/
"5101171314312",/*110*/
"1381551314312",/*111*/
"1010981314312",/*112*/
"0101171314312",/*113*/
"0310111314312",/*114*/
"12111531314312",/*115*/
"601521314312",/*116*/
"1091131314312",/*117*/
"0131401314312",/*118*/
"061311314312",/*119*/
"7710151314312",/*120*/
"1413101415903",/*121*/
"138415903",/*122*/
"12804151003",/*123*/
"141140151003",/*124*/
"151200151003",/*125*/
"112131415903",/*126*/
"151428151003",/*127*/
"15126615903",/*128*/
"0129151003",/*129*/
"120121015903",/*130*/
"770815903",/*131*/
"91011815903",/*132*/
"2761015903",/*133*/
"7812615903",/*134*/
"812310151003",/*135*/
"13158915903",/*136*/
"511141215903",/*137*/
"779815903",/*138*/
"151220151003",/*139*/
"7115815903",/*140*/
"115314151003",/*141*/
"116115903",/*142*/
"1017715803",/*143*/
"4148315903",/*144*/
"1354415803",/*145*/
"81106151003",/*146*/
"15106151003",/*147*/
"6031415903",/*148*/
"6410115803",/*149*/
"81506151003",/*150*/
"1565415803",/*151*/
"1514121015803",/*152*/
"30101115103",/*153*/
"270110104",/*154*/
"895915803",/*155*/
"11109215803",/*156*/
"12201415903",/*157*/
"289315803",/*158*/
"121301315903",/*159*/
"3121101203",/*160*/
/*STARI_PLAVI*/
"9595111529",/*30*/
"820131669"/*69*/
};  //RFID serial numbers to grant access to
int accessGrantedSize = 62;                                //The number of serial numbers 

#define buzzer 5      //buzer zvucnik 
int lock = 4; //RELAY-BRAVA-Which pin the lock will be on if using a relay or solenoid or similar
boolean locked = true;

void setup()
{
  Serial.begin(9600);     //Serial monitor is only required to get tag ID numbers and for troubleshooting
  SPI.begin();            //Start SPI communication with reader
  rfid.init();            //initialization

  //Choose which lock below:
  pinMode(lock, OUTPUT);
  pinMode(buzzer, OUTPUT);
  digitalWrite(buzzer, LOW); // Make sure led is off
  Serial.println("Place card/tag near reader...");
}

void loop()
{
  if (rfid.findCard(PICC_REQIDL, str) == MI_OK)   //Wait for a tag to be placed near the reader
  {
    Serial.println("Card found");
    String temp = "";                             //Temporary variable to store the read RFID number
    if (rfid.anticoll(str) == MI_OK)              //Anti-collision detection, read tag serial number
    {
      Serial.print("The card's ID number is : ");
      for (int i = 0; i < 4; i++)                 //Record and display the tag serial number
      {
        temp = temp + (0x0F & (str[i] >> 4));
        temp = temp + (0x0F & str[i]);
      }
      Serial.println (temp);
      checkAccess (temp);     //Check if the identified tag is an allowed to open tag
    }
    rfid.selectTag(str); //Lock card to prevent a redundant read, removing the line will make the sketch read cards continually
  }
  rfid.halt();
}

void checkAccess (String temp)    //Function to check if an identified tag is registered to allow access
{
  boolean granted = false;
  for (int i = 0; i <= (accessGrantedSize - 1); i++) //Runs through all tag ID numbers registered in the array
  {
    if (accessGranted[i] == temp)           //If a tag is found then open/close the lock
    {
      Serial.println ("Access Granted");
      granted = true;
      open_lock();
    }
  }
  if (granted == false)     //If the tag is not found
  {
    Serial.println ("Access Denied");
    buzz();
  }
}

void open_lock() {
  //Use this routine when working with Relays and Solenoids etc.
  digitalWrite(lock, HIGH);
  delay(3000);
  digitalWrite(lock, LOW);
  delay(500);
}
void buzz() {
  digitalWrite(buzzer, HIGH); // Make sure red LED is off
  delay(500);
  digitalWrite(buzzer, LOW); // Make sure blue LED is off
  delay(200);

}

Hmm. Doesn't look iffy, not big enough or complex enough. But, try

anyway.

Most certainly the case. Every card scanned pushes the heap closer to the stack.
In addition to switching to c-strings, a fixed input buffer should be used, and the cards should be stored in the EEPROM.

Then it should run forever and have loads of space to spare.

Yes, but failure on first try? Not seeing enough other consumption, but the two libraries are unfamiliar to me, and may be hogs.

yeah ok thank you very much for your effort realy.... but knowledge skills in coding are not on that level... so I can't do it :frowning: If someone can do it for me it will be great... I'm willing to pay for the work...