the code make my Arduino reset every loop???

I don’t understand why -
I have ask here once, and someone told me that I need to clean the memory - so I think I did it, but if someone can take a look and see what I did wrong -

#include <SoftwareSerial.h>
#include <stdio.h>
SoftwareSerial mySerial(10, 11); // RX, TX
int ok_csq_pin=7;
int send_msg_pin=6;
int redled=13;
int greenled=12;
int time=1;
int low=0;
int high=0;
long startTime;                   // to store the start of the timer
long interval = 180000;           // defalt interval of sending msg in milliseconds (~~  3 min)
void setup()  
  Serial.begin(19200); // Open serial communications and wait for port to open:
  Serial.println("Ready to work!");
  startTime = millis(); //set startTime
  Serial.println("Modem connection is on!");

void loop ()
  if(millis() - startTime < interval) 
  { //What to do if didn't pass 10 min

    if (digitalRead(send_msg_pin)==HIGH)
      startTime = millis();

  { //3 min is done - need to send auto msg 

    Serial.println("Sending automatic msg - 3 min is pass");
    Serial.print("OLD Delay time is - ");
    sbdrt(); // only see msg 

    Serial.print("The new delay time is - ");

  }//end of auto sending msg

}//end of loop

void sbdrt()
  Serial.println("sending AT+sbdrt");
  int s=mySerial.available();
  char rt_full[s];
  if  (mySerial.available()>s-2)
  {//start of  answer

    for (int sbdrt_num=0;sbdrt_num<s;sbdrt_num++)
    {//start reading 
      Serial.print("    ");

    }//end of reading
    Serial.println("this is the full response - ");

    char * pch_sbrt;
    int i=0;
    char *david_sbrt[2];
    int answer_sbrt[2];
    pch_sbrt = strtok( rt_full, ":");
    while (pch_sbrt !=NULL)  

    }// end of cutting the answer

    for (int y=0;y<2;y++)

    Serial.println("this is the final answer");
    for (int v=0;v<2;v++)
    {//printing the int value of my msg 

      Serial.print("  -  " );


    Serial.print("This is the msg   -  " );
    Serial.print("This is the delay time in minuts - ");
    long new_delay=60000*(answer_sbrt[1]);
    Serial.print("The new dealy time in miilsec is -");
    if (new_delay!=0)
      Serial.println("new delay  ");
    if (answer_sbrt[0]==6)
      Serial.println("the msg recive - green ");
    else if (answer_sbrt[0]==8)
      Serial.println("the msg recive - red ");

    for (int temp=0;temp<s;temp++)//cleaning the memory
     for (int temp1=0;temp1<2;temp1++)//cleaning the memory
    memset(rt_full,0,s); //clean the memory 
    memset(answer_sbrt,'\n',2); //clean the memory 

    Serial.println("*****end of sbdrt******");

  }//end of reading 

}//end of sbdrt

and this is the output

Ready to work!
Modem connection is on!
Sending automatic msg - 10 min is pass
OLD Delay time is - 30000
sending AT+sbdrt
0 A
1 T
2 +
3 s
4 b
5 d
6 r
7 t




12 +
13 S
14 B
15 D
16 R
17 T
18 :


21 6
22 ,
23 2


26 O
27 K


this is the full response -


this is the final answer
0 - 6
1 - 2
This is the msg - 6
This is the delay time in minuts - 2

The new dealy time in miilsec is -120000

new delay
the msg recive - green
***Ready to work!

Thanks ,

 for (int temp=0;temp<s;temp++)//cleaning the memory
     for (int temp1=0;temp1<2;temp1++)//cleaning the memory
    memset(rt_full,0,s); //clean the memory 
    memset(answer_sbrt,'\n',2); //clean the memory

If you managed your strings properly, you wouldn’t need this junk.
A string can be terminated as you build it, and reset with a single write of zero to its first element.

o.k. so what I need to do? remove this part? - how do I know I mange my string correctly?

thanks .

int s=mySerial.available();
  char rt_full[s];

Not like that, that’s for certain.
An ‘s’ element array does not have a subscript ‘s’

I'm sorry I don't understand what does it mean can you explain in simple English - what do you mean ,and what I need to understand

Thank .

OK, imagine I declare an array:

int myArray [5];

The array has 'n' = 5 elements, and the elements are numbered 0, 1, 2, 3 and 4. But not 5.

So, if I write myArray [5] = 42;, I would be doing something very silly.

of course ,but I don't do this (am I???) where I put data into place that isn't "belong to me"?

,but I don't do this

Of course you do - see reply #3.

didn't see it, and I have look and look so many times..

Thanks you for now ! I will put this part of the code in my all program and see how it's work. (and also look for mistakes like this again )


  • now you have 20000 messages because of me :-)

I only picked-out the most obvious one to me - there may be others still in there.

(Yup, that’s 20k posts, but I bet if I found and deleted all my redirection posts for misplaced threads, “please use code tags”, “don’t cross-post” etc, I’d have about 10k :frowning: )

Congrats on 20000 posts, AWOL!