9
#include <LiquidCrystal.h> #include <Servo.h> Servo myservo; LiquidCrystal lcd(8,9,10,11,12,13); int val = 0; char code[10]; int bytesread = 0; int flag = 1; void setup() { Serial.begin(2400); pinMode(2,OUTPUT); digitalWrite(2, LOW); lcd.begin(16,2); lcd.print("PLACE YOUR TRAVEL CARD"); } // create servo object to control a servo // LCD connections // character array to store rf-id tag // bit counter to monitor rf-id code // to verify valid rf-id card code // RFID reader SOUT pin connected to Serial RX pin at 2400bps // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin // Activate the RFID reader // set up the LCD's number of columns

RFID + ARDUINO PRG

Embed Size (px)

DESCRIPTION

This document contains the program to interface the RFIDs with the Arduino Micro-controller in the Basic C language.And it is well supported by statements for the understanding of the students.

Citation preview

Page 1: RFID + ARDUINO PRG

#include <LiquidCrystal.h>

#include <Servo.h>

Servo myservo;

LiquidCrystal lcd(8,9,10,11,12,13);

int val = 0;

char code[10];

int bytesread = 0;

int flag = 1;

void setup()

{

Serial.begin(2400);

pinMode(2,OUTPUT);

digitalWrite(2, LOW);

lcd.begin(16,2);

lcd.print("PLACE YOUR TRAVEL

CARD");

}

// create servo object to control a servo

// LCD connections

// character array to store rf-id tag

// bit counter to monitor rf-id code

// to verify valid rf-id card code

// RFID reader SOUT pin connected to

Serial RX pin at 2400bps

// Set digital pin 2 as OUTPUT to

connect it to the RFID /ENABLE pin

// Activate the RFID reader

// set up the LCD's number of columns

and rows:

// Print a message to the LCD.

Page 2: RFID + ARDUINO PRG

void loop()

{

Serial.begin(2400);

lcd.setCursor (0, 0);

int vall = digitalRead(ippin);

if (vall == HIGH)

{

lcd.clear();

lcd.print("TRESSPASSER");

}

lcd.print("PLACE YOUR TRAVEL

CARD");

if(Serial.available() > 0)

{

if((val=Serial.read())==10)

{

bytesread = 0;

while(bytesread<10)

{

if(Serial.available()>0)

{

val = Serial.read();

// initialize baud rate as 2400bps

// set the cursor to column 0, line 1

// to check for invalid entry

//display message

// if data available from reader

// check for header

// count value 0

// read 10 digit code

//to check if rf-id card is placed at the

reader

Page 3: RFID + ARDUINO PRG

if((val == 10)||(val == 13))

{

break;

}

code[bytesread] = val;

bytesread++;

}

}

int i= 0;

if(bytesread == 10)

{

lcd.setCursor(0, 1);

char read_code[4][10]=

{{'4','E','0','0','7','0','2','9','5','1'} ,

{'6','F','0','0','5','5','B','4','4','F'} ,

{'0','6','0','0','8','E','7','7','0','B'} ,

{'0','6','0','0','8','E','7','6','1','5'}};

int flag =0;

for(int j = 0;j<4; j++)

{

for( i = 0;i<10; i++)

{

// if header or stop bytes before the 10

digit reading

// stop reading

// add the digit

// ready to read next digit

// if 10 digit read is complete

//valid rf-id card codes for verification

//flag to check for valid card code

//to check for all valid cards

//to check each bit of valid code

Page 4: RFID + ARDUINO PRG

if (code[i] == read_code[j][i])

{

flag = 1;

}

else

{

flag = 0;

break;

}

}

if (i==10 && flag ==1)

{

break;

}

lcd.clear();

Serial.begin(9600);

if(flag == 1)

{

lcd.print("HAVE A NICE

JOURNEY");

}

//initialize baud rate to 9600 bps

//if valid card is detected

// display message

Page 5: RFID + ARDUINO PRG

else

{

lcd.print("CARD INVALID");

}

bytesread = 0;

digitalWrite(2, HIGH);

delay(1500);

digitalWrite(2, LOW);

}

}

}

//invalid rf-id card

// display message

//reset count

// deactivate the RFID reader for a

moment so it will not flood

// wait for a bit

// Activate the RFID reader