Вы находитесь на странице: 1из 5

#include <LiquidCrystal.

h>

#include <Servo.h>

Servo myservo; // create servo object to control a servo

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

int val = 0;

char code[10]; // character array to store rf-id tag

int bytesread = 0; // bit counter to monitor rf-id code

int flag = 1; // to verify valid rf-id card code

void setup()

Serial.begin(2400); // RFID reader SOUT pin connected to

Serial RX pin at 2400bps

pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to

connect it to the RFID /ENABLE pin

digitalWrite(2, LOW); // Activate the RFID reader

lcd.begin(16,2); // set up the LCD's number of columns

and rows:

lcd.print("PLACE YOUR TRAVEL

CARD"); // Print a message to the LCD.

}
void loop()

Serial.begin(2400); // initialize baud rate as 2400bps

lcd.setCursor (0, 0); // set the cursor to column 0, line 1

int vall = digitalRead(ippin);

if (vall == HIGH) // to check for invalid entry

lcd.clear();

lcd.print("TRESSPASSER"); //display message

lcd.print("PLACE YOUR TRAVEL

CARD");

if(Serial.available() > 0) // if data available from reader

if((val=Serial.read())==10) // check for header

bytesread = 0; // count value 0

while(bytesread<10) // read 10 digit code

if(Serial.available()>0) //to check if rf-id card is placed at the

reader

val = Serial.read();
if((val == 10)||(val == 13)) // if header or stop bytes before the 10

{ digit reading

break; // stop reading

code[bytesread] = val; // add the digit

bytesread++; // ready to read next digit

int i= 0;

if(bytesread == 10) // if 10 digit read is complete

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'}}; //valid rf-id card codes for verification

int flag =0; //flag to check for valid card code

for(int j = 0;j<4; j++) //to check for all valid cards

for( i = 0;i<10; i++) //to check each bit of valid code

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

flag = 1;

else

flag = 0;

break;

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

break;

lcd.clear();

Serial.begin(9600); //initialize baud rate to 9600 bps

if(flag == 1)

{ //if valid card is detected

lcd.print("HAVE A NICE

JOURNEY"); // display message

}
else //invalid rf-id card

lcd.print("CARD INVALID"); // display message

bytesread = 0; //reset count

digitalWrite(2, HIGH); // deactivate the RFID reader for a

moment so it will not flood

delay(1500); // wait for a bit

digitalWrite(2, LOW); // Activate the RFID reader

Вам также может понравиться