I’ve been having issues with my RFID project. I’m not sure if it’s in the wiring, the code, or just a bad component, but I was hoping for some advice.
I posted one instance of code I found, and have tried 4 others I found on Google, each of which returned the serial values “255 255 255 255…”, so I kind of doubt its the code.
It is hooked up as follows:
Arduino ID-20
5V VCC
GND GND
D2 D0
Lastly, I assume the components work fine, because it never returns any serial values to my com port until I wave the tag in front of it.
Any ideas?
#include <SoftwareSerial.h>
SoftwareSerial RFID(2, 3); // RX and TX
unsigned char i;
void setup()
{
RFID.begin(9600); // start serial to RFID reader
Serial.begin(9600); // start serial to PC
}
void loop()
{
if (RFID.available() >= 2)
{
i = RFID.read();
Serial.print(i);
Serial.print(" ");
}
}
Please read this:- How to use this forum
Because your post is breaking the rules about posting code.
You will also that these rules ask you for a link to the part you are using and a schematic ( not Fritzing ) of how you have wired things up.
That code will only print out anything when there are two or more characters in the buffer so it will never read the whole code, there will always be one character missing.
As far as the code goes - I receive the same result, "255 255 255 255" when, instead of using the line
if(RFID.available() >= 2)
I use
if(RFID.available())
If I'm interpreting your response correctly, this should print every character in the buffer. What could cause the repeated 255s?
You forgot the other things I asked, a link to what you bought and a schematic.
I could not find any reference to D0 on the ID-20 stuff I found on line, so I need to know what you did.
A value of 255 is often the symptom of an upside down signal. You can get theses if the device is outputting RS232 directly into an Arduino pin. But that is just a guess because you have not supplied sufficient information.
You could look at my YouTube video #34 which is all about an RFID reader, may be the same as yours (but I can't seem to find a reference to the one you're using).
At the very least it might give you some ideas where you're going wrong.
URL to my YouTube channel in the footer of this post.
There are a few things missing from your wiring. Pin 2 should be connected to pin 11.
Also pin 7 is the output format selector. As this is not connected to anything it is likely that it is outputting Wegand format. That code you have is expecting a serial ASCII output, to get a serial output you should connect pin 7 to ground.