RFID and a LCD

After a long wait my delivery arrived with the new RFID kit and 16×2 LCD.
So first thing to work on was the LCD, and what better to start with than “Hello World”! Having not used the Arduino for some time I started with the LiquidCrystal HelloWorld example and then worked from there.

 

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(“hello, world!”);
}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);// print the number of seconds since reset:
lcd.print(millis()/1000);
}

After checking that I had everything working correctly using HelloWorld, I started experimenting displaying variables and changing the location of the cursor.

Next to work on the RFID module.

Not having an example to start with, I did a little searching online to find an excellent Instructables post. From this post I learned that with the RFID tx pin connected to the arduino’s rx pin, you can you the Serial.read() command to read the unique identifier.

/* RFID ID12 */
//RFID tx pin –> arduino rx pin

char val = 0; // variable to store the data from the serial port

void setup() {
Serial.begin(9600); // connect to the serial port

}

void loop () {
// read the serial port
if(Serial.available() > 0) {
val = Serial.read();
Serial.write(val);
}
}

Now that I was able to display text on the LCD and also read the values of the RFID tags, the next logical step was to combine the two together!

Now working on my own code, I set out to get the LCD asking for the card to be scanned, and then displaying the number of the card.

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

void setup() {

lcd.clear();

// put your setup code here, to run once:
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print(“Please Scan Your”);
lcd.setCursor(0,1);
lcd.print(“Card:”);

}

void loop() {
// put your main code here, to run repeatedly:
if(Serial.available() > 0) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
lcd.print(“Your Card is”);

lcd.setCursor(0, 1);
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());

}
delay(1000);
lcd.clear();
}
}

Advertisements

One thought on “RFID and a LCD

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s