Hi Don,
When I was experimenting with RFID, I was using the ID-20: https://www.sparkfun.com/products/11828. This unit has a very good range and is easy to use with an Arduino. Here is the Sparkfun hookup guide: https://learn.sparkfun.com/tut...882562561.1510038480
See below for more notes and sample code. Good luck!
Randy
Here are some raw notes I'll copy and paste from my testing in 2015/2016 which may be helpful:
Only need 3 wires coming off of ID-20LA RFID reader.
Pin 1 (GND) and Pin 7 (FORM) to Ground
Pin 2 (RES) and Pin 11 (VCC) to +5v
Pin 9 (D0) to Arduino serial port Rx. I.e. pin 15 for Serial3 RX
Pin 10 (READ) sets to +5v on RFID read, so good for LED via resistor to ground
TESTING 1/21/16: Connected the RFID reader to an Arduino using just three wires: +5v, ground, and signal (RFID reader pin 9.) It is important to power the RFID reader from the same power as the Arduino for the signal to work reliably. Also connected RFID reader pin 10 to the POSITIVE side of an LED, with a resistor then to ground. LED lights when code is read.
CABLE LENGTH 1/21/16: Tested the RFID reader connected to Arduino via a 62-foot-long 4-conductor 22awg cable (I have 1000' of this, very inexpensive.) looked at signal quality at each end of the cable and it was excellent both ways. So standard serial connection (one wire) even over such a long distance works no problem! No need for RS-485 due to length of wire between RFID reader and Arduino.
Important: 1/21/16: If the power does not have a common ground and common +5v between the RFID reader and the Arduino, the RFID reader may APPEAR to work correctly, however each reading for a given tag is likely to be wrong and possibly different each time. A power reset must be done to correct this.
FOR THIS REASON, because it can spit out random incorrect IDs, we should probably track more than three digits of each code -- to minimize the possibility of a random (bad) code matching an actual code. We can at least do four digits with an integer value.
Finally, here is some test code I wrote a few years ago -- it might help you get started:
// Rev 06-29-2015 by RDP
#define RFIDBUFSIZE 16 // Size of data sent by RFID reader
#define RFIDSTX 2
#define RFIDCR 13
#define RFIDLF 10
#define RFIDETX 3
void setup() { // Set up code called once on start-up
Serial.begin(9600); // Serial monitor
Serial.println("RFID Card Reader Test");
Serial3.begin(9600); // RFID reader will connect to Serial3
while (Serial3.read() > 0) { // Clear out any incoming RFID junk
delay(1);
}
}
void loop() { // Main code, to run repeatedly
if (Serial3.available()) {
byte rfidCode = getRFID();
Serial.print("Scanned RFID: ");
Serial.println(rfidCode);
// check to see if we already have registered this code, etc.
}
Serial.print(".");
delay(2000); // kill some time
}
////////////////////////////////
/// Define various functions ///
////////////////////////////////
byte getRFID() {
/* Gets called if there is at least a byte of data waiting in the incoming
serial buffer for the RFID reader. This routine reads the entire RFID,
does some basic confirming that it's a good read, and returns a byte 0..255
based on the last two hex digits of the scanned RFID code.
We could use all 10 hex digits, but totally unnecessary. We simply need
to be sure that we don't use two RFID tags that share the same last two
digits. There are 256 possible values, so not much chance of dup tags.
Assumes using the ID-20LA RFID reader.
Connect RFID reader pins as follows:
Pin 1 and Pin 7 to Ground
Pin 2 and Pin 11 to +5v
Pin 9 to Arduino serial port Rx. I.e. pin 15 for Serial3 RX
RFID reader sends 16 bytes each time it is activated:
Byte 1 = STX (0x02)
Byte 2..11 = 10 bytes of data, the unique ID. ASCII '0'..'9', 'A'..'F'
Byte 12..13 = 2 bytes of checksum
Byte 14..15 = CR + LF (decimal 13 and 10)
Byte 16 = ETX (0x03)
A typical string coming from the serial interface, in decimal, might be:
2, 54, 56, 48, 48, 57, 51, 55, 53, 67, 55, 52, 57, 13, 10, 3
We would look at 67, 55 -- which is 'C' '7' in ASCII read as hex, which is 199 decimal.
This is calculated as (12 * 16) + 7 = 199.
*/
byte rfidData[RFIDBUFSIZE]; // Buffer for incoming data
// Wait for all 16 bytes to be reading in serial buffer
do {} while (Serial3.available() < RFIDBUFSIZE);
for (int RFIDByte = 0; RFIDByte < RFIDBUFSIZE; RFIDByte++) {
rfidData[RFIDByte] = Serial3.read();
// Serial.println(rfidData[RFIDByte]);
}
if ((rfidData[0] != RFIDSTX) || (rfidData[13] != RFIDCR) || (rfidData[14] != RFIDLF) || (rfidData[15] != RFIDETX)) {
Serial.println("Houston, we have a problem!");
} else {
// Serial.println("All internal bytes look okay!");
}
// We will take the last two digits of the RFID code.
// ASCII '0'..'9' is 48..57. Subtract 48 from ASCII value to get value 0..9.
// ASCII 'A'..'F' is 65..70. Subtract 55 from ASCII value to get value 10..15.
// Then multiply by 1 or 16, depending on the position.
byte rfidCode = 0; // 00..FF = 0..255
if (rfidData[9] <= 57) { // Must be ASCII '0'..'9'
rfidCode = (rfidData[9] - 48) * 16;
} else { // Must be ASCII 'A'..'F'
rfidCode = (rfidData[9] - 55) * 16;
}
if (rfidData[10] <= 57) {
rfidCode = rfidCode + (rfidData[10] - 48);
} else {
rfidCode = rfidCode + (rfidData[10] - 55);
}
return rfidCode;
}