hello friends,
i did rfid door lock, , working fine. want put 2 rfid readers, i'm unable to. can tell me what's wrong?
code > 9000 characters, i'm removed functions irrelevant question. full code attached
i did try change baud rate of new 1 14400, still nothing.
help please..
thanks
i did rfid door lock, , working fine. want put 2 rfid readers, i'm unable to. can tell me what's wrong?
code: [select]
#include <softwareserial.h>
softwareserial rfid(2, 3); // rx , tx
softwareserial outrfid(6, 7); // rx , tx
int data1 = 0;
int yes = 9;
int no = 4;
int buzzer = 5;
char str6[15] = "swipe card"; // display on lcd default
char buffer[5];
char serinstring[25];
int pid =0;
int serinlen = 25;
// use allowedtags[0] in place of tag1 , allowedtags[1] in place of tag2, etc
int allowedtags[][11] = {
{49,50,48,48,48,55,49,50,51,57,13}, // tag 1
{50,51,48,55,53,49,52,50,55,56,13} // tag 2
};
int blockedtags[][11] = {
{53,50,56,55,51,57,53,55,51,57,13}, // tag 1
};
int newtag[11] = { 0,0,0,0,0,0,0,0,0,0,0}; // used read comparisons
char* tagname[] = {
"hanish", // tag 1
"jeremy clarkson", // tag 2
"dexter d dog", // tag 3
};
char* tagnameblock[] = {
"tom", // tag 1
"jeerry", // tag 2
};
// number of entries is:
const int tagcount = sizeof allowedtags / sizeof allowedtags[0];
const int tagcount2 = sizeof blockedtags / sizeof blockedtags[0];
void setup()
{
rfid.begin(9600); // start serial check in rfid reader
outrfid.begin(9600); // start serial check out rfid reader
serial.begin(9600); // start serial pc
pinmode(yes, output); // status leds
pinmode(no, output);
pinmode(buzzer, output); // sets pin output
lcdinitialise();
lcdclear();
lcdstring(str6);
serial.println("#s|logrfid|[]#");
}
void readtags()
{
if (rfid.available() > 0)
{
// read tag numbers
delay(100); // needed allow time data come in serial buffer.
serial.print("tag id :");
(int z = 0 ; z < 11 ; z++) // read rest of tag
{
data1 = rfid.read();
newtag[z] = data1;
serial.print(newtag[z]);
for(int zx=0 ; z < 10 ; z++)
{
serial.print(",");
break;
}
}
serial.println(" ");
rfid.flush(); // stops multiple reads
// search tag database particular tag
int tagid = findtag( newtag );
int tagid2 = findblockedtag( newtag );
if( tagid > 0 )
{
cardaccepted();
}
else if( tagid2 > 0)
{
cardblocked();
}
else
{
serial.println("tag unidentified");
cardrejected ();
}
serial.println(); // blank separator line in output
}
}
void readtagsout()
{
if (outrfid.available() > 0)
{
// read tag numbers
delay(100); // needed allow time data come in serial buffer.
serial.print("tag id :");
(int z = 0 ; z < 11 ; z++) // read rest of tag
{
data1 = outrfid.read();
newtag[z] = data1;
serial.print(newtag[z]);
for(int zx=0 ; z < 10 ; z++)
{
serial.print(",");
break;
}
}
serial.println(" ");
outrfid.flush(); // stops multiple reads
// search tag database particular tag
int tagid = findtag( newtag );
int tagid2 = findblockedtag( newtag );
if( tagid > 0 )
{
cardaccepted();
}
else if( tagid2 > 0)
{
cardblocked();
}
else
{
serial.println("tag unidentified");
cardrejected ();
}
serial.println(); // blank separator line in output
}
}
boolean comparetag(int aa[11], int bb[11])
{
boolean ff = false;
int fg = 0;
(int cc = 0 ; cc < 11 ; cc++)
{
if (aa[cc] == bb[cc])
{
fg++;
}
}
if (fg == 11)
{
ff = true;
}
return ff;
}
/**
* search specific tag in database
*/
int findtag( int newtag[11] ) {
(int thiscard = 0; thiscard < tagcount; thiscard++) {
// check if tag value matches row in tag database
if(comparetag(newtag, allowedtags[thiscard]) == true)
{
// row in database starts @ 0, add 1 result so
// card id starts 1 instead (0 represents "no match")
return(thiscard + 1);
}
}
// if don't find tag return tag id of 0 show there no match
return(0);
}
int findblockedtag( int newtag[11] ) {
(int thiscard = 0; thiscard < tagcount2; thiscard++) {
// check if tag value matches row in tag database
if(comparetag(newtag, blockedtags[thiscard]) == true)
{
// row in database starts @ 0, add 1 result so
// card id starts 1 instead (0 represents "no match")
return(thiscard + 1);
}
}
// if don't find tag return tag id of 0 show there no match
return(0);
}
void cardaccepted(void) //function when card accepted
{
int tagid = findtag( newtag );
exceltimestamp();
excelnamelog();
excellog();
serial.print("#s|sendk|[");
serial.print(itoa((pid), buffer, 10));
serial.print("&");
serial.print("access granted");
serial.print(" {tab} ");
serial.println("]#");
excelnext();
excelsave();
serial.print("name : ");
serial.println(tagname[tagid - 1]);
serial.println("accepted");
lcdinitialise();
lcdclear();
lcdstring("hello ");
lcdstring(tagname[tagid - 1]);
analogwrite(buzzer,100);
digitalwrite(yes, high);
delay(600);
digitalwrite(buzzer, low);
digitalwrite(yes, low);
delay(1000);
lcdinitialise();
lcdclear();
lcdstring(str6);
}
void cardblocked(void) //function when card rejected
{
exceltimestamp();
excelblockednamelog();
excellog();
serial.print("#s|sendk|[");
serial.print(itoa((pid), buffer, 10));
serial.print("&");
serial.print("tag blocked");
serial.print(" {tab} ");
serial.println("]#");
excelnext();
excelsave();
serial.println("tag blocked");
digitalwrite(no, high);
lcdinitialise();
lcdclear();
lcdstring("tag blocked");
analogwrite(buzzer,10);
delay(100);
digitalwrite(buzzer, low);
digitalwrite(no, low);
delay(200);
digitalwrite(no, high);
analogwrite(buzzer,10);
delay(200);
digitalwrite(no, low);
digitalwrite(buzzer, low);
delay(300);
lcdinitialise();
lcdclear();
lcdstring(str6);
digitalwrite(no, low);
}
void cardrejected(void) //function when card rejected
{
exceltimestamp();
excelnamelog();
excellog();
serial.print("#s|sendk|[");
serial.print(itoa((pid), buffer, 10));
serial.print("&");
serial.print("tag unidentified");
serial.print(" {tab} ");
serial.println("]#");
excelnext();
excelsave();
serial.println("tag unidentified");
digitalwrite(no, high);
lcdinitialise();
lcdclear();
lcdstring("no access ");
analogwrite(buzzer,10);
delay(100);
digitalwrite(no, low);
analogwrite(buzzer,50);
delay(500);
digitalwrite(buzzer, low);
digitalwrite(no, high);
delay(400);
digitalwrite(no, low);
delay(1000);
lcdinitialise();
lcdclear();
lcdstring(str6);
digitalwrite(no, low);
}
void loop()
{
readtags();
readtagsout();
}
code > 9000 characters, i'm removed functions irrelevant question. full code attached
i did try change baud rate of new 1 14400, still nothing.
help please..
thanks
your function "readtags" looks me identical function "readtagsout" - why?
please post code , explain problem is.
please post code , explain problem is.
Arduino Forum > Using Arduino > Programming Questions > 2 RFID Readers
arduino
Comments
Post a Comment