Arduino Reboots it self when it receives a text message it has to process

Hi.
My arduino resets it self, when it receives a text message it has to process.
I am doing a small temperature control, where i send text messages to get the actual status, to set it to 2 different temperatures and to manually turn it on.
My setup is a arduino UNO + a GPRS Shield V2.0 from SeedStudio.
Here is the code (The language in the replies are in danish, so if you don't understand the text, just ask)
Can you tell me why it is rebooting?
I hope you can help, since I'm loosing my hair over this!

#include <DallasTemperature.h>
#include "SIM900.h"
#include <SoftwareSerial.h>
#include <OneWire.h> 

//If not used, is better to exclude the HTTP library,
//for RAM saving.
//If your sketch reboots itself proprably you have finished,
//your memory available.
//#include "inetGSM.h"

#include "sms.h"
SMSGSM sms;

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.


//Outputs & inputs
int inPutVP = 4;
int rel1 = 5; 
int led1 = 13;
int led2 = 12;
OneWire oneWire(2);
DallasTemperature tempSens(&oneWire);

//Var
int startvarm = 2; //Starter funktionen til Varme. brugt til knap.
int startvarmvand = 3; //Starter funktionen til varmt vand. brugt til knap
int numdata;
boolean started=false;
int position;  //Lagrer beskedens position paa sim.
char phone_number[20]; // telefon Nummer
char sms_text[100]; // Besked indhold
char hentSMS; // Bruges til at hente sms'en ned
boolean nySMS; //Tjekker om der er en ny SMS. Bliver sat til TRUE hvis der er, og naar programmet har koert bliver den sat til False
boolean tempStyring22 = false;
boolean tempStyring15 = false;
boolean OnOff = false;
int tjekVP;
boolean styringOnOff = false;

//Functions
int varme() {
       digitalWrite(rel1, HIGH);
       digitalWrite(led1, HIGH);
       delay(500);
       digitalWrite(rel1, LOW);
       digitalWrite(led1, LOW);
       delay(500);
       styringOnOff = !styringOnOff;
       OnOff = !OnOff;
}
int onOroff() {
  tjekVP = digitalRead(inPutVP);
  if (tjekVP == HIGH) {
     OnOff = !OnOff; 
     delay(1000);
  }
  
}
 
 void powerUpOrDown()
{
  pinMode(9, OUTPUT); 
  digitalWrite(9,LOW);
  delay(1000);
  digitalWrite(9,HIGH);
  delay(2000);
  digitalWrite(9,LOW);
  delay(3000);
}

void setup() 
{
  //Serial connection.
  powerUpOrDown();
  pinMode(rel1, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(startvarm, INPUT);
  pinMode(inPutVP, INPUT);
  pinMode(startvarmvand, INPUT);
  Serial.begin(9600);
  Serial.println("ESTIA SMS Styring.");
  //Start configuration of shield with baudrate.
  //For http uses is raccomanded to use 4800 or slower.
  if (gsm.begin(19200)){
    Serial.println("\nstatus=READY");
    started=true;  
  }
  else Serial.println("\nstatus=IDLE");
  
  if(started){
      Serial.println("\nStartet");
  }
  tempSens.begin();

};

void loop() 
{
  if(started){
    if (OnOff == true){
     digitalWrite(led2, HIGH); 
    }
    else {
     digitalWrite(led2, LOW); 
    }
    
 
    //Read if there are messages on SIM card and print them.
    position=sms.IsSMSPresent(SMS_ALL);
    onOroff();
    if(position >= 1)
    {
      nySMS = true;
      hentSMS = sms.GetSMS(position, phone_number, sms_text, 100);

      if (!strcmp(sms_text, "VP")) {
        varme();
        if (OnOff == true) {
          sms.SendSMS(phone_number, "Varmepumpe Startet");
        }
        else if(OnOff == false) {
          sms.SendSMS(phone_number, "Varmepumpe Slukket"); 
        }
        nySMS = false;
        } 
        
      if(!strcmp(sms_text, "22")) {
          tempStyring22 = !tempStyring22;
          tempStyring15 = false;
          if (tempStyring22 == true) {
            if (OnOff == true) {
           sms.SendSMS(phone_number, "Du har aktiveret 22 graders styring, varmepumpe er on"); 
            }
           else if (OnOff == false) {
           sms.SendSMS(phone_number, "Du har aktiveret 22 graders styring, varmepumpe er off"); 
            }
          }

          else if (tempStyring22 == false) {
           if (OnOff == true) {
           sms.SendSMS(phone_number, "22 graders styring aktiv varmepumpe er on"); 
            }
           else if (OnOff == false) {
           sms.SendSMS(phone_number, "22 graders styring deaktiv, varmepumpe er off"); 
            }
          }
        //
         nySMS = false;
      }

      if(!strcmp(sms_text, "15")) {
          tempStyring15 = !tempStyring15;
          tempStyring22 = false;
          if (tempStyring15 == true) {
            if (OnOff == true) {
           sms.SendSMS(phone_number, "Du har aktiveret 15 graders styring, varmepumpe er on"); 
            }
           else if (OnOff == false) {
           sms.SendSMS(phone_number, "Du har aktiveret 15 graders styring, varmepumpe er off"); 
            }
          }

          else if (tempStyring15 == false) {
           if (OnOff == true) {
           sms.SendSMS(phone_number, "15 graders styring aktiv varmepumpe er on"); 
            }
           else if (OnOff == false) {
           sms.SendSMS(phone_number, "15 graders styring deaktiv, varmepumpe er off"); 
            }
          }
         nySMS = false;
      }
      
      if(!strcmp(sms_text, "Status")) {
       tempSens.requestTemperatures();
       float temperature = tempSens.getTempCByIndex(0);
       int intTemperature = (int) temperature + 0.5;
       String stringOne = "Temperaturen er lige nu: ";
       stringOne += intTemperature;
       if (OnOff == true) {
         stringOne += "\nVarmepumpen er On"; 
       }
       else {
         stringOne += "\nVarmepumpen er Off"; 
       }
       if (tempStyring22 == true) {
        stringOne += "\n22 Graders funktion aktiv";
       }
       
       else if (tempStyring15 == true) {
        stringOne += "\n15 Graders funktion aktiv"; 
       }
       
       else{
        stringOne += "\nIngen temp. funktioner aktiv";
       }
       char textSMS[150];
       stringOne.toCharArray(textSMS, 150);
       sms.SendSMS(phone_number, textSMS);  
      }
      
      if(sms.DeleteSMS(position)){
       Serial.println("\nSMS Slettet"); 
      }
    }
    delay(2000);
  }
        
  if (tempStyring22 == true) {
     tempSens.requestTemperatures();
     float temperature = tempSens.getTempCByIndex(0);
     delay(100); //just here to slow down the output so it is easier to read
     if (temperature <= 21) {
      if (OnOff == false){
       varme();
       }
     }
     if (temperature >= 22) {
      if (OnOff == true){
       varme();
       }
     }
   }
     
   if (tempStyring15 == true) {
     tempSens.requestTemperatures();
     float temperature = tempSens.getTempCByIndex(0);
     delay(100); //just here to slow down the output so it is easier to read
     if (temperature <= 14) {
      if (OnOff == false){
       varme();
       }
     }
     if (temperature >= 15) {
      if (OnOff == true){
       varme();
       OnOff = !OnOff;
       }
     }
  }
}

Just a guess, but how are you powering the shield?

It's a bit long and lacks comments, and not in a language I can read. Can you give a more detailed description of how the program flows, while not getting an SMS, and then how it works when it receives an SMS? Helps a lot if you explain it in words.

I have tried powering the arduino and shield via USB and an external 2A Powersupply, nothing helps.

First off, i forgot to mention, i am using the GSMSHIELD library.

It has 4 sms commands it should respond to As listed below:

VP - Poweres on the heater manually, by activating the function varme() which turns on the relay for the heater.

15 - a setting set for 15 degrees, starts and stops the heater accordingly. Again by activating the function varme().

22 - same as above, just with 22.

Status - Responds a status message, which contains information about the current temperature (Temperaturen er lige nu = The temperature right now) and wether or not a temperature controller is active (the function 15 or 22).¨

When ever it receive a text, it shows this in my serial connection:

RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: 
+CMGL:
ATT: OK
RIC: 
+CMGL: 1,"REC READ","+4522234850","","14/04/23,20:4
ATT: OK
RIC: 
+CMGL: 1,"REC READ","+4522234850","","14/04/23,20:44:37+08"
Vp

OK

ATT: +CMGL:
RIC: 
+CMGL: 1,"REC READ","+4522234850","","14/04/23,20:44:37+08"
Vp

OK

And then it reboots.

While not receiving a message, it shows this:

ATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: 
OK

ATT: +CMGL:
RIC: 
OK

If it receives a text it does not have to respond to, it stops, and does nothing, as shown below:

ATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: NO STRING RCVDATT: OK
RIC: 
+CMGL: 1,"REC UNREAD","+4522234850",
ATT: OK
RIC: 
+CMGL: 1,"REC UNREAD","+4522234850","","14/04/23,21:11:00+08"
Bum

OK

ATT: +CMGL:
RIC: 
+CMGL: 1,"REC UNREAD","+4522234850","","14/04/23,21:11:00+08"
Bum

OK

Your code is too long to understand and you are not offering any explanation how it runs. How am I supposed to help you?

At least, initialize your array!!!

char sms_text[100]=""; // Besked indhold

At least, initialize your array!!!

The compiler/crt0 already did that.

Is the array big enough?

It should be. I counter the longest message it could have to send to 105 characters.
What further explanation do you require?

I counter the longest message it could have to send to 105 characters.

So where do the other 5 characters go?

The sms_text[100] char is containing the text in the incoming text.

To break things down:

  position=sms.IsSMSPresent(SMS_ALL);
    onOroff();
    if(position >= 1)
    {
      nySMS = true;
      hentSMS = sms.GetSMS(position, phone_number, sms_text, 100);

This bit of code checks to see, if there is a new message.

This bit, checks to see, if the text in the message is equivalent to "VP", and replies with a text, depending on the heater to be on (True) or off (false)

if (!strcmp(sms_text, "VP")) {
        varme();
        if (OnOff == true) {
          sms.SendSMS(phone_number, "Varmepumpe Startet");
        }
        else if(OnOff == false) {
          sms.SendSMS(phone_number, "Varmepumpe Slukket"); 
        }
        nySMS = false;
        }

This next bit activates the 22 degrees function, returning a text stating if the function is activated or not, and if the heater is on or off:

if(!strcmp(sms_text, "22")) {
          tempStyring22 = !tempStyring22;
          tempStyring15 = false;
          if (tempStyring22 == true) {
            if (OnOff == true) {
           sms.SendSMS(phone_number, "Du har aktiveret 22 graders styring, varmepumpe er on"); 
            }
           else if (OnOff == false) {
           sms.SendSMS(phone_number, "Du har aktiveret 22 graders styring, varmepumpe er off"); 
            }
          }

          else if (tempStyring22 == false) {
           if (OnOff == true) {
           sms.SendSMS(phone_number, "22 graders styring aktiv varmepumpe er on"); 
            }
           else if (OnOff == false) {
           sms.SendSMS(phone_number, "22 graders styring deaktiv, varmepumpe er off"); 
            }
          }
        //
         nySMS = false;
      }

This next bit is the same as above, only this time its 15 degrees instead of 22:

if(!strcmp(sms_text, "15")) {
          tempStyring15 = !tempStyring15;
          tempStyring22 = false;
          if (tempStyring15 == true) {
            if (OnOff == true) {
           sms.SendSMS(phone_number, "Du har aktiveret 15 graders styring, varmepumpe er on"); 
            }
           else if (OnOff == false) {
           sms.SendSMS(phone_number, "Du har aktiveret 15 graders styring, varmepumpe er off"); 
            }
          }

          else if (tempStyring15 == false) {
           if (OnOff == true) {
           sms.SendSMS(phone_number, "15 graders styring aktiv varmepumpe er on"); 
            }
           else if (OnOff == false) {
           sms.SendSMS(phone_number, "15 graders styring deaktiv, varmepumpe er off"); 
            }
          }
         nySMS = false;

This next bit, is a status text. It should reply the current status of the system, wether or not a temperature control is activated, what temperature there is now, and if the heater is on or off:

      if(!strcmp(sms_text, "Status")) {
       tempSens.requestTemperatures();
       float temperature = tempSens.getTempCByIndex(0);
       int intTemperature = (int) temperature + 0.5;
       String stringOne = "Temperaturen er lige nu: ";
       stringOne += intTemperature;
       if (OnOff == true) {
         stringOne += "\nVarmepumpen er On"; 
       }
       else {
         stringOne += "\nVarmepumpen er Off"; 
       }
       if (tempStyring22 == true) {
        stringOne += "\n22 Graders funktion aktiv";
       }
       
       else if (tempStyring15 == true) {
        stringOne += "\n15 Graders funktion aktiv"; 
       }
       
       else{
        stringOne += "\nIngen temp. funktioner aktiv";
       }
       char textSMS[150];
       stringOne.toCharArray(textSMS, 150);
       sms.SendSMS(phone_number, textSMS);  
      }

The next bit, deletes the message it received, to make room for a new:

      if(sms.DeleteSMS(position)){
       Serial.println("\nSMS Slettet"); 
      }
    }
    delay(2000);
  }

And here is the functions, for the temperature control:

  if (tempStyring22 == true) {
     tempSens.requestTemperatures();
     float temperature = tempSens.getTempCByIndex(0);
     delay(100); //just here to slow down the output so it is easier to read
     if (temperature <= 21) {
      if (OnOff == false){
       varme();
       }
     }
     if (temperature >= 22) {
      if (OnOff == true){
       varme();
       }
     }
   }
     
   if (tempStyring15 == true) {
     tempSens.requestTemperatures();
     float temperature = tempSens.getTempCByIndex(0);
     delay(100); //just here to slow down the output so it is easier to read
     if (temperature <= 14) {
      if (OnOff == false){
       varme();
       }
     }
     if (temperature >= 15) {
      if (OnOff == true){
       varme();
       OnOff = !OnOff;
       }
     }
  }
}

Could this be a memory problem with the arduino? it tells me i'm only using 19.064 bytes out of 32.256, but still?

it tells me i'm only using 19.064 bytes out of 32.256, but still?

That's how much flash (program) memory it uses - it says nothing about RAM.

Is there any way i can check that?

I'm leaning towards it!

You still haven't answered the question I posed in reply #7

liudr:
Your code is too long to understand and you are not offering any explanation how it runs. How am I supposed to help you?

At least, initialize your array!!!

char sms_text[100]=""; // Besked indhold

SMS is 140 octets, not 100, make sure your array is long enough...

Awol - What do you men where does the other 5 go? The max length of the text it should receive is 6 characters.

140 octets? I dont understand, sorry

The max length of the text it should receive is 6 characters.

So why did you say 105?

Thai is the max. Length the outgoing massage Will Reach

Could the issue be, that my strings are taking up all the SRAM space?

I'd go for the easy gains and move as many constant strings into flash, and see how that goes.

Give us an example of the longest SMS you will send. Will it be stored in the 100 byte buffer?

Read String class reference in arduino IDE. Use string.reserve(). We don't like people using String class here, especially those that don't understand the class but insists on using it in a "pyramid" way.

The max length of a text i will SEND to the arduino, is 6 characters. "Status".

How would i go around and do that? i've tried and google a few times, but i can't get the F() to work properly :S

What does the 100 in this line of code mean? I don't have your shield or library.

[/hentSMS = sms.GetSMS(position, phone_number, sms_text, 100);
code]

If it somehow means length of text, it may overflow even if SMS is very short. Just my hunch.