My arduino uno blocked after 5 or 6 execution of my program

hello freinds, i still executing my program in my arduino board for months.
from two months my card arduino uno blokced after some running of my program,
i changed my board to a new one but the problem still.
the same i checked my connections many time and many solutions from forums but the problem still existing.

What code?

#include <SoftwareSerial.h>

String stnbr;
long inputsms;

String num_on;
String num_off;
String num_cancel;

String smsRDM="Redemarrage de Arduino";

String smstton="ARROSAGE Automatique ON Pour: ";
String smsttoff="ARROSAGE OFF";
String smsscnd=" Secondes.";
String smssmnt=" Minutes.";


String sami="009999990";

int h_k=0;
int m_k=0;
int s_k=0;
unsigned long period= 43200000;
unsigned long time_now= 0;

SoftwareSerial gsmSerial(7, 8);

int c=0;
int cc=30;

char incomingByte="";
String inputString="";

void(* resetFunc) (void) = 0;

void setup()
{ 
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
 
  pinMode(6, LOW);
  pinMode(9, LOW);    
  pinMode(10, LOW);
  pinMode(11, LOW);
  pinMode(12, LOW);
  pinMode(13, LOW);

  Serial.begin(9600);
  gsmSerial.begin(9600);

  while (!gsmSerial.available()) {
    gsmSerial.println("AT");
    Serial.println("Connecting...");
  }
 Serial.println("Connected!!!");
 
  gsmSerial.println("AT+CMGF=1");
  delay(500);
  gsmSerial.println("AT+CNMI=1,2,0,0,0");
  delay(500);
  gsmSerial.println("AT+CMGL=\"REC UNREAD\"");
  delay (500);
  
  Message(smsRDM,sami);

}

void loop()
{
  time_now=millis();
  if (time_now>=period) {
     Serial.println("Redemarrage!!!");
    resetFunc();
    }
     
  if (gsmSerial.available()) {
    inputString = "";
    delay(1000);
    while (gsmSerial.available()) {
      incomingByte = gsmSerial.read();
      inputString += incomingByte;
    }
     delay(100);
    //inputString.replace("\n","");
    Serial.print("input : ");
    Serial.print(inputString);
    Serial.println("   end");

    inputString.toUpperCase();
    Serial.println("input up : " + inputString);
//////////

  if (inputString.indexOf("ON") > 0) {
  int p= inputString.indexOf("N");
   for(byte i=p+1;i<inputString.length();i++)
   {
      if(isDigit(inputString.charAt(i))) ;
      stnbr+=inputString.charAt(i);
   }
   inputsms = stnbr.toInt();    
//----------------------------------//
int t= inputString.indexOf("T");
   for(byte j=t+4;j<t+16;j++)
   {
      if(isDigit(inputString.charAt(j))) ;
      num_on+=inputString.charAt(j);
   }  

  h_k = (inputsms/3600); 
  m_k = (inputsms -(3600*h_k))/60;
  s_k = (inputsms -(3600*h_k)-(m_k*60));
   
   Message(smstton+=String(m_k)+=smssmnt+=String(s_k) +=smsscnd,num_on);
   
   delay(500);
   onkey(inputsms);
   delay(500);
   Message(smsttoff,num_on);
   delay(2500);
   resetFunc();
    }
   
  if (inputString.indexOf("OFF") > 0) {
   fnc_off();
   //----------------------------------//
int v= inputString.indexOf("T");
   for(byte l=v+4;l<v+16;l++)
   {
      if(isDigit(inputString.charAt(l))) ;
      num_off+=inputString.charAt(l);
   }
    
//-----------------------------------------//
   Message(smsttoff,num_off);
   delay(1500);
   gsmSerial.println("AT+CMGDA=\"DEL ALL\"");
  delay(500);
   resetFunc();
    }
 
    if (inputString.indexOf("DEL") > -1) {
      gsmSerial.println("AT+CMGDA=\"DEL ALL\"");
      delay(1000);
    }
  }
}

//Method for serial communications
void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    gsmSerial.write(Serial.read());
  }
  while(gsmSerial.available()) 
  {
    Serial.write(gsmSerial.read());
  }
}

void Message(String sms,String numero)
{
  gsmSerial.println("AT");
  updateSerial();
  gsmSerial.println("AT+CMGF=1");// Change to text mode
  updateSerial();

 gsmSerial.write("AT+CMGS=\"");
 gsmSerial.print(numero);
 gsmSerial.write("\"\r");
 
  updateSerial();
  gsmSerial.print(sms); //Your message
  updateSerial();
  gsmSerial.write(26);
  }

////////////////////////////////

