Arduino Uno R3 code questions

Hello fellow programmers,

I am very new with this concept of programing. I absolutely know nothing about programming.

What I am doing is using a EM-18 RFID reader connected to a Uno R3 for a model railway inventory system. Whereby the reader is placed under the track and RFID tag placed in each piece of rolling stock using the RFID code to identify each piece of stock. This simple code works well but each time I scan a tag it adds it on to the end of the tag id before it. for example.

12345678900987654321.

What I would like to see after each tag is scanned the next scanned tag will go on a new line.

1234567890
0987654321
and so on for each scan

the code I am running is as follows:

int count = 0;
void setup()
{
Serial.begin(9600);
Serial.println(“Scan RFID Tag:”);
}
void loop()
{
if(Serial.available())
{
count = 0; // Reset count to zero// Keep reading Byte by Byte from the Buffer till the Buffer is empty
{
char input = Serial.read();
Serial.print(input);
count++; //
delay(5); //
}

}
}

Change this

Serial.print(input);

to this

Serial.println(input);

Serial.println() adds a line-feed

And thank you for presenting your question so clearly.

...R

Thanks Robin,

now the code puts each digit on a new line. eg

1
2
3
4

etc

your thoughts?

Then you need to read the number of characters for a single code and then do a line with Serial.println()

How will you know when you have all the characters for a code?

You might look at the Arduino code in this demo to see how to save all the data into a variable before printing any of it. There are more basic examples here. There is also an Arduino function readBytesUntil() that may be useful - but it blocks until it is satisfied.

…R

Typically the RFID reader should put a special character before and/or after the ID. Try changing running this code:

void setup() {
   Serial.begin(9600);
   Serial.println("Scan RFID Tag:");
}
void loop()
{
   if(Serial.available()) {
         char input = Serial.read();
         Serial.print(input);
         Serial.print(" 0x");
         Serial.println((int)input, HEX);
   }
}

This will display each character received and its hexadecimal character code. With luck there will be an unprintable character after the digits of the ID which will tell you when an ID ends. Let us know what you find.

thefallenlog1975:
Hello fellow programmers,

I am very new with this concept of programing. I absolutely know nothing about programming.

What I am doing is using a EM-18 RFID reader connected to a Uno R3 for a model railway inventory system.

Just out of curiosity, what scale are you modelling in?
I want to use an Arduino to detect the identity of wagons in a hump (gravity) shunting yard in OO/HO gauge and cannot find the RFID tags in the size and price I want.

Thanks John WASSER.

I ran your sketch I get this:

Scan RFID Tag:
0 0x30
1 0x31
0 0x30
0 0x30
7 0x37
0 0x30
E 0x45
8 0x38
7 0x37
2 0x32
E 0x45
B 0x42

I basically only want the tag id number parallel across the page and when I scan a new tag it starts a new line, like indicated below. cheers

1234567890
0987654321

Henry_Best:
Just out of curiosity, what scale are you modelling in?
I want to use an Arduino to detect the identity of wagons in a hump (gravity) shunting yard in OO/HO gauge and cannot find the RFID tags in the size and price I want.

Hi I am modelling HO, currently I am using small door entry fob tags, but I am looking into the Chinese market to get the glass capsule types. cheers

Robin2:
Then you need to read the number of characters for a single code and then do a line with Serial.println()

How will you know when you have all the characters for a code?

You might look at the Arduino code in this demo to see how to save all the data into a variable before printing any of it. There are more basic examples here. There is also an Arduino function readBytesUntil() that may be useful - but it blocks until it is satisfied.

...R

Thanks Robin,

re your quote

"How will you know when you have all the characters for a code?"

This is why im asking the experts..I didn't even know arduino existed a week ago. So I have no idea and for me re read you previous thread confuses me some what with out knowing the very basics first..i really appreciate your help though...

cheers

thefallenlog1975:
"How will you know when you have all the characters for a code?"

This is why im asking the experts.

What does the documentation for your RFID system say? (Post a link to the datasheet).

If every code has exactly the same number of characters you will probably get away with reading that number of characters every time. You could probably build a check for the longer time period between different tags being presented compared to the time period between individual characters.

From your test using @johnwasser's code it looks like there is no special terminating character.

...R

thefallenlog1975:
Thanks John WASSER.

I ran your sketch I get this:

Scan RFID Tag:
0 0x30
1 0x31
0 0x30
0 0x30
7 0x37
0 0x30
E 0x45
8 0x38
7 0x37
2 0x32
E 0x45
B 0x42

Is that one scan? What happens if you scan card A, then card B, then card A again? If you scan a bunch of different cards is there any pattern in the output? For example do they all end in 'B'?