Hi guys, a made a project to open and close a door with relays when reading a rfid card with bits and pieces of some codes I found online, initially it works fine, but after some time it looks like the arduino freezes, can someone tell me why?
I read something online about using "string" in the code that might be causing that, but i don't understand why, and i'm quite new at programing
here's the code:
/*
*
*
*/
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
#define RELAY1 6
#define RELAY2 5
#define LED1 8
void setup()
{
// Initialise the Arduino data pins for OUTPUT
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(LED1, OUTPUT);
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();
}
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();
(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
// read the led output pin:
digitalRead(LED1);
if ((digitalRead(LED1) == LOW)){
{
Serial.println("Open");
Serial.println();
digitalWrite(RELAY1,HIGH);
delay(250);
digitalWrite(RELAY1,LOW);
digitalWrite(LED1,HIGH);
delay(1500);
goto depois;
}
}
if ((digitalRead(LED1) == HIGH)){
{
Serial.println("Close");
Serial.println();
digitalWrite(RELAY2,HIGH);
delay(250);
digitalWrite(RELAY2,LOW);
digitalWrite(LED1,LOW);
delay(1500);
}
}
depois:
delay(10);
}