Jonny Blanch.webs.com

games computers arduino

Arduino Page 2

This page a the RFID currently only has the RFID project on it.

 

Third Project: RFID

This project is mostly explained in the code below.

/*
Code revised and edited heavily by Jonnyblanch, Debugged and LCD added by JonnyBlanch
Tried to make it as simple as possible.
Things you need to know: 
 The code may seem redundent at times but hey it works.
 Connection that you need to make are stated just below.
 Make sure when you serial monitor your speed is at the blazing 2400.
Otherwise I think we're good here, Lets continue...
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 5); // initialize the library with the numbers of the interface pins

#define TAG_LEN 12
char tag[12] = {'3', '6', '0', '0', '7', '8', '9', '9', '8', '7'}; //tag 1
char tag2[12] = {'3', '6', '0', '0', '7', '8', '9', 'B', 'B', '5'}; //tag 2
char code[12];
int bytesread = 0;
//Connections to be made:
int ledPin = 13; // Connect LED to pin 13
int rfidPin = 2; // RFID enable pin connected to digital pin 2
//Connect SOUT Pin to pin 0, does not need to be defined because 0 is the default RX pin
int val=0;
void setup() {
lcd.begin(16, 2); // set up the LCD's number of rows and columns
lcd.print("Initializing...");
delay (1000);

Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps 
pinMode(rfidPin,OUTPUT);   // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
pinMode(ledPin,OUTPUT); // Set ledPin to output

digitalWrite(rfidPin, LOW); // Activate the RFID reader
}

 void loop() {
digitalWrite(ledPin,LOW); //LED off
digitalWrite(rfidPin, LOW); // Activate the RFID reader
 lcd.clear(); //Clears LCD
 lcd.setCursor(0, 0);
 lcd.print("  Please Swipe");
 lcd.setCursor(0, 1);
 lcd.print("   Your Card");
  if(Serial.available() > 0) {	    // if data available from reader
    if((val = Serial.read()) == 10) {   // check for header
	bytesread = 0;
	while(bytesread<10) {		  // read 10 digit code
	  if( Serial.available() > 0) {
	    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
digitalWrite(rfidPin, HIGH); //Turns off RFID reader, THIS IS IMPORTANT so it doesn't double read the card
	  }
	}

	if(bytesread >= 10) {		  // if 10 digit read is complete
 
	 if(strcmp(code, tag) == 0) {
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print(" Access Granted");
 lcd.setCursor(0, 1);
 lcd.println(code);
 delay (1500);
 lcd.setCursor(0, 1);
 lcd.print("Jonnyblanch  ");
         digitalWrite(ledPin,HIGH);
	   Serial.print("Tag matches: ");
	   Serial.println(code);
           digitalWrite(ledPin,HIGH);
           digitalWrite(rfidPin, HIGH);
            delay(2000);	     // wait for a second or two
           return;                   //Go to the top, skip the bottom
         }
         if(strcmp(code, tag2) == 0) {
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print(" Access Granted");
 lcd.setCursor(0, 1);
 lcd.println(code);
 delay (1500);
 lcd.setCursor(0, 1);
 lcd.print("Hector Lopez");
         digitalWrite(ledPin,HIGH);
	   Serial.print("Tag matches: ");
	   Serial.println(code);
           digitalWrite(ledPin,HIGH);
           digitalWrite(rfidPin, HIGH);
            delay(2000);	     // wait for a second
           return;
	   
	 }
	 else {
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Access Denied");
 lcd.setCursor(0, 1);
 lcd.println(code);
	   Serial.print(code);
	   Serial.println(" does not match");
           digitalWrite(rfidPin, HIGH);
           
	 }


	}
	bytesread = 0;
	     delay(2000);	     // wait for a second
        digitalWrite(ledPin,LOW);    
    }
  }
}