the code is wrong. use NewSofterSerial to create another serial on some pin but NOT 0 and 1 (this is the harware serial used to communicate with PC).
RX of the new serial has to be linked with card reader's PIN 3
another digital pin has to be linked with card reader's PIN 2
new serial has to have baud-rate of 2400, luckily the other setting are the standard used.
Now put the digital pin to HIGH, and start to read the new serial: here it is!
if you want to stop reading, just put the digital pin to LOW
this is helpful if you don't want to read more than one time the same card: just put LOW the digital pin for 1 or 2 second and you are ok, but IMHO is better if you still read it and simply eliminate consecutive read of the same code in a small amount of time (like a de-bounce code for button!).
// PARALLAX RFID VCC to Arduino 5V
// PARALLAX RFID /ENABLE to Arduino D2
// PARALLAX RFID SOUT to Arduino D3
// PARALLAX RFID GND to Arduino Gnd
// Modified by Worapoht K.
#include <SoftwareSerial.h>
#define enablePin 2
#define rxPin 3
#define txPin 4
SoftwareSerial RFID = SoftwareSerial(rxPin, txPin);
#define START_CHAR 10
#define END_CHAR 13
void setup()
{
Serial.begin(9600); // Hardware serial for Monitor 2400bps
RFID.begin(2400); // RFID reader SOUT at 2400bps
pinMode(enablePin,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(enablePin, LOW); // Activate the RFID reader
}
void loop()
{
int bytesread, val;
String code = "";
digitalWrite(enablePin, LOW); // Activate the RFID reader
// Wait for header byte
while(RFID.read() != START_CHAR)
/* DO NOTHING */ ;
bytesread = 0;
while ((val = RFID.read()) != END_CHAR)
{
if (val == START_CHAR)
break; // Bad frame
bytesread++;
if (bytesread > 10)
break; // Too many characters
code += val; // append the character
}
digitalWrite(enablePin, HIGH); // Deactivate the RFID reader
if (bytesread == 10) // Valid read. 10 characters + END_CHAR
{ // if 10 digit read is complete
if (code == "48524953696548555648")
Serial.println("That's the round tag.");
else
if (code == "48704851485249505067")
Serial.println("That's the rectangular tag.");
else
{
Serial.print("Unrecognized code: "); // possibly a good TAG
Serial.println(code); // print the TAG code
}
}
delay(1000); // wait for a second
}