Pages: [1]   Go Down
Author Topic: Arduino + RFID + LCD Project (Need Help)  (Read 420 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I am new to arduino and needed help/suggestion on how to completing my project...

About my project :
* It is a key borrowing/returning system
* Using at least 30 key tag (for key) and 30 card tag (for user)
* Call data of the key and user from visual basic (+ sql database)
* everytime user want to borrow or return the key, user must tag the key tag and card tag

I hope u all can give me suggestion/ idea on how to complete this project...
below is my first arduino coding from the search i made (i only can made the tag code appear on the lcd but not on the serial monitor)
Ur help much appreciated...


Code:
#include <LiquidCrystal.h>
#include <NewSoftSerial.h>

NewSoftSerial RFID(2, 3);                   
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);   
                                             
unsigned char card[12];

void setup()
{
  Serial.begin(9600);
  Serial.println("Serial Ready");

  RFID.begin(9600);
  Serial.println("RFID Ready");
 
  lcd.begin(16, 2);
  lcd.print("Welcome...");
  delay (2000);
  lcd.clear(); //Clears LCD
 
}

char c;
void loop()
{
unsigned char i=0;
for(;;)
{
if (RFID.available()>0)
{
card[i]=RFID.read();
i++;
}
if (i>=13)
{
i=0;
decode();
}
}
}
void decode()
{
lcd.setCursor(0,0);
unsigned char p;
for(p=1;p<13;p++)
{

lcd.print(card[p]);
}
}

« Last Edit: July 06, 2012, 08:47:34 am by fendi46 » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4763
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You MUST use code tags and NOT quote tags for your code because currently your code contains errors which are probably caused by the wrong tags only.

Your code probably contains an error:

Code:
unsigned char card[12];

but

Code:
if (i>=13)

I can't see where you use it (see problem above) but if you use i as an index to card, you're running over limit when accessing card[12]. card has 12 elements with index from 0 to 11.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry for my mistake not using code quotes since im new here...

the code is ok but i cant make the code appear on both lcd and serial monitor, when i scan tag it only appear on the lcd...

n by the way, do you got something for my project, a tutorial or link of other working similar project could be appreciated... tq...
 
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4763
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void loop() {
  unsigned char i=0;
  for(;;) {
    if (RFID.available()>0) {
      card[i]=RFID.read();
      i++;
    }
    if (i>=13) {
      i=0;
      decode();
    }
  }
}

Your code is definitely not OK! You're writing into card[12] with a definition of card to have only 12 elements (your writing to element 13, indexes start at 0 not 1).

Code:
void decode() {
  lcd.setCursor(0,0);
  unsigned char p;
  for(p=1;p<13;p++) {
    lcd.print(card[p]);
  }
}

As you can see in the above code, you're just writing to the LCD, why are you expecting something at the serial interface to appear? Just add the line

Code:
    Serial.print(card[p]);

after the lcd.print() line. You have to change the definition of card before that!

PS: Did you notice the nice formatting of the code? It's much more readable this way.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanx for your help, i understand what u mean now, and the card tag appear on both lcd and serial monitor...

by the way do u know how to make the code can be used for my project, need some idea thought...
how to  Call data of tag from visual basic (+ sql database) / how to make connection between them...


Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4763
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For your application this code isn't robust enough. You just read 12 bytes, you don't check for start or end of a tag. This way if you once miss a byte (for whatever reason), you will always be out of order afterwards.

Connecting to your application is probably easiest using a serial connection. Define a protocol which you use then on the Arduino to send the data and trust on it on the PC side. For every tag read, send a start of message character and an end of message character. Check for the checksum of the tag.

I'm using Linux, so I'll be of no help for you on your VisualBasic stuff.
Logged

Pages: [1]   Go Up
Jump to: