Hi!
I'm working on an electromagnetic door lock project. I have an Arduino Uno hooked up to an RC522 RFID module and an SRD-05VDC-SL-C 5V relay, which controls a 12V electromagnetic lock. As of now, my power source is a 4.8V battery, but it doesn't seem to be affecting the lock's performance.
My problem is that as soon as I scan the RFID tag that is authorized and the relay gets engaged and the electromagnetic lock is "unlocked", I can no longer scan the tag again. The RFID reader stops reading and I have to reset the Arduino for it to work again. I've tested my circuit extensively and found that I can scan, add and remove as many tags as I want before unlocking the lock, but as soon as that happens, the reader stops working. I am not sure if this is a software problem or a hardware problem. My design is based on this project, but I have modified many things.
Here is the void loop() of my code, as that is the part that handles the reading and unlocking. Please let me know if the full code is required (it is quite long).
void loop () {
do {
successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0
// When device is in use if wipe button pressed for 10 seconds initialize Master Card wiping
if (digitalRead(wipeB) == LOW) { // Check if button is pressed
// Visualize normal operation is iterrupted by pressing wipe button Red is like more Warning to user
digitalWrite(redLed, LED_ON); // Make sure led is off
digitalWrite(greenLed, LED_OFF); // Make sure led is off
digitalWrite(blueLed, LED_OFF); // Make sure led is off
// Give some feedback
Serial.println(F("Wipe Button Pressed"));
Serial.println(F("Master Card will be Erased! in 10 seconds"));
bool buttonState = monitorWipeButton(10000); // Give user enough time to cancel operation
if (buttonState == true && digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM
EEPROM.write(1, 0); // Reset Magic Number.
Serial.println(F("Master Card Erased from device"));
Serial.println(F("Please reset to re-program Master Card"));
while (1);
}
Serial.println(F("Master Card Erase Cancelled"));
}
if (programMode) {
cycleLeds(); // Program Mode cycles through Red Green Blue 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 are not getting a successful read
if (programMode) {
if ( isMaster(readCard) ) { //When in program mode check First If master card scanned again to exit program mode
Serial.println(F("Master Card Scanned"));
Serial.println(F("Exiting Program Mode"));
Serial.println(F("-----------------------------"));
programMode = false;
return;
}
else {
if ( findID(readCard) ) { // If scanned card is known delete it
Serial.println(F("I know this PICC, removing..."));
deleteID(readCard);
Serial.println("-----------------------------");
Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM"));
}
else {
Serial.println(F("I do not know this PICC, adding..."));
writeID(readCard);
Serial.println(F("-----------------------------"));
Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM"));
}
}
}
else {
if ( isMaster(readCard)) { // If scanned card's ID matches Master Card's ID - enter program mode
programMode = true;
Serial.println(F("Hello Master - Entered Program Mode"));
uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that
Serial.print(F("I have ")); // stores the number of ID's in EEPROM
Serial.print(count);
Serial.print(F(" record(s) on EEPROM"));
Serial.println("");
Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM"));
Serial.println(F("Scan Master Card again to Exit Program Mode"));
Serial.println(F("-----------------------------"));
}
else {
if ( findID(readCard) ) { // If not, see if the card is in the EEPROM
Serial.println(F("Welcome, You shall pass"));
granted(3000); // Open the door lock for 300 ms
}
else { // If not, show that the ID was not valid
Serial.println(F("You shall not pass"));
denied();
}
}
}
}
Thanks in advance for any help!
