[HELP] ARDUINO ERROR?

#include <SIM900.h>
#include <sms.h>
#include <SoftwareSerial.h>
SMSGSM sms;
char msg_distance[100];
const  int trigger=6;
  const  int echo=7;
  float  distance;
  float msg;
  int d_int;
  
// ---------- for sms ----------

char smsbuffer[160];      //holds buffered data
char numberRx[20];         //holds sender number
boolean started=false;

void setup ()
{
 
// ---------- serial port ----------
  gsmsetup();  
  pinMode(trigger,OUTPUT);
  pinMode(echo,INPUT);
  

}


void loop ()
{
  measuring();
  checkSMS();
  if (strstr(numberRx,"cp no.") != NULL){
  if(strstr(smsbuffer,"ON") != NULL)
 {
sprintf(msg_distance,"%d",d_int);
if (sms.SendSMS("cp no.", msg_distance));
 }
else if(strstr(smsbuffer,"OFF") !=NULL)
{
if(sms.SendSMS("cp no.", "Device Stop Sending Data!")); 
if(sms.SendSMS("cp no.", ""));
}
else if(strstr(smsbuffer,"UNLI") !=NULL)
{
if(sms.SendSMS("cp no.", "A30"));
if(sms.SendSMS("cp no.", "A30 has been send to 8888")); 
if(sms.SendSMS("cp no.", ""));
}
else{
if(sms.SendSMS("cp no.", "You send wrong code!")); 
if(sms.SendSMS("cp no.", ""));

}
  }
  
else if(strstr(numberRx,"cp no.") !=NULL)
{
  if(sms.SendSMS("cp no.", smsbuffer));
  if(sms.SendSMS("cp no.", ""));
}

if (strstr(numberRx,"cp no.") != NULL){
  if(strstr(smsbuffer,"ON") != NULL)
 {
sprintf(msg_distance,"%d",d_int);
if (sms.SendSMS("cp no.", msg_distance));
 }
}

delay(5000);
}
void gsmsetup(void)
// ---------- serial setup ----------
{
  //Serial connection.
  Serial.begin(9600);
  Serial.println("GSM Shield testing.");
  //Start configuration of shield with baudrate.
  //For http uses is raccomanded to use 4800 or slower.
  if (gsm.begin(4800)){
    Serial.println("\nstatus=READY");
    started=true;  
  }
  else Serial.println("\nstatus=IDLE");
 
}
void measuring(){
   // Trigger US-100 to start measurement
  // Set up trigger
  digitalWrite(trigger,LOW);
  delayMicroseconds(5);
  // Start Measurement
  digitalWrite(trigger,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigger,LOW);
  // Acquire and convert to mtrs
  distance=pulseIn(echo,HIGH);
  distance=distance*0.0001657;
  distance=distance*39.3701;
  // send result to UART
  d_int = (int) distance;
}


void checkSMS()
// ---------- check if there is new message ----------
{
   if(started){
    //Read if there are messages on SIM card and print them.
   
    if(gsm.readSMS(smsbuffer, 160, numberRx, 20))
    {
      Serial.print("\nFrom: ");
      Serial.print(numberRx);
      Serial.print("\nMessage: ");
      Serial.print(smsbuffer);
      Serial.println("\n");
    }   
    delay(5000);
    
  }
}

hi, there’s a problem in arduino compiler i think, because when i run my program using serial monitor, then i send a textmessage “ON” the loop will start sending the value of msg_distance. but when i close serial monitor and start the device and send a textmessage “ON” the loop will start sending but only 1 time i will receive the value of msg_distance because smsbuffer became null, why I know? because i try to send the value of smsbuffer to me and when I send a “ON” it only send 1 time ON and the loop will send null value, smsbuffer become null. what should I do?

thanks.

Is the gsm shield using 4800 baud ?

Is this of any help : Arduino Forum ?

A problem with the compiler is unlikely. In this case, I say that is about 0.1% chance.

You could cleanup your code, make indents and so on.
Also "smsbuffer became null" is something I don't understand. You have be more precise. A pointer can become null, and a buffer can be filled with one or more '\0'.

There won't be problems with the Arduino compiler. Or if there are, they are very subtle ones that you have to work very hard at to cause. I'm not aware of any at present.

      if (sms.SendSMS("cp no.", msg_distance));

What is the point of the "if" here? And all the other similar ones?


  measuring();
  checkSMS();
  if (strstr(numberRx,"cp no.") != NULL){

And what if numberRx has not just been received?

if means, if that is the numberRx then it will text, and if not then it will not text.

You
really
need
to
put
each
{
on
a
new
line
and
use
Tools + Auto Format.

That code layout is awful.

if(sms.SendSMS("cp no.", "Device Stop Sending Data!"));

I don't think you want a semicolon there.

You haven't answered my first question before. Take this, for example:

if(sms.SendSMS("cp no.", "A30"));
if(sms.SendSMS("cp no.", "A30 has been send to 8888")); 
if(sms.SendSMS("cp no.", ""));

What do the three "if" statements achieve, in your opinion?

Just a heads-up. They aren't cumulative if that is what you are thinking. They achieve nothing the way you have written them. Except confusion.

that is only for sending sms. if no "if" only the first line will be send.

What you have written does not do that.