Implementing Commands to control RFID reader


I am new to programming in general, and I have hit a bit of a road block.

I am trying to communicate with an RFID module via a command protocol. Please see page 12 on the attached PDF. This is something which I don not fully understand, despite my endless attempts to get to understand it.
My question is: What way should I send the data to the reader? Should it be something like mySerial.println(“MOF”) and wait for response. Or should I write each character individually? This then brings up the question of what is, and how to write to serial?

I am kindof struggling with this topic at the moment, so if someone could offer any help or some relative literature which I could go through and maybe come back with more intelligible questions.

Many thanks, Micheal.

rfidrw-e-ttl.pdf (543 KB)

mmi698: I am trying to communicate with an RFID module via a command protocol...

Perhaps you could post your sketch here so others can see what you have done so far.

Normally, you use the standard 'Serial' library and transmit and receive using the functions built in, which you have already discovered (partly) anyway.

For example, to read a serial port stream of data you might use:

if (Serial.available() > 0) {
  char dataChar =;

You can monitor and send data back to the Arduino using the serial monitor window. Have you done this?

Finally, is just Carriage Return and is decimal value 13 or 0x0D in hexadecimal (basically much the same as hitting the Enter key after typing something on your keyboard. You could do this with Serial.write(13), for example. Usually (and hugely simplified), Serial.print is used to send the actual (ascii) character, whereas Serial.write is used to send a value such as command codes.

But post your code (so far) and we may be able to move forward.

Note Serial.println adds a carriage return onto what you write automatically.

Thanks for your input Ralph,

At the moment I am switching the RFID module on and off by connecting and disconnecting the power. When power is applied it automatically reads an ID tag and sends down the soft serial pin. This is how I have used the unit to date. Below is my code which I am using for reading the code to date.

char rfidData[BUFSIZE];  // Buffer for incoming data
    rfidData[0] = 0;         // Clear the buffer
    char offset = 0;         // Offset into buffer      

    while (mySerial.available()) {
        byte C =;
        rfidData[offset] = C;
        int Count = offset;
        Serial.println("LOOKING FOR TAG");
        if(offset == 17){
          digitalWrite(YLED, HIGH);

As I have never needed to have a 2-way conversation with the RFID module, so I do not have any code written which transits data(only revives).

Your last post has joined a lot of dots in my head. From this, I think I might be able to attempt to Witt some sort of code.
Would something like this be the right way to go?

millis() = setime;
while(millis() - setime < 1000){
 while (mySerial.available()) {
  byte C =;

So (cr) from the ascii table is the same as from the FRID module data sheet (Serial.write(13))?

Many Thanks, Micheal.

Does the code you posted to READ the RFID actually work?

Without re-reading that pdf you posted :o I can only guess at what the command codes you are transmitting in the first few lines of your next piece of code but yes, that’s the way to send them.

I’m not sure what this line of code is supposed to do:

while(millis() - setime < 1000)

because when there is no more data to read the .available() while loop will end naturally.

And yes, from what I can work out from the pdf, the is what they mean by carriage return which is indeed Serial.write(13).

Just a little suggestion here, as it’s clear you’re fairly new to programming. Break this project into tiny little parts so you can get the reading / writing / sending commands or whatever sorted out independently as possible. Lumping all your code into one monolithic block will just obfuscate any errors and confuse the hell out of people on this forum!

Once each part is proved to be working then you can put it all back together.

If you send the command as strings, it's more readable (even with the string in PROGMEM)


is the same as