Go Down

Topic: Arduino RFID Module RDM630 Code (Read 3407 times) previous topic - next topic


Hi Gang

I'm thinking of purchasing the following RFID Module;


I found the following example code;

Code: [Select]
This is a sample code for RDM630 RFID reader by Spekel(Spekel.se)
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
char code[20];
int val = 0;
int bytesread = 0;
//create a Serial object RFID
SoftwareSerial RFID= SoftwareSerial(rxPin, txPin);

void setup()
 Serial.println("Serial Ready");
 Serial.println("RFID Ready");
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
void loop()
 val = 0;
 bytesread = 0;

 while(bytesread < 12)
   // read 12 digit code
   val = RFID.read();
   if(val == 3)
   { // if header or stop bytes before the 10 digit reading
     break; // stop reading

   if(val != 2)
     code[bytesread] = val; // add the digit
     bytesread++; // ready to read next digit
     code[bytesread] = '\0'; // add the NULL

 if(bytesread >= 12)
 { // if 12 digit read is complete
   Serial.print("Tag: [");
   for(int i=0; code[i]!='\0' ; i++)
   Serial.println("]"); //print the whole 13 bytes

I was wondering if someone could explain what the following two lines do;

Code: [Select]
code[bytesread] = '\0'; // add the NULL


Code: [Select]
for(int i=0; code[i]!='\0' ; i++)



Any help would be greatly appreciated.


Jase :)


The sketch is commented. It clearly tells you that /0 is adding the NULL terminator to the end of the bytes read.

All strings should be terminated with a NULL. If you use a chat array to read in bytes then you should terminate the string with a NULL. Therefore if you want to hold 20 characters, your char array would need to be 21 to hold the extra NULL to terminate the string.

The other bits just set a loop up to read each byte and add to the array, or read valid characters from the array until it encounters the NULL (/0) signifying the end of the string.


Hi tack

Thanks for the reply. I'm starting to get it. Much appreciated.


Jase :)

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131