Coding help for a beginner

I am needing help with code for Arduino Uno .What I need it to do is read 5 different RFIDs that have to be placed in the correct place. I have 5 Tiki Statues that are different color and I need the correct color to be placed in the correct spot to open a magnetic look. It doesn’t matter which color is place first just the correct place. In have code to do 3 like this but cant get it to work with 5. I am new to this so any help is appreciated. Here is what I have

/**
*

  • Typical pin layout used:

  •         MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
    
  •         Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
    
  • Signal Pin Pin Pin Pin Pin Pin

  • RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
  • SPI SS 1 SDA(SS) ** custom, take a unused pin, only HIGH/LOW required **
  • SPI SS 2 SDA(SS) ** custom, take a unused pin, only HIGH/LOW required **
  • SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
  • SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
  • SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15

*/

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_1_PIN 10 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
#define SS_2_PIN 8 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1
#define SS_3_PIN 7 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1

#define NR_OF_READERS 3

byte ssPins[] = {SS_1_PIN, SS_2_PIN,SS_3_PIN};

MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
String read_rfid;
String ValidCard_1 = “8cc1ad85”;
String ValidCard_2 = “5efc1f2b”;
String ValidCard_3 = “1196b85”;
boolean Card_1_ok = false;
boolean Card_2_ok = false;
boolean Card_3_ok = false;

int Read1 = 9;
int Read2 = 9;
boolean ValidCardOrder = true;
String Prevcard = “”;
int NoCardCnt = 0;
int DoorLockPin = 4;
int DoorOpenSec = 2;

/**

  • Initialize.
    */
    void setup() {
    pinMode(DoorLockPin,OUTPUT);
    digitalWrite(DoorLockPin,HIGH);
    Serial.begin(9600); // Initialize serial communications with the PC
    while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)

SPI.begin(); // Init SPI bus

for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
Serial.print(F("Reader “));
Serial.print(reader);
Serial.print(F(”: "));
mfrc522[reader].PCD_DumpVersionToSerial();
}
}

/**

  • Main loop.
    */
    void loop() {

if (NoCardCnt > 150){
Card_1_ok = false;
Card_2_ok = false;
Card_3_ok = false;
ValidCardOrder = true;
digitalWrite(DoorLockPin,HIGH);
NoCardCnt = 0;
Prevcard = “”;
Read1 = 9;
Read2 = 9;
}

for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Look for new cards

//   
//Serial.println("Reading readers" + String(ValidCardOrder) + "-----" + String(Card_1_ok) + "--" + String(Card_2_ok) + "--" + String(Card_3_ok));   

if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
  Serial.print(F("Reader "));
  Serial.print(reader);
  // Show some details of the PICC (that is: the tag/card)
  dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
  Serial.println(read_rfid);
  
  ValidateCard(reader);
  
  // Halt PICC
  mfrc522[reader].PICC_HaltA();
  // Stop encryption on PCD
  mfrc522[reader].PCD_StopCrypto1();
}
else{
  NoCardCnt = NoCardCnt + 1;
  delay(50);
  //Serial.println("No card on sensor cnt"  + String(NoCardCnt));
}  

 } 

}

void dump_byte_array(byte *buffer, byte bufferSize) {
read_rfid = “”;
for (byte i = 0; i < bufferSize; i++) {
read_rfid = read_rfid + String(buffer[i], HEX);
}
}

void ValidateCard(int reader) {
if (reader == Read1) {
Serial.println(“Reader 1 already reads”);
goto GoNext;}
if (reader == Read2) {
Serial.println(“Reader 2 already reads”);
goto GoNext;}

int x;
Prevcard = read_rfid;
if (Card_1_ok == false && Card_2_ok == false && Card_3_ok == false){
if (ValidCard_1 == read_rfid){
Read1 = reader;
Card_1_ok = true;
NoCardCnt = 0;
goto GoNext;
}
else{
ValidCardOrder = false;
goto GoNext;
}
}

if (Card_1_ok == true && Card_2_ok == false && Card_3_ok == false){
  if (ValidCard_2 == read_rfid){
      Read2 = reader;
      Card_2_ok = true; 
      NoCardCnt = 0;
      goto GoNext;     
  } 
  else{
      ValidCardOrder = false;
      goto GoNext;      
  } 
}

if (Card_1_ok == true && Card_2_ok == true && Card_3_ok == false){
  if (ValidCard_3 == read_rfid){
      Card_3_ok = true;   
      if (ValidCardOrder) { 
          open_lock();              
       }  
  } 
  else{
      ValidCardOrder = false;      
  } 
}

GoNext:
x = 0;

}

void open_lock(){
//Serial.println("****************************************** Door opened");
digitalWrite(DoorLockPin,LOW);
delay(DoorOpenSec*1000);
digitalWrite(DoorLockPin,HIGH);
Card_1_ok = false;
Card_2_ok = false;
Card_3_ok = false;
ValidCardOrder = true;
NoCardCnt = 0;
Prevcard = “”;

Hi Lamar,

It’s a little tricky to troubleshoot code when it’s posted in a big dump like that. The best way is to tackle your problem in smaller sections. So go through and make sure that each little bit is working. You say that you can get 3 out of the 5 working? Then perhaps try stripping it back to three, using the serial terminal for ‘break by break’ feedback, then slowly reintroduce the 4-5 elements.