Go Down

### Topic: How do i decode an RFID tag to the number printed on the tag? (Read 168 times)previous topic - next topic

#### travis_farmer

##### May 12, 2016, 12:06 pm
I have found several items on the internet to read in the HEX code, but what about the numeric code on the tag?

For instance, I have one tag that has the HEX result of 0D0031EF53
the number on the tag is 0003272531

is it a one-way hash? if so, how to I convert the number to the HEX value?

#### Ralph_S_Bacon

#1
##### May 12, 2016, 02:05 pm
The number 0003272531 on the tag is in decimal.

To convert the number manually go to this website.

Were you considering using an Arduino to do this?
Simple Arduino and electronics videos designed to get your project off the ground

#### travis_farmer

#2
##### May 12, 2016, 05:01 pm
Yes, I had hopes of doing the conversion with the Arduino. I did try converting hex to decimal using the windows calculator, but I use the whole hex string, hence why I didn't get the right answer.
am I to assume the leading 0D is a checksum?

So I guess my question now is how do I take a hex string in Arduino, and either convert it to decimal, or a string with the number in it. I am actually fairly good at coding, but my brain seems to be at a loss on this one.

#### Ralph_S_Bacon

#3
##### May 12, 2016, 06:57 pmLast Edit: May 14, 2016, 11:37 am by Ralph_S_Bacon
The '0D' could be anything - vendor specific code, supplier code - who knows!

To convert a hex value like that use the 'standard' C++ functions - convert the hex string to a long integer and then (if you want to) convert that to a string.

Hex to Dec (prefix the hex with '0x')

Long Int to String (non-standard but probably works in Arduinoland)

Above methods are just suggestions - there are doubtless other ways that others may suggest too.

It would be useful to know what you want to do with all this - it may affect responses you get.

If you are thinking about getting an RFID reader for your Arduino (a Mifare MIRC522, for example) you might like to watch my YouTube video #34 RFID Reader/Writer (Mifare MFRC522) with a Logic Level Shifter that will be published at noon on Friday 13th May 2016.
Simple Arduino and electronics videos designed to get your project off the ground

#### sterretje

#4
##### May 12, 2016, 08:33 pm
Please provide your code (using code tags). Also please provide links to the reader that you use and the library that you use. Lastly provide a sample of the number on the tag (complete) and the matching data that you get when you read the tag.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

#### travis_farmer

#5
##### May 12, 2016, 09:33 pm
here is the code I am using to test the RFID Reader.
I actually found a hex to long function online, (I don't remember where)

Code: [Select]
String inputStringA = "";
long LastTag = 0;
long TagReset = 8000;
int InCount = 0;
String LastTagRX = "";

// Found this online
long hexToDec(String hexString) {

long decValue = 0;
int nextInt;

for (int i = 0; i < hexString.length(); i++) {

nextInt = int(hexString.charAt(i));
if (nextInt >= 48 && nextInt <= 57) nextInt = map(nextInt, 48, 57, 0, 9);
if (nextInt >= 65 && nextInt <= 70) nextInt = map(nextInt, 65, 70, 10, 15);
if (nextInt >= 97 && nextInt <= 102) nextInt = map(nextInt, 97, 102, 10, 15);
nextInt = constrain(nextInt, 0, 15);

decValue = (decValue * 16) + nextInt;
}

return decValue;
}

// will in the future handle what to do with the tag
void ProcIDtag(String InputStr)
{
Serial.println("Got the tag!");
Serial.print("ID: ");
InputStr = InputStr.substring(2,InputStr.length() - 2);
Serial.println(hexToDec(InputStr));
}

void setup() {
Serial.begin(9600);
Serial1.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:

}

void serialEvent1()
{
while (Serial1.available()) {
if (InCount >= 13) {
InCount = 0;
// read same tag once in 8 seconds, or a new tag right now
if ((millis() - LastTag) >= TagReset || LastTag == 0 || inputStringA != LastTagRX)
{
ProcIDtag(inputStringA);
LastTagRX = inputStringA;
LastTag = millis();
}
inputStringA = "";
}
else {
if (InCount != 0)
{
inputStringA += inCharA;
}
InCount++;
}
}
}

It seems to work pretty good with the tags I have.

one tag has the number 0003272531 on it, and the code returns 3272531 via USB serial.
I am using an Arduino Mega2560
and the RFID reader is from eBay
http://www.ebay.com/itm/172080565523

similar, I think, to
http://www.seeedstudio.com/depot/125Khz-RFID-module-UART-p-171.html

no library in needed as the core hardware serial works.

My intentions for this project is a security alarm (with a keypad). I will have a short list of RFID tags that will arm/disarm the alarm, and reference them to associated PIN numbers from the keypad (not the same numbers on the RFID tag!)
I will also me using a VGA module (based on the Gameduino) that I have not yet played around with to display status info, and logging info once logged in.
Fairly complex way to do a simple task, but that's the way I like it.

#### Paul__B

#6
##### May 13, 2016, 12:07 am
The '0D' could be anything - vendor specific code, supplier code - who knows!
Carriage return?

If you are thinking about getting an RFID reader for your Arduino (a Mifare MIRC522, for example) you might like to watch my YouTube video #34 RFID Reader/Writer (Mifare MFRC522) with a Logic Level Shifter that will be published at noon on Friday 13th May 2016.

#### Ralph_S_Bacon

#7
##### May 13, 2016, 07:32 am
Doh! That link won't become active till noon GMT on Friday. Should have thought of that! Oh well...
Simple Arduino and electronics videos designed to get your project off the ground

#### Grumpy_Mike

#8
##### May 13, 2016, 09:45 am
Some vendors of access control equipment do scramble the code in their readers so the number that comes out is not the same as the token. This is part a security thing but mainly to stop people using third party cheaper readers when enlarging their system.

#### Paul__B

#9
##### May 13, 2016, 10:44 am
Doh! That link won't become active till noon GMT on Friday. Should have thought of that! Oh well...
Well, it is now past noon GMT and it is Friday the 13th, so I seriously suggest you repair the broken link you posted!

#### Ralph_S_Bacon

#10
##### May 14, 2016, 11:41 amLast Edit: May 14, 2016, 11:41 am by Ralph_S_Bacon
Well, it is now past noon GMT and it is Friday the 13th, so I seriously suggest you repair the broken link you posted!
Even though I am now in a different country to where I live I have now logged in and repaired that broken link. Note to self: don't trust YouTube to generate working links when you are not there to check them!

Seriously though, thanks for bringing this to my attention, I have no idea how it became a broken link considering it was pasted from YouTube (unless it was a private, pre-published link just for my use).
Simple Arduino and electronics videos designed to get your project off the ground

#### Paul__B

#11
##### May 14, 2016, 01:51 pm
The breakage was due to a glitch pasting it into the dialog generated by the link ("chain") icon when the default "http://" root is not highlighted.

Go Up

Please enter a valid email to subscribe