RFID Reader Parrallax and Arduino ATMEGA 1280

ok so i have had my Mega for a couple years collecting dust and the rfid reader whitch i could never get working but no more slacking off XD!! Now i plan on getting it working ! Since i have an Arduino Mega, copying and paste codeing wont work here so this is what i uploaded to my mega

#include <SoftwareSerial.h>

int  val = 0; 
char code[10]; 
int bytesread = 0; 

#define rxPin 22  // RFID reader SOUT pin connected to Serial RX pin at 2400bps to digital pin 22
#define txPin 23  // nothing connected


void setup()
{ 
  Serial.begin(2400);  // Hardware serial for Monitor 2400bps

  pinMode(24,OUTPUT);       // Set digital pin 24 as OUTPUT to connect it to the RFID /ENABLE pin 
  digitalWrite(24, LOW);    // Activate the RFID reader 
}


void loop()
{ 
  SoftwareSerial RFID = SoftwareSerial(rxPin,txPin); 
  RFID.begin(2400);

  if((val = RFID.read()) == 10)
  {   // check for header 
    bytesread = 0; 
    while(bytesread<10)
    {  // read 10 digit code 
      val = RFID.read(); 
      if((val == 10)||(val == 13))
      {  // if header or stop bytes before the 10 digit reading 
        break;                       // stop reading 
      } 
      code[bytesread] = val;         // add the digit           
      bytesread++;                   // ready to read next digit  
    } 

    if(bytesread == 10)
    {  // if 10 digit read is complete 
      Serial.print("TAG code is: ");   // possibly a good TAG 
      Serial.println(code);            // print the TAG code 
    }
    bytesread = 0; 
    delay(500);                       // wait for a second
  } 
}

(modified by moderator)

nothing happens when i swipe any rfid tag by please help

Since i have an Arduino Mega

Why are you using software serial? You will be much better off using the hardware serial ports.

Please use the # icon when posting code so we can read it without distortion.

You don't seem to be checking if data is available you are just reading it.

also your are redefining the serial connection on every loop and since your using an arduino mega as Grumpy_Mike suggested you could use one of the hardware serial ports and to check how many chars you have incoming on your serial port use Serial.available()

yes you are right, and since i am sure you have noticed i have ZERO coding knowledge. I just fount this on code on Aquino's website with a Google search and pasted it i know i have a lot more learning to do! could you please give me an example of what i should put in my code?

You will be much better off using the hardware serial ports.

How do i DO THAT ????

With the code right now my arduino seems do do nothing

How do i DO THAT ????

We may be a bunch of grumpy old men, but we aren't deaf.

Connect the RFID reader to pins 14 and 15, and use Serial1 instead of the SoftwareSerial instance.

pins 14 and 15, and use Serial1

Would that not be Serial3 according to my Mega 1280?

Would that not be Serial3 according to my Mega 1280?

Could be. Remember I'm a grumpy old man who can't see as well as I used to.

Connect the RFID reader to pins 14 and 15, and use Serial1 instead of the SoftwareSerial instance.

Paul Mike and every one else thank you for taking your time to help me. I know i am a little bit clueless when it comes to PBasic or Arduinos code so your input is deeply appreciated!

Paul you said to connect to pins 14 and 15 I am not even sure if i am connecting the device correctly
Please can you give some more detail as i don't understand

Here is how i have it connected now at home

Parallax RFID Arduino Mega ATMEGA1280

VCC 3V Pin
/ENABLE Digital pin 24
SOUT Digital Pin 22
GND GND on the Arduino

i dont know why in the code on Arduino Playground - HomePage WHY is the TX pin Declared ???? If you Like i can Post some pics or a video if you like!

VCC 3V Pin

Why as the data sheet says:-

VCC System power, +5V DC input.

WHY is the TX pin Declared ?

It is not?
Pin 2 is for the enable and the reader goes into the RX pin.

Connect the RFID reader to pins 14 and 15, and use Serial1 instead of the SoftwareSerial instance.

Then is this how i should do it???

Parallax RFID Arduino Mega ATMEGA1280

VCC 5V Pin
/ENABLE Communication TX PIN 1
SOUT Communication RX PIN 0
GND GND on the Arduino

Then is this how the code should look like

#include <Serial1.h>

int  val = 0; 
char code[10]; 
int bytesread = 0; 

#define rxPin 0  // RFID reader SOUT pin connected to Serial RX pin at 2400bps to digital pin 22
#define txPin 14 // DO I TAKE A WIRE AND CONNECT IT TO RX pin 0 ?????


void setup()
{ 
  Serial.begin(2400);  // Hardware serial for Monitor 2400bps

  pinMode(1,OUTPUT);       // Set communication pin 1 as OUTPUT to connect it to the RFID /ENABLE pin 
  digitalWrite(1, LOW);    // Activate the RFID reader 
}


void loop()
{ 
  Serial1 RFID = Serial1(rxPin,txPin); 
  RFID.begin(2400);

  if((val = RFID.read()) == 10)
  {   // check for header 
    bytesread = 0; 
    while(bytesread<10)
    {  // read 10 digit code 
      val = RFID.read(); 
      if((val == 10)||(val == 13))
      {  // if header or stop bytes before the 10 digit reading 
        break;                       // stop reading 
      } 
      code[bytesread] = val;         // add the digit           
      bytesread++;                   // ready to read next digit  
    } 

    if(bytesread == 10)
    {  // if 10 digit read is complete 
      Serial.print("TAG code is: ");   // possibly a good TAG 
      Serial.println(code);            // print the TAG code 
    }
    bytesread = 0; 
    delay(100);                       // wait for a second 
  } 
}

/ENABLE Communication TX PIN 1

No this is an enable pin and has to be placed low to enable the reader, it should not be connected to the TX line but any general output pin.

No this is an enable pin and has to be placed low to enable the reader, it should not be connected to the TX line but any general output pin.

Then should i connect it to Communication TX PIN 14
and is my code correct like this

#include <Serial1.h>

int  val = 0; 
char code[10]; 
int bytesread = 0; 

#define rxPin 0  // RFID reader SOUT pin connected to Serial RX pin at 2400bps to digital pin 22
#define txPin 1 // DO I TAKE A WIRE AND CONNECT IT TO RX pin 0 ?????


void setup()
{ 
  Serial.begin(2400);  // Hardware serial for Monitor 2400bps

  pinMode(14,OUTPUT);       // Set communication pin 1 as OUTPUT to connect it to the RFID /ENABLE pin 
  [glow=yellow,2,300]digital[/glow]Write(14, LOW);    // Activate the RFID reader also should i take out the digital?
}


void loop()
{ 
  Serial1 RFID = Serial1(rxPin,txPin); 
  RFID.begin(2400);

  if((val = RFID.read()) == 10)
  {   // check for header 
    bytesread = 0; 
    while(bytesread<10)
    {  // read 10 digit code 
      val = RFID.read(); 
      if((val == 10)||(val == 13))
      {  // if header or stop bytes before the 10 digit reading 
        break;                       // stop reading 
      } 
      code[bytesread] = val;         // add the digit           
      bytesread++;                   // ready to read next digit  
    } 

    if(bytesread == 10)
    {  // if 10 digit read is complete 
      Serial.print("TAG code is: ");   // possibly a good TAG 
      Serial.println(code);            // print the TAG code 
    }
    bytesread = 0; 
    delay(100);                       // wait for a second 
  } 
}

You are aware that the IDE has a button labeled Verify, right? Why are you posting code that hasn't a snowballs chance in .... of compiling?

There is no Serial1.h file. Serial1 is an instance of the HardwareSerial class. It is already defined.

You do not create an instance of the Serial1 class called RFID. The RX and TX pins for Serial1 are known to the Serial1 instance, and they are not pins 0 and 1.

Even in the old code, creating a new instance of the SoftwareSerial class every pass through loop was stupid. Whoever wrote the code you started with was clueless.

