Hit Read More to continue on and see the code.
//RFID tag verificaton with custom tag output
//Based off of Arduino Playground sketch
//Modified by Jair2k4
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 6
#define ledPin 13
#define CODE_COUNT 2
#define MIN_ROTATION 150
#define MAX_ROTATION 30
// set up a soft serial port
SoftwareSerial mySerial(rxPin, txPin);
int val = 0;
char code[10];
int bytesread = 0;
char *goodCode = "INSERT TAG HERE"; //The value of your RFID tag
#include <Servo.h>
Servo servo;
void setup() {
// define pin modes for tx, rx, led pins:
pinMode(rxPin, INPUT); // Set rxPin as INPUT to accept SOUT from RFID pin
pinMode(txPin, OUTPUT); // Set txPin as OUTPUT to connect it to the RFID /ENABLE pin
pinMode(ledPin, OUTPUT); // Let the user know whats up
// set the data rate for the serial ports
mySerial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
Serial.begin(9600); // Serial feedback for debugging in Wiring
servo.attach(3);
// say something
Serial.println();
}
void loop() {
digitalWrite(txPin, LOW); // Activate the RFID reader
digitalWrite(ledPin, LOW); // Turn off debug LED
if((val = mySerial.read()) == 10) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
val = mySerial.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
}
if(bytesread == 10) { // If 10 digit read is complete
digitalWrite(txPin, HIGH); // deactivate RFID reader
digitalWrite(ledPin, HIGH); // activate LED to show an RFID card was read
//Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(); // print the TAG code
boolean success = true;
for(int i=0;i<10;i++) {
if(goodCode[i] != code[i]) {
success = false;
digitalWrite(ledPin, HIGH); // activate LED to show error
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
break;
}
}
if(success){
digitalWrite(ledPin, HIGH);
Serial.print("PASSWORD"); //Print desired password
servo.write(MAX_ROTATION);
delay(1000);
}
else {
}
}
bytesread = 0;
delay(500);
servo.write(MIN_ROTATION);
}
}
No comments:
Post a Comment