Rdm6300 rfid help

Hello! I'm in over my head and looking for some guidance.
I am using this code from Wookai on GitHub to read RFID tags with a RDM6300.

Wookai/arduino-rfid: A short example of how to read 125 kHz RFID tags using an Arduino and a RMD6300 RFID module

I am trying to modify the code so that I can use 1 reader to read 4 tags (1 at a time), but trigger a different output for each tag. Currently, no matter what I have tried, all the tags trigger the 1st output. I have no formal training in this, so please explain it to me like I'm 5. Huge thanks in advance for any help!

This is what I have so far...

// define constants for pins
int SUCCESS = 10;
int ERROR = 13;
int relay1 = 8;
int relay2 = 9;
int relay3 = 10;
int relay4 = 11;

// variables to keep state
int readVal = 0; // individual character read from serial
unsigned int readData[10]; // data read from serial
int counter = -1; // counter to keep position in the buffer
char tagId[11]; // final tag ID converted to a string

char* authorizedTags1[2]; // array to hold the list of authorized tags
char* authorizedTags2[2];
char* authorizedTags3[2];
char* authorizedTags4[2];
// fills the list of authorzied tags
void initAuthorizedTags1() {
	// add your own tag IDs here
  authorizedTags1[0] = "01006ACCF4"; 
  authorizedTags1[1] = "01006AC92E"; 
}
void initAuthorizedTags2() {
  authorizedTags2[0] = "01006BE090"; 
  authorizedTags2[1] = "01006BED14"; 
}
void initAuthorizedTags3() {
  authorizedTags3[0] = "01006BE25C";
  authorizedTags3[1] = "01006BE5E4";
}
void initAuthorizedTags4() {
  authorizedTags4[0] = "01006BE818";
  authorizedTags4[1] = "01006BDF6D";
}
void setup() {                
  Serial.begin(9600);
  pinMode(SUCCESS, OUTPUT);
  pinMode(ERROR, OUTPUT);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  initAuthorizedTags1();
  initAuthorizedTags2();
  initAuthorizedTags3();
  initAuthorizedTags4();
}

// check if the tag ID we just read is any of the authorized tags
int checkTag1() {
  int i;
  
  for (i = 0; i < 4; ++i) {
    if (strcmp(authorizedTags1[i], tagId) == 0) {
      return 1;
    }
  }
  return 0;
}
int checkTag2() {
  int i;
  
  for (i = 0; i < 4; ++i) {
    if (strcmp(authorizedTags2[i], tagId) == 0) {
      return 2;
    }
  }
  return 0;
}
int checkTag3() {
  int i;
  
  for (i = 0; i < 4; ++i) {
    if (strcmp(authorizedTags3[i], tagId) == 0) {
      return 3;
    }
  }
  return 0;
}
int checkTag4() {
  int i;
  
  for (i = 0; i < 4; ++i) {
    if (strcmp(authorizedTags4[i], tagId) == 0) {
      return 4;
    }
  }
  return 0;
}

// convert the int values read from serial to ASCII chars
void parseTag() {
  int i;
  for (i = 0; i < 10; ++i) {
    tagId[i] = readData[i];
  }
  tagId[10] = 0;
}

// once a whole tag is read, process it
void processTag() {
	// convert id to a string
  parseTag();
	
	// print it
  printTag();
	
	// check if the tag is authorized
  if (checkTag1() == 1) {
    tagSuccess1(); // if so, perform an action (blink a led, open a door, etc...)
    }else if (checkTag2() == 2) {
      tagSuccess2();
    }else if (checkTag3() == 3) {
      tagSuccess3();
    }else if (checkTag4() == 4) {
      tagSuccess4();
    }
  else {
    tagFailed(); // otherwise, inform user of failure
  }}


void printTag() {
  Serial.print("Tag value: ");
  Serial.println(tagId);
}

// perform an action when an authorized tag was read
void tagSuccess1() {
  Serial.println("Tag 1 authorized.");
	
	// here, we simply turn on the success LED for 2s
  digitalWrite(SUCCESS, HIGH);
  digitalWrite(ERROR, LOW);
  delay(2000);
}
void tagSuccess2() {
  Serial.println("Tag 2 authorized.");
	
	// here, we simply turn on the success LED for 2s
  digitalWrite(SUCCESS, HIGH);
  digitalWrite(ERROR, LOW);
  delay(2000);
}
void tagSuccess3() {
  Serial.println("Tag 3 authorized.");
	
	// here, we simply turn on the success LED for 2s
  digitalWrite(SUCCESS, HIGH);
  digitalWrite(ERROR, LOW);
  delay(2000);
}
void tagSuccess4() {
  Serial.println("Tag 4 authorized.");
	
	// here, we simply turn on the success LED for 2s
  digitalWrite(SUCCESS, HIGH);
  digitalWrite(ERROR, LOW);
  delay(2000);
}

// inform the user that the tag is not authorized
void tagFailed() {
  Serial.println("Unauthorized access!");
	
  digitalWrite(SUCCESS, LOW);
  digitalWrite(ERROR, HIGH);
  delay(2000);
}

// this function clears the rest of data on the serial, to prevent multiple scans
void clearSerial() {
  while (Serial.read() >= 0) {
		; // do nothing
	}
}

void loop() {
	// turn LEDs off
  digitalWrite(SUCCESS, LOW);
  digitalWrite(ERROR, LOW);

	if (Serial.available() > 0) {
		// read the incoming byte:
		readVal = Serial.read();
		
		// a "2" signals the beginning of a tag
		if (readVal == 2) {
			counter = 0; // start reading
		} 
		// a "3" signals the end of a tag
		else if (readVal == 3) {
			// process the tag we just read
			processTag();
			
			// clear serial to prevent multiple reads
			clearSerial();
			
			// reset reading state
			counter = -1;
		}
		// if we are in the middle of reading a tag
		else if (counter >= 0) {
			// save valuee
			readData[counter] = readVal;
			
			// increment counter
			++counter;
		} 
	}
}

Please confirm that you had the code working properly before you modified it!

The term "Arduino" encompasses a wide range of development boards and modules, each with distinct features and specifications. To provide effective assistance, it's essential to identify the specific Arduino board you're using.

Labels and Markings: Many boards have model numbers or names printed directly on them. Look for identifiers like "ESP32-DevKitC," "NodeMCU-32S," or others.

Pin Configuration: Compare the pin layout of your board with standard pinout diagrams available online. This can offer clues about the board model.

If you have: the original packaging or datasheet, refer to them for model information.

  1. Provide Us Clear Documentation: Since we can’t see your project, share an annotated schematic (best) or a clear drawing of your setup. Pictures are welcome, but avoid using Fritzing diagrams as they are wiring diagrams, not schematics, and are not ideal for troubleshooting.

  2. Include Technical Details: If there is specific hardware involved, include links to technical information. There are often many versions of similar components, so precise details are essential. What version are you using?

  3. Reference Resources: For additional help, check out useful links and tutorials: Useful Links on Arduino Forum. Post links to your hardware technical information.

  4. Obtain a copy: of the Arduino Cookbook and complete several of the projects. Many of them will help you achieve parts of your goals.

  5. Course Electronics For Beginners (eBook)

  6. Electronics For Beginners (eBook)

  7. Arduino Step-by-step Projects Course | Build 25 Projects

  8. You can download a copy of KiCad free of charge. While they do ask for an optional donation, the software is fully functional regardless of whether you choose to donate. It may take a few weeks to become comfortable with the program, depending on how quickly you pick things up.

Yes, the original code works exactly as it should.

And do each of the 5 cards also read properly?

Yes, I was able to identify all of my cards

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.