user26738: This is a simple Arduino program which reads RFID tag and sends the data over a network (lora). 
The program works fine in as i run it, the arduino reads RFID and sends it over the network (lora)
but 
after a few hours it stops responding it neither reads nor sends the data over network (lora network).
I am very new to arduino and have no idea what causes the box to stop responding, kindly help. 
When i restart the boxes or upload the code to it again, it starts behaving normally for a few hours and then goes back to not responding. 
    /*
   Typical pin layout used:
   -----------------------------------------------------------------------------------------
               MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
               Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
   Signal      Pin          Pin           Pin       Pin        Pin              Pin
   -----------------------------------------------------------------------------------------
   RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
   SPI SS      SDA(SS)      10            53        D10        10               10
   SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
   SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
   SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
   Red LED                  A0
   Green LED                A2
   Blue LED                 A3
*/
/***********************************************************************************************/
//#include <SPI.h>
#include <MFRC522.h>
//#include <HID.h>

// Cooking API libraries
//#include <arduinoUtils.h>
//#include <arduinoUART.h>
//#include <arduinoMultiprotocol.h>
#include <arduinoLoRaWAN.h>

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          10         // Configurable, see typical pin layout above
#define MAX             10         // Maximum Buffer size
#undef Debugg
/******** RFID Reader initialization**********************************************/
MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance
//char rfid_old[MAX];
byte *buffer;

/******************************LoRa Initialization********************************/
// Pin definition for LoRaWAN module error LED:
const int error_led =  7;
//////////////////////////////////////////////
uint8_t socket = SOCKET0;
//////////////////////////////////////////////

// Device parameters for Back-End registration
////////////////////////////////////////////////////////////
char DEVICE_EUI[] = "0000000097E471E1"; // 0000000097E471E1 / 00000000518AD184
char DEVICE_ADDR[] = "97E471E1"; // 97E471E1 / 518AD184
char NWK_SESSION_KEY[] = "00EBB4C1FCDFF52878B1725CBDFF0BA1"; // Configured for TTN
char APP_SESSION_KEY[] = "4EDC3AB4F79C565685109ECD4AF4604C"; // Configured for TTN
char APP_KEY[] = "70B3D57ED0000300"; //APP_EUI
////////////////////////////////////////////////////////////
// Define port to use in Back-End: from 1 to 223
uint8_t PORT = 1;

// variable
uint8_t error;
uint32_t cFreq[] = { 867100000, 867300000, 867500000, 867700000, 867900000 };
char rfid_arr[MAX];
char stampleErrorChar[] = "4AD6A6A65784AEBA2B"; // this data is sent from the WService When Stample Error-> Error
/* *******************************START Initialize Indication LEDs******************************* */
int greenPin = 6;
int redPin = 8;

void setup() 
{
  Serial.begin(57600);
  //LoRaWAN example - Send Unconfirmed packets (no ACK)
  pinMode(error_led, OUTPUT);
  digitalWrite(error_led, LOW);

  LoRaSetup();
  RfidSetup();
}

//-----------------------------------------------------------------------------
// Name.: RfidSetup
// Descr: 
//
// In...:
// Out..:
// Ret..:
//-----------------------------------------------------------------------------
void RfidSetup()
{
  SPI.begin();                        // Init SPI bus
  mfrc522.PCD_Init();                 // Init MFRC522
  mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
}
void LoRaSetup()
{
  LoRaWAN.ON(socket);
  LoRaWAN.factoryReset();

  // Channel parameters
  for (uint8_t i = 3; i < 8; i++) {
    LoRaWAN.setChannelStatus(i, (char*)"on");
    LoRaWAN.setChannelFreq(i, cFreq[i - 3]);
  }
  for (uint8_t i = 0; i < 3; i++) {
    LoRaWAN.setChannelDutyCycle(i, 302);
  }

  for (uint8_t i = 3; i < 8; i++) {
    LoRaWAN.setChannelDutyCycle(i, 99);
  }

  LoRaWAN.setPower(5); // [N/A, 14, 11, 8, 5, 2] dBm
  LoRaWAN.setADR((char*)"off"); // Adaptive data rate
  LoRaWAN.setDataRate(5); // [250, 440, 980, 1760, 3125, 5470, 11000];
  LoRaWAN.setDeviceEUI(DEVICE_EUI);
  //showErrorResult((char*)"2. Set Device EUI ", LoRaWAN.getDeviceEUI());
  LoRaWAN.setAppEUI(APP_KEY);
  //showErrorResult((char*)"3. Set APP EUI ", LoRaWAN.getAppEUI());
  LoRaWAN.setDeviceAddr(DEVICE_ADDR);

  LoRaWAN.setNwkSessionKey(NWK_SESSION_KEY);

  LoRaWAN.setAppSessionKey(APP_SESSION_KEY);
  //showErrorResult((char*)"6. Set App Session Key ",error);
  LoRaWAN.setRetries(3);
  LoRaWAN.saveConfig();
  LoRaWAN.joinABP();
}


void loop() 
{
  // Look for new cards
  if (! mfrc522.PICC_IsNewCardPresent()) {    
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }
  else
  {
     error = LoRaWAN.joinABP();
     if (error == 0) 
     {
       char* UId = GetUid(mfrc522);    
       if(UId != NULL)
       {
          BlinkGreen(500);
          delay(100);
          // Send it!
          error = LoRaWAN.sendUnconfirmed(PORT, UId);
          Serial.println(error);
          delay(100);
          if(error == 0)
          {
             Serial.println(LoRaWAN._dataReceived);
             BlinkGreen(1000);
          }
          else
          {
             BlinkRed(1000);
          }
        }
        delay(2000);
     }   
  }
}

char* GetUid(MFRC522 mfrc522)
{
    // Optional: Dump data about the cards
    //mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
    buffer = mfrc522.uid.uidByte;

    for (int i = 0; i < mfrc522.uid.size; i++)
    {
      sprintf(&rfid_arr[i * 2], "%02X", mfrc522.uid.uidByte[i]);
    }
    mfrc522.PICC_HaltA(); //command the card into sleep mode                                                                          
    return rfid_arr;
}

void BlinkGreen(int delayTime)
{
  digitalWrite(greenPin, HIGH);
  delay(delayTime);
  digitalWrite(greenPin, LOW);
}

void BlinkRed(int delayTime)
{
  digitalWrite(redPin, HIGH);
  delay(delayTime);
  digitalWrite(redPin, LOW);
}
void showErrorResult(char* errorMessage, uint8_t error)
{
  if(error == 0)
  {
    Serial.print(errorMessage);
    Serial.println("OK!");
  }
  else
  {
    Serial.print(errorMessage);
    Serial.print(" Error: ");
    Serial.println(error);  
  }
}


user26738: @Matt,
thanks guys. But if rfid_arr size was an issue, wouldn't the box be giving problem the first time we use it? because it works for few hours before it goes into not responding state. The rfid tag data looks like below 
AEA00622 
DE1CD403 

26738: <p>This is a simple Arduino program which reads RFID tag and sends the data over a network (lora). </p>

<p>The program works fine in as i run it, the arduino reads RFID and sends it over the network (lora)</p>

<p>but </p>

<p>after a few hours it stops responding it neither reads nor sends the data over network (lora network).</p>

<p>I am very new to arduino and have no idea what causes the box to stop responding, kindly help. </p>

<p>When i restart the boxes or upload the code to it again, it starts behaving normally for a few hours and then goes back to not responding. </p>

<pre><code>    /*
   Typical pin layout used:
   -----------------------------------------------------------------------------------------
               MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
               Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
   Signal      Pin          Pin           Pin       Pin        Pin              Pin
   -----------------------------------------------------------------------------------------
   RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
   SPI SS      SDA(SS)      10            53        D10        10               10
   SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
   SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
   SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
   Red LED                  A0
   Green LED                A2
   Blue LED                 A3
*/
/***********************************************************************************************/
//#include &lt;SPI.h&gt;
#include &lt;MFRC522.h&gt;
//#include &lt;HID.h&gt;

// Cooking API libraries
//#include &lt;arduinoUtils.h&gt;
//#include &lt;arduinoUART.h&gt;
//#include &lt;arduinoMultiprotocol.h&gt;
#include &lt;arduinoLoRaWAN.h&gt;

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          10         // Configurable, see typical pin layout above
#define MAX             10         // Maximum Buffer size
#undef Debugg
/******** RFID Reader initialization**********************************************/
MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance
//char rfid_old[MAX];
byte *buffer;

/******************************LoRa Initialization********************************/
// Pin definition for LoRaWAN module error LED:
const int error_led =  7;
//////////////////////////////////////////////
uint8_t socket = SOCKET0;
//////////////////////////////////////////////

// Device parameters for Back-End registration
////////////////////////////////////////////////////////////
char DEVICE_EUI[] = "0000000097E471E1"; // 0000000097E471E1 / 00000000518AD184
char DEVICE_ADDR[] = "97E471E1"; // 97E471E1 / 518AD184
char NWK_SESSION_KEY[] = "00EBB4C1FCDFF52878B1725CBDFF0BA1"; // Configured for TTN
char APP_SESSION_KEY[] = "4EDC3AB4F79C565685109ECD4AF4604C"; // Configured for TTN
char APP_KEY[] = "70B3D57ED0000300"; //APP_EUI
////////////////////////////////////////////////////////////
// Define port to use in Back-End: from 1 to 223
uint8_t PORT = 1;

