26
Aug

We can connect two RFID reader simultaneously to an arduino board and get data from there serial pin without using RX0 and TX1 pin of  arduino.

circuit diagram

We can declare two new new serial port in the arduino digital pin 2,3 and 8,9 using <NewSoftSerial.h>.

Sample code is given below…

Code :


/*
Connection details :
1. SOUT pin of RFID1 in to digital pin 8.
2. SOUT pin of RFID2_out to digital pin 2 .
*/
#include <NewSoftSerial.h>
NewSoftSerial nsso(2, 3);
NewSoftSerial nssi(8, 9);
//RFID
int  val = 0;
char code[] = "          ";
int bytesread = 0;
int  counter = 0;
char prev_code[] = "-         ";
int prev_in = 2;
void setup()
{
Serial.begin(9600);
nsso.begin(9600);
nssi.begin(9600);
Serial.println("Swipe Rfid card");
}
void loop()
{
int p = 0;
if ((millis() / 2000) % 2 == 0){ //Each 2 sec scan for each RFIDs
//RFID 1
if(nsso.available() > 0) {          // if data available from reader2
if((val = nsso.read()) == 10) {   // check for heade
bytesread = 0;
while(bytesread<10) {              // read 10 digit code
if( nsso.available() > 0) {
val = nsso.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
p = 0;    //;
}
}
}
}
}
else
{
//RFID 2
if(nssi.available() > 0) {          // if data available from reader2
if((val = nssi.read()) == 10) {   // check for header
bytesread = 0;
while(bytesread<10) {              // read 10 digit code
if( nssi.available() > 0) {
val = nssi.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
p = 1;
}
}
}
}
}
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
if (p == 0){
Serial.println("Data from 2nd RFID");
}else if (p == 1){
Serial.println("Data from 1st RFID");
}
}
bytesread = 0;
delay(500);
}      // wait for .5 seconds
} //loop

/*Connection details :
1. SOUT pin of RFID1 in to digital pin 8.2. SOUT pin of RFID2_out to digital pin 2 .
*/#include <NewSoftSerial.h>
NewSoftSerial nsso(2, 3);NewSoftSerial nssi(8, 9);
//RFIDint  val = 0;char code[] = "          ";int bytesread = 0;int  counter = 0;char prev_code[] = "-         ";int prev_in = 2;
void setup(){
Serial.begin(9600);nsso.begin(9600);nssi.begin(9600);Serial.println("Swipe Rfid card");}
void loop(){int p = 0;
if ((millis() / 2000) % 2 == 0){ //Each 2 sec scan for each RFIDs//RFID 1if(nsso.available() > 0) {          // if data available from reader2if((val = nsso.read()) == 10) {   // check for headebytesread = 0;while(bytesread<10) {              // read 10 digit codeif( nsso.available() > 0) {val = nsso.read();if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit readingbreak;                       // stop reading}code[bytesread] = val;         // add the digitbytesread++;                   // ready to read next digitp = 0;    //;}}}}}else{//RFID 2if(nssi.available() > 0) {          // if data available from reader2if((val = nssi.read()) == 10) {   // check for headerbytesread = 0;while(bytesread<10) {              // read 10 digit codeif( nssi.available() > 0) {val = nssi.read();if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit readingbreak;                       // stop reading}code[bytesread] = val;         // add the digitbytesread++;                   // ready to read next digitp = 1;}}}}}
if(bytesread == 10) {              // if 10 digit read is completeSerial.print("TAG code is: ");   // possibly a good TAGSerial.println(code);            // print the TAG code
if (p == 0){Serial.println("Data from 2nd RFID");}else if (p == 1){Serial.println("Data from 1st RFID");}}
bytesread = 0;delay(500);}      // wait for .5 seconds} //loop


Posted by on 26 Aug 2010 by shajir in Arduino, Electronics

Add reply

*