Hi.
I have one question.
How do I get the relay to stay on top until no-permitted the ID-card will be showing.
///////////////////////////////////////// Main Loop ///////////////////////////////////
void loop () {
do {
successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0
if (programMode) {
cycleLeds(); // Program Mode cycles through RGB waiting to read a new card
}
else {
normalModeOn(); // Normal mode, blue Power LED is on, all others are off
}
}
while (!successRead); //the program will not go further while you not get a successful read
if (programMode) {
if ( isMaster(readCard) ) { //If master card scanned again exit program mode
Serial.println("This is Master Card");
Serial.println("Exiting Program Mode");
Serial.println("-----------------------------");
programMode = false;
return;
}
else {
if ( findID(readCard) ) { //If scanned card is known delete it
Serial.println("I know this PICC, so removing");
deleteID(readCard);
Serial.println("-----------------------------");
}
else { // If scanned card is not known add it
Serial.println("I do not know this PICC, adding...");
writeID(readCard);
Serial.println("-----------------------------");
}
}
}
else {
if ( isMaster(readCard) ) { // If scanned card's ID matches Master Card's ID enter program mode
programMode = true;
Serial.println("Hello Master - Entered Program Mode");
int count = EEPROM.read(0); // Read the first Byte of EEPROM that
Serial.print("I have "); // stores the number of ID's in EEPROM
Serial.print(count);
Serial.print(" record(s) on EEPROM");
Serial.println("");
Serial.println("Scan a PICC to ADD or REMOVE");
Serial.println("-----------------------------");
}
else {
if ( findID(readCard) ) { // If not, see if the card is in the EEPROM
Serial.println("Welcome: Door Oppend");
///////////////////////////////////////////////////////////////////////////////////////////
//
// I want to recieve an SMS tellin me that the door is opened
//
///////////////////////////////////////////////////////////////////////////////////////////////
//
// I tried putting this here after innitializing the GSM module but it did not work
//
//
//
//
//
//
///////////////////////////////////////////////////////////////////////////////////////////
openDoor(300); // Open the door lock for 300 ms
}
else { // If not, show that the ID was not valid
Serial.println("Error: Unknown Card");
delay(1200);
//failed();
}
}
}
}
///////////////////////////////////////// Get PICC's UID ///////////////////////////////////
int getID() {
// Getting ready for Reading PICCs
if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
return 0;
}
if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue
return 0;
}
// There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC
// I think we should assume every PICC as they have 4 byte UID
// Until we support 7 byte PICCs
Serial.println("Scanned PICC's UID:");
for (int i = 0; i < 4; i++) { //
readCard[i] = mfrc522.uid.uidByte[i];
Serial.print(readCard[i], HEX);
}
Serial.println("");
mfrc522.PICC_HaltA(); // Stop reading
return 1;
}
////////////////////// Check readCard IF is masterCard ///////////////////////////////////
// Check to see if the ID passed is the master programing card
boolean isMaster( byte test[] ) {
if ( checkTwo( test, masterCard ) )
return true;
else
return false;
}
///////////////////////////////////////// Unlock Door ///////////////////////////////////
void openDoor( int setDelay ) {
digitalWrite(blueLed, LED_OFF); // Turn off blue LED
digitalWrite(redLed, LED_OFF); // Turn off red LED
digitalWrite(greenLed, LED_ON); // Turn on green LED
digitalWrite(relay, LOW); // Unlock door!
delay(setDelay); // Hold door lock open for given seconds
digitalWrite(relay, LOW); // Relock door
delay(1200); // Hold green LED on for 2 more seconds
}
///////////////////////////////////////// Failed Access ///////////////////////////////////
void failed() {
digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
digitalWrite(redLed, LED_ON); // Turn on red LED
delay(1200);
}