sending sms by GSM sim900

hi,
i’m trying to send sms to my phone by gsm shield when the PIR sensor recoginze a motion .
but sometimes the PIR recognize a motion and the phone doesn’t receive sms.
and when it’s sent, phone receives it after like 1 min. how can i fix it (to receive sms directly when recognizing a motion and every time )?

this is my code:

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
int SenPin = 9;
int val=0;
int i=0;

boolean started=false;

void sendsms()
{
  if (sms.SendSMS("+XXXXXXXXXX", "SMS from Arduino "))
      Serial.println("\nSMS sent OK");
}

void setup() 
{
  //Serial connection.
   pinMode(SenPin, INPUT);
  Serial.begin(9600);
  Serial.println("GSM Shield testing.");

  if (gsm.begin(2400)){
    Serial.println("\nstatus=READY");
    started=true;  
  }
  else Serial.println("\nstatus=IDLE");
  

};



void loop() 
{
  if(i==0)
     delay(5000);
  val=digitalRead(SenPin);
  Serial.println(val);
  if(started && val)
  {
   sendsms();
   delay(2000);
  }
    else
        Serial.println("\nno motion");
   delay(1000);
   i++;
}

It might help to get rid of the delay() calls. If the PIR sensor signals in the middle of a delay() it will not be detected.

There will be some delay getting a message through the system. I don't think there is any way to guarantee immediate delivery.

i removed the delay and doens't help... can i use AT commands in arduino? and how?

can i use AT commands in arduino?

Only if you can also use capital letters.

and how?

Just [u]exactly[/u] like the library does.

PaulS:

can i use AT commands in arduino?

Only if you can also use capital letters.

and how?

Just [u]exactly[/u] like the library does.

thank u but how exactly can i use capital letters? does it need a special terminal or something like that?