Get rid of the first line in loop. Get rid of the #include statement.

Change all occurrences of RFID to Serial1. Move the Serial1.begin() statement to setup() where it belongs.

Paul i don’t know anything about coding

i am trying to learn with this project
after following your instructions i am still very confused and the code still dose not work

here is the revised code

int  val = 0; 
char code[10]; 
int bytesread = 0; 




void setup()
{ 
  Serial.begin(2400);  // Hardware serial for Monitor 2400bps

  pinMode(14,OUTPUT);       // Set communication pin 1 as OUTPUT to connect it to the RFID /ENABLE pin 
  digitalWrite(14, LOW);    // Activate the RFID reader also should i take out the digital?
}


void loop()
{ 
  Serial1.begin(2400);

  if((val = Serial1.read()) == 10)
  {   // check for header 
    bytesread = 0; 
    while(bytesread<10)
    {  // read 10 digit code 
      val = Serial1.read(); 
      if((val == 10)||(val == 13))
      {  // if header or stop bytes before the 10 digit reading 
        break;                       // stop reading 
      } 
      code[bytesread] = val;         // add the digit           
      bytesread++;                   // ready to read next digit  
    } 

    if(bytesread == 10)
    {  // if 10 digit read is complete 
      Serial.print("TAG code is: ");   // possibly a good TAG 
      Serial.println(code);            // print the TAG code 
    }
    bytesread = 0; 
    delay(100);                       // wait for a second 
  } 
}

my sout pin is connected to rx 0
my /enable pin is connected to tx3 14

Why are you still calling Serial1.begin() in loop()?

my sout pin is connected to rx 0
my /enable pin is connected to tx3 14

Why? Have you yet to figure out that SOUT is the OUTPUT from the RFID reader, so it needs to go to a Serial IN?

Have you not figured out that /enable needs to go to a digital pin that you set LOW?

Didn't Grumpy_Mike point out that pin 14 is associated with Serial3, not Serial1? You can use either one, but you must use the one that you connect SOUT to. And DO NOT connect SOUT to RX0.

Is there any one who can help me with this????????

I Got It Today Finely i Got My ARDUINO MEGA 1280 WORKING WITH THE RFID READER

Ok here is the pin out

VCC - 5V
/Enable - DIGITAL PIN 22
SOUT - RX pin 0
GND - GND

#define TAG_LEN 12

char tag[12] = {'0', '1', '0', '3', '6', 'A', 'F', '2', 'B', '1'};
char code[12];
int bytesread = 0;
int ledPin = 13; // Connect LED to pin 13
int rfidPin = 22; // RFID enable pin connected to digital pin 2
int val=0;
void setup() {

Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
pinMode(rfidPin,OUTPUT);   // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
pinMode(ledPin,OUTPUT); // Set ledPin to output

digitalWrite(rfidPin, LOW); // Activate the RFID reader
}

 void loop() {

  if(Serial.available() > 0) {	    // if data available from reader
    if((val = Serial.read()) == 10) {   // check for header
	bytesread = 0;
	while(bytesread<10) {		  // read 10 digit code
	  if( Serial.available() > 0) {
	    val = Serial.read();
	    if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
		break;			     // stop reading
	    }
	    code[bytesread] = val;	   // add the digit
	    bytesread++;			 // ready to read next digit
	  }
	}
	if(bytesread >= 10) {		  // if 10 digit read is complete

	 if(strcmp(code, tag) == 0) {
	   Serial.print("Tag matches: ");
	   Serial.println(code);
	   blink();
	 }
	 else {
	   Serial.print(code);
	   Serial.println(" does not match");
	   digitalWrite(ledPin,HIGH);
	 }


	}
	bytesread = 0;
	     delay(500);			     // wait for a second
    }
  }
}

void blink() {
  digitalWrite(ledPin, HIGH);
  delay(250);
  digitalWrite(ledPin, LOW);
  delay(250);
}

// extra stuff
// digitalWrite(2, HIGH);		 // deactivate RFID reader