sending SMS with SM5100B - sends only one SMS

hi,

I wrote a code that call "sendsms" function, the code works and i get a message but only once. I can call the function a few times after i get the first sms but it doesnt do nothing, only if I reset the arduino (by software or manully) I get the sms at the first try of calling again to the function.

anyone?

anyone?

Anyone what? Want to see your code? No, not really, but you won't get help any other way.

Sorry.

Void SendSms()
{       
        tmpDA=digitalRead(DA);
        if ( tmpDA>0) scankDA();
        if (sys.mode==0) break;
        Serial.print("\nCurrent state is: ");
        Serial.print(sys.state, DEC);
        Serial.print("\n");
        Serial1.println("AT+CMGF=1"); // set SMS mode to text
        Serial1.print("AT+CMGS=");
        Serial1.print(34,BYTE); // ASCII equivalent of "
        Serial1.print(mobilenumber);
        Serial1.println(34,BYTE);  // ASCII equivalent of "
        delay(1000); // give the module some thinking time
        Serial1.print("Baby in danger");
        Serial1.println(26,BYTE);  // ASCII equivalent of Ctrl-Z
        delay(15000); // the SMS module needs time to return to OK status
         sys.state=7;
         laststate=6;
}

That's one function, not all of your code. Where is the serial output?

The “function” is actually part of state machine (switch based).
state 6 sends the message, again it works excellent at the first time but again only after reset.

int SensIn1= A0;            // Analog in pin for sensor 1 (baby)
int SensIn2= A1;            // Analog in pin for sensor 2 (driver)
int SensVal1=0;             // Sensor 1 measure		
int SensVal2=0;	             // Sensor 2 measure	
int SensSt1=0;	             // Sensor 1 indication
int SensSt2=0;		     // Sensor 2 indication
int pr=22;                         // Play/Recorde select
int pd=24;                         // Power down the ISD
int ce=26;                         // ISD chip enable
int eom=28;                       // end of message indication from ISD
int LED1=30;                       // LED pin
char mobilenumber[] = "0547368366";   // cell number for sending SMS
char doublecheck=0;
int P1=0;
int tmp=0;
byte DOutA= 32;            // select the pin for the Data output A
byte DOutB = 34;           // select the pin for the Data output B
byte DOutC = 36;           // select the pin for the Data output C
byte DOutD = 38;           // select the pin for the Data output D
byte DE = 40;                  // select the pin for the Output Enable
int DA = 42;                 // select the pin for the Data available
int RE=52;                   // Reset PIN
byte A=0,B=0,C=0,D=0, sum=0;
byte DAV=0, temp=0, StartOverFlag=4, StartIdentFlag=0;
byte d[5]={3,0,4,8,1};    //array needed for checking if the order of pressed key is correct
int tmpDA=0;
int duration=0;
int timeout=0;

struct system {
   byte state;
   byte mode;
};

system sys={1,1};
void delay_voice();
void startSMS();
void endSMS();
void scankeyboard();
void  printkeyboard();
void  scankDA();


void setup()
{
 digitalWrite(RE, HIGH);
 delay(200);
  pinMode(RE, OUTPUT);
 pinMode(pr,  OUTPUT);
 pinMode(pd, OUTPUT);
 pinMode(ce, OUTPUT);
 pinMode(eom, INPUT);
 pinMode(LED1, OUTPUT);
 pinMode(DOutA, INPUT);
 pinMode(DOutB, INPUT);
 pinMode(DOutC, INPUT);
 pinMode(DOutD, INPUT);
 pinMode(DA, INPUT);
 pinMode(DE, OUTPUT);
  Serial.begin (9600);
 Serial1.begin (9600);
 digitalWrite(pd, HIGH);
 digitalWrite(pr, HIGH);
 digitalWrite(DE, LOW); 
 delay(35000);
}

