trouble in reading rfid cards

I am new to arduino and couldn’t find the problem.rfid based secured access system is my project.i want to show “found” on lcd when the card matches with the data in the code, else “not found”.but my lcd always shows “not found”; progrm code is as follows:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//byte incomingByte[25];
int data[26];
int f=0;
int j[38]={5,4,6,8,4,8,4,8,5,0,7,0,4,8,5,7,5,6,6,8,6,7,5,4};//id of card

void setup()
{
lcd.begin(16, 2);
lcd.print(“welcome”);
delay(1000);
Serial.begin(9600);
lcd.clear();

}

void loop() {

label:lcd.print(“show card”);
delay(1000);
lcd.clear();
boolean j1=true;

if (Serial.available()> 0)
{
int i;
for( i=0;i<25;i++)
{
data = Serial.read();

  • //delay(100);*
    _ Serial.print(data*);_
    _
    }_
    _
    //data=lowByte(incomingByte)*_

* // boolean j1=true;*
* for(i=0;i<25;i++)*
* {*

if(data_==j*)j1=true;
//f=1;
}*_

* if(j1)*

* { lcd.print(" found");*
* delay(1000);*
* lcd.clear();*
* goto label;*
* }*
* //else if (j2) lcd.print(“found1”);*
* else*
* {*
* lcd.print(“not found”);*
* delay(1000);*
* lcd.clear();*
* goto label;*

* }*

* }*
}

int j[38]={5,4,6,8,4,8,4,8,5,0,7,0,4,8,5,7,5,6,6,8,6,7,5,4};//id of card

ID of what kind of card? That’s not anything like I recognize.

Get rid of the goto crap. Completely unnecessary!

        if (Serial.available()> 0)
        {
               int i;
               for( i=0;i<25;i++)
               {
                data = Serial.read();

Get a clue. If there is one or more bytes to read, that does NOT mean that it is OK to read all 24 of them.

Why is the array j sized to hold 38 characters, if the tag is only 24?

There was a sticky at the top of the forum that you clearly didn’t read. Otherwise, you’d have posted the code correctly.

It’s also a bad idea to connect things like RFID readers to THE serial port, eliminating the ability to debug.

am sorry, i done a mistake,its j[25].its id of rfid card got by connecting reader with pc. i connected tx pin of rfid reader to arduino rx pin. pls help me, what should i do next?

its id of rfid card got by connecting reader with pc.

How did you connect the two? What kind of reader is it?

using an rs232 converter i connected the rfid reader and pc.am using EM 18 rfid reader module.then i got the code which i mentioned in the program.then i connected reader's tx pin with rx pin in arduino and interfaced lcd.

pls help me, what should i do next?

Correct the things you have been told about test them and post the code again and say what it does now.

program code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

byte data[24];

int j[24]={5,4,6,8,4,8,4,8,5,0,7,0,4,8,5,7,5,6,6,8,6,7,5,4};//id of card

void setup()
{

lcd.begin(16, 2);
lcd.print(“welcome”);
delay(1000);
Serial.begin(9600);
lcd.clear();

}

void loop() {

label:lcd.print(“show card”);
delay(1000);
lcd.clear();
boolean j1=true;

if (Serial.available()> 0)
{
int i;
for( i=0;i<24;i++)
{

data = Serial.read();
_ Serial.print(data*);_
_
}*_

* for(i=0;i<25;i++)*
* {*

if(data != j )
* j1=false;*
* break;*

* }*

* if(j1)*

* { lcd.print(" found");*
* delay(1000);*
* lcd.clear();*
* goto label;*
* }*

* else*
* {*
* lcd.print(“not found”);*
* delay(1000);*
* lcd.clear();*
* goto label;*

* }*

* }*
}
when i upload this and shows the card,“not found” appears in the display. This is what i am getting on serial monitor:"
546848485070485756686754-1-1-1-1-1-1-1-1-1-1-1-1-1", which is so called id of card(excluding '-1’s.

Grumpy_Mike: Correct the things you have been told about test them and post the code again and say what it does now.

So why have you not done this?

Read the how to use this forum sticky and post the code correctly. Do not read data from the serial port if it has not arrived, that is why you get -1 Put the data you get into an array. Compair the array elements one at a time, if any one does not match then set a match variable from true to false.

data[24] is my array to receive the id… i attached my code below,pls check and help me…

pgm2rfid.ino (1.37 KB)

boolean j1=true;
              for(i=0;i<25;i++)
              {            
                  if( data[i] !=j [i]) j1= false;
              }
           goto label;

No no no no no no no no no no no
Never never never use goto!!!

Go back to Reply #1. You have NOT gotten ridden of the useless gotos. You have NOT changed how you are reading data.

You are not getting good data from the card. Until you do that, you are wasting your time, and ours, trying to make sense of it.

There are plenty of examples around for reading serial data. One thing that they ALL have in common is that they do NOT assume that because there is one byte available that they can then read all 24 of them.

You are reading from, and writing to, Serial. If your RFID reader is attached to pins 0 and 1, you can NOT use those pins for debugging, too. You can read from, and write to, the RFID reader OR the PC. NOT both.

can you please give me an example for reading serial data????? if i remove the gotos it becomes infinite.....

can you please give me an example for reading serial data?

http://www.ladyada.net/learn/arduino/lesson4.html

if i remove the gotos it becomes infinite.

Rubbish. What do you mean by that?

if i remove the gotos it becomes infinite…

You need to explain what this means. The loop() function IS called in an infinite loop. That is as it should be.

Reading serial data properly requires that the data be either a fixed size or properly delimited. Which, if either, is true in your case is hard to determine since you won’t provide a link to the reader or the cards and you won’t describe how the reader is attached to the Arduino.

If the data IS a fixed length, and you can be absolutely certain that none ever gets lost (an unreasonable assumption), then simply:

while(Serial.available() < 24)
{
   // Do nothing
}

// We get here when there are 24 bytes to read.

thank you sir for the example.But we need to display the "found" in LCD not in pc. sir can you please give the source code......

But we need to display the “found” in LCD not in pc. sir can you please give the source code…

Sure:

lcd.print("found");

Now, what have you done to fix your reading code? And, where the hell are the other answers you need to provide?