// variable
uint8_t error;
uint32_t cFreq[] = { 867100000, 867300000, 867500000, 867700000, 867900000 };
char rfid_arr[MAX];
char stampleErrorChar[] = "4AD6A6A65784AEBA2B"; // this data is sent from the WService When Stample Error-&gt; Error
/* *******************************START Initialize Indication LEDs******************************* */
int greenPin = 6;
int redPin = 8;

void setup() 
{
  Serial.begin(57600);
  //LoRaWAN example - Send Unconfirmed packets (no ACK)
  pinMode(error_led, OUTPUT);
  digitalWrite(error_led, LOW);

  LoRaSetup();
  RfidSetup();
}

//-----------------------------------------------------------------------------
// Name.: RfidSetup
// Descr: 
//
// In...:
// Out..:
// Ret..:
//-----------------------------------------------------------------------------
void RfidSetup()
{
  SPI.begin();                        // Init SPI bus
  mfrc522.PCD_Init();                 // Init MFRC522
  mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
}
void LoRaSetup()
{
  LoRaWAN.ON(socket);
  LoRaWAN.factoryReset();

  // Channel parameters
  for (uint8_t i = 3; i &lt; 8; i++) {
    LoRaWAN.setChannelStatus(i, (char*)"on");
    LoRaWAN.setChannelFreq(i, cFreq[i - 3]);
  }
  for (uint8_t i = 0; i &lt; 3; i++) {
    LoRaWAN.setChannelDutyCycle(i, 302);
  }

  for (uint8_t i = 3; i &lt; 8; i++) {
    LoRaWAN.setChannelDutyCycle(i, 99);
  }

  LoRaWAN.setPower(5); // [N/A, 14, 11, 8, 5, 2] dBm
  LoRaWAN.setADR((char*)"off"); // Adaptive data rate
  LoRaWAN.setDataRate(5); // [250, 440, 980, 1760, 3125, 5470, 11000];
  LoRaWAN.setDeviceEUI(DEVICE_EUI);
  //showErrorResult((char*)"2. Set Device EUI ", LoRaWAN.getDeviceEUI());
  LoRaWAN.setAppEUI(APP_KEY);
  //showErrorResult((char*)"3. Set APP EUI ", LoRaWAN.getAppEUI());
  LoRaWAN.setDeviceAddr(DEVICE_ADDR);

  LoRaWAN.setNwkSessionKey(NWK_SESSION_KEY);

  LoRaWAN.setAppSessionKey(APP_SESSION_KEY);
  //showErrorResult((char*)"6. Set App Session Key ",error);
  LoRaWAN.setRetries(3);
  LoRaWAN.saveConfig();
  LoRaWAN.joinABP();
}


void loop() 
{
  // Look for new cards
  if (! mfrc522.PICC_IsNewCardPresent()) {    
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }
  else
  {
     error = LoRaWAN.joinABP();
     if (error == 0) 
     {
       char* UId = GetUid(mfrc522);    
       if(UId != NULL)
       {
          BlinkGreen(500);
          delay(100);
          // Send it!
          error = LoRaWAN.sendUnconfirmed(PORT, UId);
          Serial.println(error);
          delay(100);
          if(error == 0)
          {
             Serial.println(LoRaWAN._dataReceived);
             BlinkGreen(1000);
          }
          else
          {
             BlinkRed(1000);
          }
        }
        delay(2000);
     }   
  }
}

char* GetUid(MFRC522 mfrc522)
{
    // Optional: Dump data about the cards
    //mfrc522.PICC_DumpToSerial(&amp;(mfrc522.uid));
    buffer = mfrc522.uid.uidByte;

    for (int i = 0; i &lt; mfrc522.uid.size; i++)
    {
      sprintf(&amp;rfid_arr[i * 2], "%02X", mfrc522.uid.uidByte[i]);
    }
    mfrc522.PICC_HaltA(); //command the card into sleep mode                                                                          
    return rfid_arr;
}

void BlinkGreen(int delayTime)
{
  digitalWrite(greenPin, HIGH);
  delay(delayTime);
  digitalWrite(greenPin, LOW);
}

void BlinkRed(int delayTime)
{
  digitalWrite(redPin, HIGH);
  delay(delayTime);
  digitalWrite(redPin, LOW);
}
void showErrorResult(char* errorMessage, uint8_t error)
{
  if(error == 0)
  {
    Serial.print(errorMessage);
    Serial.println("OK!");
  }
  else
  {
    Serial.print(errorMessage);
    Serial.print(" Error: ");
    Serial.println(error);  
  }
}
</code></pre>
 26738: <p>@Matt,</p>

<p>thanks guys. But if rfid_arr size was an issue, wouldn't the box be giving problem the first time we use it? because it works for few hours before it goes into not responding state. The rfid tag data looks like below 
AEA00622 
DE1CD403 </p>
