My classmates and I (2 ChEn, 2 MeEn) have started a very ambitious project way outside of our comfort zone. Unfortunately we are not the greatest programmers in the world. We are trying to get a PRFID (28140)hooked to a Adriano UNO to read one RFID key tag continuously, when the key tag is removed a alarm goes off and a LED blinks. The alarm and LED are then turned off by a separate key. We have gotten the program to turn on the alarm/LED when one key is register. Most of our code is just pieced together from code we have found online. Any help would be appreciated. Again WE ARE NOT PROGRAMERS please give us explanations in simple terms.
Most of our code is just pieced together from code we have found online
What code?
Sorry here's what weve got
#include <SoftwareSerial.h>
//Parallax RFID Reader
#define RFIDEnablePin 2 //Pin that enables reading. Set as OUTPUT and LOW to read an RFID tag
#define RFIDSerialRate 2400 //Parallax RFID Reader Serial Port Speed
//Using SoftwareSerial Library to locate the serial pins off the default set
//This allows the Arduino to be updated via USB with no conflict
#define RxPin 5 //Pin to read data from Reader
#define TxPin 4 //Pin to write data to the Reader NOTE: The reader doesn't get written to, don't connect this line.
SoftwareSerial RFIDReader(RxPin,TxPin);
String RFIDTAG=""; //Holds the RFID Code read from a tag
String DisplayTAG = ""; //Holds the last displayed RFID Tag
void setup()
{
// RFID reader SOUT pin connected to Serial RX pin at 2400bps
RFIDReader.begin(RFIDSerialRate);
// Set Enable pin as OUTPUT to connect it to the RFID /ENABLE pin
pinMode(RFIDEnablePin,OUTPUT);
pinMode(8, OUTPUT);
// Activate the RFID reader
// Setting the RFIDEnablePin HIGH will deactivate the reader
// which could be usefull if you wanted to save battery life for
// example.
digitalWrite(RFIDEnablePin, LOW);
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Hello world!"); // prints hello with ending line break
}
void loop()
{
if(RFIDReader.available() > 0) // If data available from reader
{
ReadSerial(RFIDTAG); //Read the tag number from the reader. Should return a 10 digit serial number
}
//This only displays a tag once, unless another tag is scanned
if(DisplayTAG!=RFIDTAG)
{
DisplayTAG=RFIDTAG;
Serial.println(RFIDTAG);
digitalWrite(8, HIGH);
delay(2000);
digitalWrite(8, LOW);
}
}
void ReadSerial(String &ReadTagString)
{
int bytesread = 0;
int val = 0;
char code[10];
String TagCode="";
if(RFIDReader.available() > 0) { // If data available from reader
if((val = RFIDReader.read()) == 10) { // Check for header
bytesread = 0;
while(bytesread<10) { // Read 10 digit code
if( RFIDReader.available() > 0) {
val = RFIDReader.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
for(int x=0;x<10;x++) //Copy the Chars to a String
{
TagCode += code[x];
}
ReadTagString = TagCode; //Update the caller
while(RFIDReader.available() > 0) //Burn off any characters still in the buffer
{
RFIDReader.read();
}
}
bytesread = 0;
TagCode="";
}
}
}
Apart from the missing code tags, what's the problem?
As of right now every time a tag is read the LED/Alarm goes off. What we want is for one tag to be read continuously, then when removed the LED/Alarm goes off. The alarm is then disarmed by another key
You need code that behaves like this pseudo code
void loop() {
tagNumber = readTag();
if (tagNumber != correctNumber) {
soundAlarm();
}
}
Your loop() function does not seem to have any code to sound the alarm.
...R