Little help limiting RFID Access

Hey, So I want to make a box, that is accessed by RFID which moves a servo then locks again (I have this sorted already)

Now what I want to do is limit the amount of times it can be opened a day by that UID, for example 2 times by “user1” and 3 times by “user3” I have bought an DS3231 RTC and added it which I was thinking could help.

my current code for the access is

  if (uidDec == xxxx)
  {
     lcd.clear();
    lcd.print(" Hello player1");
    delay(1000);
    lcd.clear();

  
     for (pos = 0; pos <= 100; pos += 3) { 
    lock.write(pos);
    delay(15);
  
     }
     delay(1000);
     for (pos = 100; pos >= 0; pos -= 3) {
      delay(15);
    lock.write(pos); 
     }                                   

  
  }else if (uidDec == xxx2)
  {
     lcd.clear();
    lcd.print(" Hello player2");
    delay(1000);
    lcd.clear();

  
     for (pos = 0; pos <= 100; pos += 3) {
    lock.write(pos);
    delay(15);
  
     }
     delay(1000);
     for (pos = 100; pos >= 0; pos -= 3) {
      delay(15);
    lock.write(pos); 
     }

Any help would be great, cheers

Circuitry looks like working. What is the trouble You want help for?

I would suggest you install the RTCLib library and look at the example for the DS3231. Get that working. Understand the code.

Then, incorporate it into your code. You will also need to keep track of the access count for the current RFID tag for the current day. You could probably store this information in EEPROM if you are worried about loosing power or just a regular array if you are not.

After you have it all together, and if it doesn't work, post your code and your problems and people can help.

blh64:
Then, incorporate it into your code. You will also need to keep track of the access count for the current RFID tag for the current day. You could probably store this information in EEPROM if you are worried about loosing power or just a regular array if you are not.

After you have it all together, and if it doesn't work, post your code and your problems and people can help.

Cheers, yeah I was thinking along those lines, will give it a crack when I get some more time, ive already got RTClib installed, got the time correct and displaying on the LCD. Cheers

I understand why people don't spoon feed codes now, ive learnt quite a bit finding it out myself, I have managed to limit the activations per card using the "count" function and if/else if.

Just need to find a way to reset the count per rtc.day now. :slight_smile:

That will depend on whether you mean per calendar day, or per 24 hour interval.

Which one do you want?

I can imagine you having a count variable as well as the day of week (dow) variable. When you get an RFID code, you compare the currend dow from the RTC to your stored dow and if they are not equal, you reset the count back to 1 and set the dow variable to the rtc dow. If they are the same, you increment count and if it is too high, don't open the lock

Paul__B:
That will depend on whether you mean per calendar day, or per 24 hour interval.

Which one do you want?

I was thinking per calendar day, but for now I am going to try this, so if i want to clear them at different times I can, so with this code it resets just before midnight

  if (now.hour() == 23 & now.minute() == 59 & now.second() == 00) {
    count = 0;
    count2 = 0;
  }

I have made a count for each RFID UID, so I can clear them at different times if needed and have different limits.

So I have it all pretty much sorted now :slight_smile:

Lloydieboy:
I was thinking per calendar day, but for now I am going to try this, so if i want to clear them at different times I can, so with this code it resets just before midnight

Well, by calendar day is much easier, as you just run a reset function at the start of each day.

The most straightforward code for this is to keep a record of the day (number), routinely check it against the current day, then when the two differ, set the day record to the current day and do all your resets.

Note that doing it this way, it will not matter if the program happened to be busy performing an alternate function for all of the last minute. It is generally preferable to monitor for a change of parameter - in this case, the day - than to match a particular time, particularly when it is time that you are dealing with.

Lloydieboy:
I have made a count for each RFID UID, so I can clear them at different times if needed and have different limits.

Well, you must have a count for each RFID UID in order to count them individually. :roll_eyes:

Paul__B:
The most straightforward code for this is to keep a record of the day (number), routinely check it against the current day, then when the two differ, set the day record to the current day and do all your resets.

This check really only needs to be done when you read a new RFID tag. If no tags are being presented to the system, it can happily do nothing but loop(). Once a tag is read, compare the current day with the day-stamp of the last read and if they are different, do the reset. If they are the same, increment the count for that tag.

Paul__B:
Well, you must have a count for each RFID UID in order to count them individually. :roll_eyes:

Sorry I guess i worded that the wrong, this is my first week every trying to code something, Just trying to learn, thanks for guidance.

sorry