RFID Control system LCD print help

Hi all,

Thank you for reading. I have put together a RFID access control system using a Adrudino uno, RC522, LCD and a x4 relay board.

The original code I had controlled a servo motor and I have edited the code to Digital pins 1 and 2 to trigger my respective relays.

When I scan a registered tag once = access granted (actuator lock pulls in) and scan again Access granted (actuator lock pushed out)

With both card reads the LCD display reads out the same message that I have set to (come on in mate)

what I would like to do is on the scan where the actuator lock pulls in = LCD display (come on in mate),
On the scan where the actuator lock pushes out = LCD display (go have a beer).

Can anyone please give me some direction with editing the code for the LCD.

Footnotes: I am pretty new to coding this is my third Arduino project. Also I understand that there is probably a lot of dead code left over from the servo motor that isn't used anymore, any constructive input on that would be great also.

TIA everyone.

}

RFID access control code.pdf (50.3 KB)

Can you pop the code within </> code tags in a reply so we can see what it is doing without having to download stuff?

Haven't read through all your code but I see you have a concept of slots in EEPROM for each tag. How many tags do you have? Let's say 10.

Before setup() declare an array to hold true/false values for each tag. True means the person is entering the building.

const int NUM_TAGS = 10;
bool isIn[NUM_TAGS];         // true => in building
int tagIdx;                          // index of tag found

In setup() set each slot to false.

  // nobody in building
  for (int idx = 0; idx < NUM_TAGS; idx++) isIn[idx] = false;

When you find the tag in EEPROM toggle the value in the slot, if the card was not in the building now it is and vice versa. Save the index to the slot where the tag was found.

      uint8_t findIDSLOT( byte find[] ) {
        uint8_t count = EEPROM.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

            tagIdx = i;              // save index to slot
            isIn[tagIdx] = !isIn[tagIdx]; // <======== toggle value in this slot
            
            // is the same as the find[] ID card passed
            return i; // The slot number of the card
            break; // Stop looking we found it
          }
        }
      }

Now you know what to print to the LDD.

      if ( findID(readCard) ) { // If not, see if the card is in the EEPROM
      lcd.clear();
      lcd.setCursor(0, 0);
      if( isIn[tagIdx] ) {
        lcd.print("Come on in mate");
      } else {
        lcd.print("go have a beer");
      }
      lcd.setCursor(0, 1);
      lcd.print("Ravmach baby");
      open_lock(); // Open the door lock
      ShowOnLCD();
    }

As for constructive input, it's great that you have something that works. When code gets unwieldy and you have difficulty understanding it then it's time to rewrite it line by line. If this was my project I would begin with an empty sketch then add each feature (read a tag, store tag in EEPROM, find tag in EEPROM, write to LCD, etc) one at a time. Going through that exercise helps you understand how the parts fit together and makes it easier to maintain.

Iv'e just knocked off work and have read thru you're advise, Going to see if I can nut it out now. Thanks heaps for your time I'll be sure to let you know how I get on.

Regards, Tom.

@Blue Eyes.

G'day mate, last night I had a good go at inserting the code into my project but I had hit a road block getting the code to work once inserted. I think I need to do a Arduino coding for beginners course to make sense of all of this a bit easier. Could you point me in the right direction ? Thanks a lot for your time.

Here is the code I currently have.

current rfid code.zip (96.3 KB)