Grove - 125KHz RFID Reader only reading once - add more functions

Ok guys, I´m completely lost.
I´m using a Arduino Uno with a Seeed Grove base shield. On the base shield is Grove RFID Reader connected to D2.
First of all, I´ve tried many sketches but none of them worked. The only Sketch which is working is the one below. Nevertheless, it is to complicated for my skills. First of all, I want to read different cards but it´s only reading one card. I need to plug out and in again to read the next card. Is this caused by the code?
Second, I want to add code to the sketch to read a card and if the ID of the card is correct a relay should be activated. With a RC522 this is really straight forward, it´s like this:
long code=0;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
code=((code+mfrc522.uid.uidByte[i])*10);
}
Serial.print("Card No: ");
Serial.println(code);
if (code==12345678) // If code ist correct…

{

digitalWrite (Relay, HIGH);
delay (3000);

How can I translate this to the SoftwareSerial Sketch?

#include <SoftwareSerial.h>

SoftwareSerial SoftSerial(2, 3);
unsigned char buffer[64]; // buffer array for data receive over serial port
int count = 0; // counter for buffer array

void setup()
{
SoftSerial.begin(9600); // the SoftSerial baud rate
Serial.begin(9600); // the Serial port of Arduino baud rate.
}

void loop()
{
// if date is coming from software serial port ==> data is coming from SoftSerial shield
if (SoftSerial.available())
{
while(SoftSerial.available()) // reading data into char array
{
buffer[count++] = SoftSerial.read(); // writing data into array
if(count == 64)break;
}
Serial.write(buffer, count); // if no data transmission ends, write buffer to hardware serial port
clearBufferArray(); // call clearBufferArray function to clear the stored data from the array
count = 0; // set counter of while loop to zero
}
if (Serial.available()) // if data is available on hardware serial port ==> data is coming from PC or notebook
SoftSerial.write(Serial.read()); // write it to the SoftSerial shield
}

void clearBufferArray() // function to clear buffer array
{
// clear all index of array with command NULL
for (int i=0; i<count; i++)
{
buffer[i]=NULL;
}

}

Hi there,
No wonder here, That looks rough. It’s not rocket science but you need to keep it organized and clean code, Use the code tags above; like this. What Libraries are you using to use the RFID reader? Look at the example and the Link, blend those together or take from the example. It works and you can figure it out with the info available forsure. :v:

// 125Khz RFID READER test code.
//
long code=0;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
code=((code+mfrc522.uid.uidByte[i])*10);
}
Serial.print("Card No: ");
Serial.println(code);
if (code==12345678) // If code ist correct…

{

digitalWrite (Relay, HIGH);
delay (3000);

How can I translate this to the SoftwareSerial Sketch?

#include <SoftwareSerial.h>

SoftwareSerial SoftSerial(2, 3);
unsigned char buffer[64]; // buffer array for data receive over serial port
int count = 0; // counter for buffer array

void setup()
{
SoftSerial.begin(9600); // the SoftSerial baud rate
Serial.begin(9600); // the Serial port of Arduino baud rate.
}

void loop()
{
// if date is coming from software serial port ==> data is coming from SoftSerial shield
if (SoftSerial.available())
{
while(SoftSerial.available()) // reading data into char array
{
buffer[count++] = SoftSerial.read(); // writing data into array
if(count == 64)break;
}
Serial.write(buffer, count); // if no data transmission ends, write buffer to hardware serial port
clearBufferArray(); // call clearBufferArray function to clear the stored data from the array
count = 0; // set counter of while loop to zero
}
if (Serial.available()) // if data is available on hardware serial port ==> data is coming from PC or notebook
SoftSerial.write(Serial.read()); // write it to the SoftSerial shield
}

void clearBufferArray() // function to clear buffer array
{
// clear all index of array with command NULL
for (int i=0; i<count; i++)
{
buffer[i]=NULL;
}

}

this is how it should go!

Here is some example code for writing and reading a code on an RFID tag using an Arduino Uno and an MFRC522 RFID reader:

Here is some example code for writing and reading a code on an RFID tag using an Arduino Uno and an MFRC522 RFID reader:
#include <SPI.h>
#include <MFRC522.h>
const int SS_PIN = 10;
const int RST_PIN = 9;
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  Serial.println("Place your RFID tag on the reader to write data to it." );
}
void loop() {
  // Look for a new card
  if ( ! mfrc522.PICC_IsNewCardPresent()) { return; }
  // Select the card
  if ( ! mfrc522.PICC_ReadCardSerial()) { return; }
  // Dump the card data
  Serial.println("Writing data to RFID tag..." );
  Serial.print("UID: ");
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? 

" write and read a code on an rfid tag - Project Guidance - Arduino Forum [1]

Here are some steps to use the code:

  1. Connect the RFID reader to the Arduino Uno
  2. Download the MFRC522 RFID library from GitHub - miguelbalboa/rfid: Arduino RFID Library for MFRC522
  3. Open the Arduino IDE and choose rfid-master
  4. Open a new sketch and save it as RFID_Reader
  5. Type #include <MFRC522 to add the MFRC522 RFID module, SPI device communication, and EEPROM memory libraries to the sketch
  6. Compile and upload the code to the Arduino
  7. Open the serial monitor
  8. Bring an RFID tag near the RC522 module
  9. The reader will read the tag’s data and display it in the

HTH
GL :slight_smile: PJ

The sketch I was using was this one:
https://wiki.seeedstudio.com/Grove-125KHz_RFID_Reader/
This works, but only one time.
I´ve ordered a red RFID reader and with that it works perfect, I just thouht I can use the grove RFID reader with the same ease of use.