Need Help on RFID Reader

Hello,

Presently im doing an RFID Project,
I need help on interfacing it to LCD and Serial Monitor.
Coding is below (Updated)...

The problem with this code is :

That the formatting and indenting are terrible. Make the code easy to read by putting each { on a new line, by putting each } on a new line, by putting no more than one statement on a line, and by using Tools + Auto format to fix the horrid indenting.

  • the tag read at rfid shows 1 by 1 at the LCD and Serial Monitor

Because that's how you tell it to appear. How do you want it to appear?

  • serial monitors shows unknown number (the one i mark with yellow color)

They are not unknown. You just don't know what they mean.

You check that there is data to read, before reading it. So, Serial.read() will never return anything in the high byte of the int it returns. The portion that you are interested in is the low byte. So the variable that you store the low byte in should be byte sized, such as uint8_t, byte, or char. Since the data is all character, I'd use char. But, that's just me.

Serial.print()ing an int causes it to be converted to a string. Serial.print() of a char that contains the same value as the int will produce quite different output, and I suspect that is the output you are expecting.

  • currently i connect the buzer with pin 9, are im doing it right? or not...

Unlikely, since you appear to have the LCD connected to pin 9, too.

You have not declared pin 9 to be an output, nor do you have any code that affects pin 9.

That the formatting and indenting are terrible. Make the code easy to read by putting each { on a new line, by putting each } on a new line, by putting no more than one statement on a line, and by using Tools + Auto format to fix the horrid indenting.

I just know it now, Thanks, i already use Tools + Auto format and update the code...

  • the tag read at rfid shows 1 by 1 at the LCD and Serial Monitor
    Because that's how you tell it to appear. How do you want it to appear?

I want the LCD and Serial Monitor just showing the RFID tag/card number. (only the number below the number that i mark with yellow)
Can you give me solution on how to do it, and what coding should i modify?

Serial.print()ing an int causes it to be converted to a string. Serial.print() of a char that contains the same value as the int will produce quite different output, and I suspect that is the output you are expecting.

Dont really know what u mean, can u explain it or show me the example with my coding?

Unlikely, since you appear to have the LCD connected to pin 9, too.
You have not declared pin 9 to be an output, nor do you have any code that affects pin 9.

So i need to declare other pin as a output for buzzer? and how do i make the buzer to beep when the RFID tag/card is touch?

Thanks in advance.

Can you give me solution on how to do it, and what coding should i modify?

Sure. It's really simple. Change this:

  int incomingByte;

to this:

  char incomingByte;
    }//no ; here

Fine. So, why is there one here?

      };

after the else?

So i need to declare other pin as a output for buzzer?

Yes.

and how do i make the buzer to beep when the RFID tag/card is touch?

The right card or the wrong card?

I suggest you look at some of the examples in the playground here. You seem to have skipped over the basics of how to turn pins on/off, and jumped right into reading RFID tags. Its going to be a lot less confusing and time consuming if you learn the basics first.

Thank for your suggestion...
Now im able to make the rfid and lcd function as i want it,

But still have 1 more thing,
-How do i make the scan card/tag clear after a period of time with out clearing all the display??

#include <SoftwareSerial.h>
#include <LiquidCrystal.h>

#define rxPin 2
#define txPin 3

LiquidCrystal lcd(7, 8, 9, 10, 11, 12); 
SoftwareSerial RFID = SoftwareSerial(rxPin, txPin);
char code[20];
int val = 0;
int bytesread = 0;
int led = 13;

void setup()
{
  Serial.begin(9600); //open serial hardware
  RFID.begin(9600); //open serial software

  pinMode(rxPin, INPUT); //set pin on arduino for receiving RFID data
  pinMode(txPin, OUTPUT); //this is not important
  pinMode(led, OUTPUT);

  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print(" WELCOME TO JKE "); 
  lcd.setCursor(0,1);
  lcd.print("   KEY SYSTEM   ");  
  delay (5000);
  lcd.clear(); //Clears LCD
  lcd.setCursor(0,0);
  lcd.print(" TOUCH CARD/KEY ");
}

void loop()
{
  val = 0;
  bytesread = 0;

  while(bytesread < 12)
  {
    // read 12 digit code
    val = RFID.read();
    if(val == 3)
    {
      break; 
    }

    if(val != 2)
    {
      code[bytesread] = val; // add the digit
      bytesread++; // ready to read next digit
      code[bytesread] = '\0'; // add the NULL
    }
  }

  if(bytesread >= 12)
  { // if 12 digit read is complete
    Serial.print(" ");
    lcd.setCursor(0,1);
    lcd.print("  ");
    for(int i=0; i<bytesread; i++)
    {
      Serial.print(code[i]);
      lcd.print(code[i]);
    }
    digitalWrite(led, HIGH);
    delay(100);
    digitalWrite(led, LOW);
    delay(100);
    digitalWrite(led, HIGH);
    delay(100);
    digitalWrite(led, LOW);
  }
}

Please tesch or instruct me on how to do it... thanks...

-How do i make the scan card/tag clear after a period of time with out clearing all the display??

There are two parts to this. First, determining that the unknown period of time has elapsed. To do that, you need to record when the RFID tag was written to the LCD. Then, you need to determine what time it is now. Both of these are done using millis(). The difference between now and then may, or may not exceed some value. If it does, you need to clear part of the screen.

That is done by simply writing a string of spaces to the LCD starting at the same place that you wrote the RFID tag.