RFID Door Locking System

Hello, I am new to programming but am familiar with an Arduino and using/modifying basic sketches to work for me, but I have taken an interest to a rather large code(for me anyway) and have tried my hand at modifying it for a little bit different purpose, the original code is used to open a door or any type of electronic lock using an RFID reader/card and a relay. I have gotten the original code working as it was intended but my needs are a little different than what it was originally intended for, I am wanting to use this code to open a cabinet door using a linear actuator, I have modified the code so it will behave the same as the original just using a few tweaks to run a set of relays that will power the actuator. Under the section titled “Access Granted” I have changed the delay time to allow the relay that extends the actuator(relay) to remain active for 3secs which is enough time for the actuator to fully open, the actuator has built in limit switches so it will stop when it fully extends even if the relay remains on, the next part I modified is just before the “Access Granted” section I “believe” that I have added a section that using a button labeled “Close” when pushed will deactivate the relay that extends the actuator(relay) and then it will activate the relay(relayB) that will retract the actuator, or if it is not pushed nothing else will happen and the door will remain open, at least that’s my hopes, the button will be inside the cabinet so it cannot be pushed unless the door is open. I added in a digitalWrite to shut off the Extension relay(relay), then delay, then activate the Retract relay(relayB) so if you wanted to stop the cabinet midway through opening and have it shut it would not run both relays at once creating a short, and allowing time for the actuator to stop before reversing.

My main concern is I am waiting on parts to arrive to be able to test this code and am wondering if I have placed the section regarding the closing procedure in the correct spot or should it be placed somewhere else, and is the delay(200) used correctly? Thanks in advance!

The code is to big to be posted on here I believe I have it linked to the post so it can be downloaded? If not I will try and shorten it and post only the important parts in the next posting. I have edited the code a little more, please see version 2.0

AccessControl_Actuator_Sketch2.0.ino (24.4 KB)

You should put your button check inside the card reading loop:

  do {
    successRead = getID();  // sets successRead to 1 when we get read from reader otherwise 0
    //  Somewhere in this loop
  } while (!successRead);   //the program will not go further while you are not getting a successful read

You have it below the loop so the button is only checked once for each successful card read. Put it inside the loop so the button is checked repeatedly while waiting for the next card to be presented.

OK, I get what you're saying, where I had it the program would have to run completely (read card) before it would read the button state right? Also am I right in thinking that the section you have said to add it to is essentially like an "idle" program, like that section of code is one that runs continuously while waiting for a card to be read? I made up a basic run of the "closing" segment replacing the "relays" with LEDs and so far using just this little section of button code in standalone the LEDs behaved how I would like the relays to but I've just gotta get all the pieces together to see if this code might cause any unintended interactions with the main RFID access sketch.

Also just another quick question I noticed there is a time set for the section just before the "Access Granted" section that runs the "granted" segment for 300ms I have tried changing this and it doesn't appear to effect the delay defined in the "void granted" code segment, is this "time set" needed, or does it prevent another card from being scanned immediately and duplicating the "void granted?"

Thank you so much, I have also adjusted some of the delay times to get a little more "security" to prevent both relays on at once, after seeing how short some of the original delays were using LEDs.

else {
if ( findID(readCard) ) { // If not, see if the card is in the EEPROM
Serial.println(F("Welcome, You shall pass"));
granted(300); // Open the door lock for 300 ms
}
else { // If not, show that the ID was not valid
Serial.println(F("You shall not pass"));
denied();

Sturds:
Also just another quick question I noticed there is a time set for the section just before the "Access Granted" section that runs the "granted" segment for 300ms I have tried changing this and it doesn't appear to effect the delay defined in the "void granted" code segment, is this "time set" needed, or does it prevent another card from being scanned immediately and duplicating the "void granted?"

That value is just an argument passed to the granted() function. If you look at the granted() function you will see that the argument is not used for anything. You can just ignore it. To get rid of it you would change the function to remove the argument and change the code to not pass a value to the function.