Program intermittently freezes after relay is energized

Hello every one. I have a similar project and i found it wise to place my question here.
My project is a door entry system using the rfid 522 module and arduino nano. The project is already complete and the problem i am facing is that the program seems to freeze after some times the relay energized with load (door loock). some times working continious, other times only 1 entry. It seems like random.

I make some research and i add this circuit for the relay:

relay

by using this circuit works a litle better but the problem continious.
This happens only if i have load to the relay (the door lock). with out load works just fine.

the door lock works with 8v to 24v. i ve tried with several voltage from minimum to maximum but nothing change.

the code is the following:

*/

#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 4
#define RST_PIN 5
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
const int buzzerPin = 6;
void setup()
{
pinMode(buzzerPin, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
digitalWrite(2, LOW); // turn the LOCK on (HIGH is the voltage level)
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("Approximate your card to the reader...");
Serial.println();
tone(buzzerPin, 100, 100);
delay(1000);
tone(buzzerPin, 50, 100);

}
void Function1()
{
delay(500);
digitalWrite(2, HIGH); // turn the LOCK on (HIGH is the voltage level)
delay(1000);
digitalWrite(2, LOW); // turn the LOCK on (HIGH is the voltage level)
delay(500);

    }

void loop()
{

// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if ((content.substring(1) == "xx xx xx xx") || (content.substring(1) == "xx xx xx xx")|| (content.substring(1) == "xx xx xx xx")) //change here the UID of the card/cards that you want to give access
{

tone(buzzerPin, 100, 100);
delay(500);

{
Function1();
}

}

else {

tone(buzzerPin, 1000, 15000);       /* 1 minute delay for safety   if  not 
                                                                  the correct card
delay(60000); 

}
}

any suggestion?
thank you very much

Please don't hijack threads @steffch. I have split your post out to its own topic.

Hijacking is against the Arduino forum rules. The reason is that it may sidetrack the discussion, even preventing the creator of the topic from getting the assistance they need.

This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Is that AC or DC? If DC, you need a spike suppression diode in parallel with the lock, cathode (end with stripe or band) toward + volts.
If AC, an R/C snubber, MOV or bidirectional TVS diode.
Like this, substitute lock for "fan or light".
New-Project

Please see the image below to post the full code formatted correctly after you've used Ctrl + T in the IDE to format your code.

Hi, @steffch
Welcome to the forum.

Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.

What model Arduino are you using?

What are you using to power your porject?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.