void onkey(int k)
{    c=k;
  while(c>0)
  {  c--;
   getsms();
 pinMode(6, HIGH);
 delay(1000);
 }
 
pinMode(6, LOW);
delay(1500); 
//////////////////////////

  c=k;
  while(c>0)
  {  c--;
   getsms();
 pinMode(9, HIGH);
 delay(1000);
 }

pinMode(9, LOW);
delay(1500);
//////////////////////////

   c=k;
  while(c>0)
  {  c--;
   getsms();
 pinMode(10, HIGH);
 delay(1000);
 }

pinMode(10, LOW);
delay(1500); 
//////////////////////////
   
   c=k;
  while(c>0)
  {  c--;
   getsms();
 pinMode(11, HIGH);
 delay(1000);
 }
  
pinMode(11, LOW);
delay(1500); 
//////////////////////////
   c=k;
  while(c>0)
  {  c--;
   getsms();
 pinMode(12, HIGH);
 delay(1000);
 }
 
pinMode(12, LOW); 
delay(1500);
//////////////////////////
 c=k;
  while(c>0)
  {  c--;
   getsms();
 pinMode(13, HIGH);
 delay(1000);
 }
 
pinMode(13, LOW); 
//////////////////////////

  delay(2000);
 
//////////////////////////
   
 }
 
void fnc_off()
{ 
  pinMode(6, LOW);
  pinMode(9, LOW);
  pinMode(10, LOW);
  pinMode(11, LOW);
  pinMode(12, LOW);
  pinMode(13, LOW);
 }   

 void getsms()
 {
  if (gsmSerial.available()) {
    inputString = "";
    delay(1000);
    while (gsmSerial.available()) {
      incomingByte = gsmSerial.read();
      inputString += incomingByte;
    }
 
    delay(100);
    //inputString.replace("\n","");
    Serial.print("input : ");
    Serial.print(inputString);
    Serial.println("   end");

    inputString.toUpperCase();
    Serial.println("input up : " + inputString);

 if (inputString.indexOf("OFF") > 0) {
   fnc_off();
   //----------------------------------//
int x= inputString.indexOf("T");
   for(byte q=x+4;q<x+16;q++)
   {
      if(isDigit(inputString.charAt(q))) ;
      num_cancel+=inputString.charAt(q);
   }
 //-----------------------------------------//
   Message(smsttoff,num_cancel);
    delay(1000);
   resetFunc();
    }

    if (inputString.indexOf("DEL") > -1) {
     gsmSerial.println("AT+CMGDA=\"DEL ALL\"");
      delay(1000);
    }
  }
 }
 

What is this supposed to do?

A problem is that the problem is not well defined. Could you restate the problem?

my idea is to activate realys with gsm command by sending sms containig specific words and numbers to ran my board from distant places.

Too far from the question. Are you trying to set the pins to low?
Use digitalWrite()

thank you for replying, but my problem is not about activate or deactivate my relays with my board, because the project is working for months.

am asking about the source of error.
is it in my program or otherthing?

Hello
I´ve made a low level flight above your sketch and I´ve detected 28 calls of the delay() function. Do you aware that each call will bring your sketch to sleep? Is this a design goal for your realtime application?

    Line 62:   delay(500);
	Line 64:   delay(500);
	Line 66:   delay (500);
	Line 82:     delay(1000);
	Line 87:      delay(100);
	Line 119:    delay(500);
	Line 121:    delay(500);
	Line 123:    delay(2500);
	Line 139:    delay(1500);
	Line 141:   delay(500);
	Line 147:       delay(1000);
	Line 155:   delay(500);
	Line 191:  delay(1000);
	Line 195: delay(1500); 
	Line 203:  delay(1000);
	Line 207: delay(1500);
	Line 215:  delay(1000);
	Line 219: delay(1500); 
	Line 227:  delay(1000);
	Line 231: delay(1500); 
	Line 238:  delay(1000);
	Line 242: delay(1500);
	Line 249:  delay(1000);
	Line 255:   delay(2000);
	Line 275:     delay(1000);
	Line 281:     delay(100);
	Line 301:     delay(1000);
	Line 307:       delay(1000);

Have nice day and enjoy coding in C++.

What error?

in my sketch there are some delays for:
-part of communication code with gsm module.
-part of counting time for relay activation for a specific period and i dont like tow do it with millis function.

at all my program is supposed to do his job one time a week and the rest is to beng in standby mode.

the error is my board is blocked and needs to restart manually by shutdowning and reboot after 5 sms received succelly

What does that mean?

not accept message from sms module again and did not response.

i have to reboot it manually after sending 5 or 6 sms received by this board.

but my project is based by activation of my relays sequencelly from distance by sending sms to my board every time.

void loop()
{ 
Serial.println( "tick");

If you add the serial print, when the system is blocked does the printing stop?

How much ram does your program consume?

Are you expecting your program to be quick and responsive?

I added an lcd 162 for my project for showing if there a problem with communication with my arduino uno and the same time writing the same messages sended to serial, whene the blockage ocured i see a trouble in the message writen in the lcd 162.
for the ram the sketch use only 31 per cent of the RAM.

???

Means?

Why does that require a 1000ms delay?

Why does that need a 1 second delay?

Why so many delays?

when the system is blocked the print in lcd will be a random of symbols