title: send sms with sim900 using arduino
body: <pre><code> #include &lt;Password.h&gt; 
  #include &lt;Keypad.h&gt; 
  #include &lt;Servo.h&gt; 
  #include "SIM900.h"
  #include &lt;SoftwareSerial.h&gt;
  #include "sms.h"
  
  Servo myservo; 
  Password password = Password( "1234" ); //password to unlock box, can be changed
  SMSGSM sms;
  int numdata;
  boolean started=false;
  char smsbuffer[160];
  char n[20];
  
  const byte ROWS = 4; 
  const byte COLS = 4; 
  
  // Define the Keymap
  char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
  };
  // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
  byte rowPins[ROWS] = { 9, 8, 7, 6 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
  byte colPins[COLS] = { 5, 4, 3, 2 };
  int x=0;
  
  
  // Create the Keypad
  Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  
  void setup()     //if i add sms(); function it workssss
  { 
  
     Serial.begin(9600); //Start a Serial COM
  
     Serial.println(F("ARDUINO SECURITY SYSTEM V1.0"));
  
     Serial.print(F("Checking GSM COM..."));
  
    if (gsm.begin(9600)) //Start the GSM COM
    {
      (sms.SendSMS("+XXXXX","Your Home Security system is powered up"));
      Serial.println(F("Good To GO!!"));
    }
    else
    {
      Serial.println(F("Could not connect to GSM modem"));
    }
  
    Serial.write(254);
    Serial.write(0x01);
    delay(200); 
    pinMode(11, OUTPUT);  //green light
    pinMode(12, OUTPUT);  //red light
    myservo.attach(13); //servo on digital pin 9 //servo
    keypad.addEventListener(keypadEvent);//add an event listener for this keypad
  
    }
  
  void loop(){
    keypad.getKey();
    myservo.write(0);
    }
    //take care of some special events
    void keypadEvent(KeypadEvent eKey){
    switch (keypad.getState()){
    case PRESSED:
  
    Serial.print("Enter : ");
    Serial.println(eKey);
    delay(10);
  
    Serial.write(254);
  
    switch (eKey){
      case 'A': checkPassword(); delay(1); break;
      case 'C': checkPassword(); delay(1); break;
      case 'D': checkPassword(); delay(1); break;
      case 'B': password.reset(); delay(1); break;
      case '*': checkPassword(); break;
      case '#': password.reset(); break;
  
      default: password.append(eKey); delay(1);
    }
   }
  }
  void checkPassword(){
  
  if (password.evaluate()){  //if password is right open box
  
      Serial.println("Accepted");
      Serial.write(254);delay(50);
      //Add code to run if it works
      myservo.write(5); //160deg
  
          digitalWrite(11, HIGH);//turn on
      delay(2000); //wait 5 seconds
      digitalWrite(11, LOW);// turn off   
  }
  else
  {
  
      Serial.println("Denied"); //if passwords wrong keep box locked
      Serial.write(254);delay(10);
      x++;
  
      if(x==3)
      //add code to run if it did not work
     {
      myservo.write(0);
      digitalWrite(12, HIGH); 
      delay(500); 
      digitalWrite(12, LOW);  
    if (gsm.begin(9600)) 
    {
      (sms.SendSMS("+XXXXX","Your Home Security system is being bridged"));
  
      Serial.println("USER WARNED");
     }
  
  }
  }
  }
  ;
  }
  </code></pre>
  
  <p>In the picture the same code doesn't seem to work when I place the lines</p>
  
  <pre><code>if (gsm.begin(9600)) //Start the GSM COM
    {
      (sms.SendSMS("+8613668914901","Your Home Security system is being bridged"));
  </code></pre>
  
  <p>but this lines work great inside the void setup function.</p>
  
  <p><img src="https://i.stack.imgur.com/TY8iv.png" alt="Image"></p>
  
  <p>How can I fix this problem? Inside the void setup the sketch works fine but when I also put the code in the function CheckPassword it doesn't send SMS.</p>
  
  <p>I also tried to create a function let's say void SMS and call it in the checkPassword function but it doesn't solve the problem, btw the same function when called in the void setup works fine.</p>