void loop()
{
//  static int state = 1; // initial state is 1, the "idle" state.
  static int laststate = 1;
  switch(sys.state)
  {
    case 1:
        tmpDA=digitalRead(DA);
        if ( tmpDA>0) scankDA();
        if (sys.mode==0) break;
        Serial.print("\nCurrent state is: ");
        Serial.print(sys.state, DEC);
        Serial.print("\n");
       if (sys.mode==1) 
       {
        SensVal1=analogRead(SensIn1);
        delay(1000);
        if (SensVal1>200)
        {
        SensSt1=1;
        sys.state=2;
        }
        else
        SensSt1=0;
       }
       break;
    case 2:
        tmpDA=digitalRead(DA);
        if ( tmpDA>0) scankDA();
        if (sys.mode==0) break;
        Serial.print("\nCurrent state is: ");
        Serial.print(sys.state, DEC);
        Serial.print("\n");
       SensVal2=analogRead(SensIn2);
       delay(1000);
      if (SensVal2>200)
       {
       SensSt2=1;
       sys.state=1;
       }
      else
       {
         SensSt2=0;
         sys.state=3;
       }
      break;
    case 3: 
        tmpDA=digitalRead(DA);
        if ( tmpDA>0) scankDA();
        if (sys.mode==0) break;
        Serial.print("\nCurrent state is: ");
        Serial.print(sys.state, DEC);
        Serial.print("\n");
        delay(1000);
      
      if (doublecheck==0)
      {
        doublecheck=1;
        sys.state=1;
        Serial.print("Check sensors again\n");
        delay(2000);
      }
      else
       {
         if( SensSt1==1 && SensSt2==0)
         {
         doublecheck=0;
         sys.state=6;
         }
       }
      break;
    case 4:
        tmpDA=digitalRead(DA);
        if ( tmpDA>0) scankDA();
        if (sys.mode==0) break;
        Serial.print("\nCurrent state is: ");
        Serial.print(sys.state, DEC);
        Serial.print("\n");
       digitalWrite(pr, HIGH);       // play mode
       Serial.print("\nPR set to HIGH\n");
       delay_voice();                          // wait interval 
       digitalWrite(pd, LOW);          // prepare voice to start operation 
       Serial.print("\nPD set to LOW\n");
       delay_voice(); 
       digitalWrite(ce, LOW);          // start play
      Serial.print("\nCE set to LOW\n"); 
       delay_voice(); 
       digitalWrite(ce, HIGH);        // play until end of the messege voice 
       Serial.print("\nCE set to HIGH\n");
       delay(5000);
       digitalWrite(pd, HIGH);	      // stop operation
       sys.state=7;
       laststate=4;
      break;
   case 5:
        tmpDA=digitalRead(DA);
        if ( tmpDA>0) scankDA();
        if (sys.mode==0) break;
        Serial.print("\nCurrent state is: ");
        Serial.print(sys.state, DEC);
        Serial.print("\n");
        delay(1000);
     for (int i=0; i<10; i++)
     {
       digitalWrite(LED1,HIGH); 
       Serial.print("\n1\n");
       delay(250);
       digitalWrite(LED1,LOW);
       delay(250);
       Serial.print("\n0\n");  
     }
     sys.state=7;
     laststate=5;
      break;
    case 6:
        tmpDA=digitalRead(DA);
        if ( tmpDA>0) scankDA();
        if (sys.mode==0) break;
        Serial.print("\nCurrent state is: ");
        Serial.print(sys.state, DEC);
        Serial.print("\n");
        Serial1.println("AT+CMGF=1"); // set SMS mode to text
        Serial1.print("AT+CMGS=");
        Serial1.print(34,BYTE); // ASCII equivalent of "
        Serial1.print(mobilenumber);
        Serial1.println(34,BYTE);  // ASCII equivalent of "
        delay(1000); // give the module some thinking time
        Serial1.print("Baby in danger");
        Serial1.println(26,BYTE);  // ASCII equivalent of Ctrl-Z
        delay(15000); // the SMS module needs time to return to OK status
         sys.state=7;
         laststate=6;
      break;
    case 7:
       tmpDA=digitalRead(DA);
       if ( tmpDA>0) scankDA();
       if (sys.mode==0) break;
       Serial.print("\nCurrent state is: ");
       Serial.print(sys.state, DEC);
       Serial.print("\n");
      if (laststate== 4)
      {
           tmpDA=digitalRead(DA);
           if ( tmpDA>0) scankDA();
           if (sys.mode==0) break;
           delay(10000);
           sys.state=5;
      }
      else if(laststate==5)
      {
           tmpDA=digitalRead(DA);
           if ( tmpDA>0) scankDA();
           if (sys.mode==0) break;
           delay(15000);
           sys.state=6;
      }
       else if(laststate==6)
       {
           tmpDA=digitalRead(DA);
           if ( tmpDA>0) scankDA();
           if (sys.mode==0) break;
           digitalWrite(RE,LOW);
           delay(50000);
           sys.state=1;
       }
     break;
     
    default:
      sys.state = 1;
      break;
  }
}
  
  void delay_voice()
  {
  delay(500);
  }
  

void  scankDA()
{
 for( int i=0; i<2; i++)
 {
  delay(1000);
 }
 tmpDA=digitalRead(DA);
 if(tmpDA>0)
{
  Serial.print("\n ready to scan code");
 digitalWrite(LED1, HIGH); 
 scankeyboard();
}
}

}

Part of the code (non rellavent function) deleted since i got the next message:
“The message exceeds the maximum allowed length”