Using Arduino > Networking, Protocols, and Devices

Sending SMS using SIM900 GPRS Shield

(1/2) > >>


I am using the gprs shield v1.0 with arduino uno and I wish to send an SMS using it. This is the link to shield :
I use the GSM library which comes along with it.

I uploaded the following code to Arduino:

--- Code: ---
#include "SIM900.h"
#include <SoftwareSerial.h>

#include "sms.h"

int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];

void setup()
  //Serial connection.
  Serial.println("GSM Shield testing.");
  //Start configuration of shield with baudrate.
  //For http uses is reccomanded to use 4800 or slower.
  if (gsm.begin(9600)){
  else Serial.println("\nstatus=IDLE");
    //Enable this two lines if you want to send an SMS.
      int c = sms.SendSMS("+919703894422", "Arduino SMS");

void loop()
    //Read if there are messages on SIM card and print them.
    if(gsm.readSMS(smsbuffer, 160, n, 20))

--- End code ---

The sendSMS function returns a value of -1, which is the default value if SMS is not sent.
I went through the library's send SMS function but could not find any bug in it. This is the code:

--- Code: ---
char SMSGSM::SendSMS(char *number_str, char *message_str)
  char ret_val = -1;
  byte i;
  char end[2];
  if (CLS_FREE != gsm.GetCommLineStatus()) return (ret_val);
  ret_val = 0; // still not send
  // try to send SMS 3 times in case there is some problem
  for (i = 0; i < 3; i++) {
    // send  AT+CMGS="number_str"
#ifdef DEBUG_ON
Serial.println("DEBUG:SMS TEST");
    // 1000 msec. for initial comm tmout
    // 50 msec. for inter character timeout
    if (RX_FINISHED_STR_RECV == gsm.WaitResp(1000, 500, ">")) {
#ifdef DEBUG_ON
      // send SMS text
  //_cell.flush(); // erase rx circular buffer
      if (RX_FINISHED_STR_RECV == gsm.WaitResp(7000, 5000, "+CMGS")) {
        // SMS was send correctly
        ret_val = 1;

      else continue;
    else {
      // try again


  return (ret_val);

--- End code ---

I found that when the function writes the SMS text to gsm, it does not receive the desired "+CMGS" from gsm and hence return value is never set to 1. Can someone please tell why this is happening?

I also tried sending the AT commands through a serial monitor and there also I face the same problem. After I write the message and send a Ctrl+Z, it responds with ERROR.

Please help....

my suggestions could seem obvious but you didn't say anything about the status LED
Does it blink at the rate of 64ms On/3000ms Off ?
And does your sim card need a pincode ? if yes, did you enter it ?

I don't have this shield (mine is a gps/gprs v3, based on the sim908) , and I don't use the library, which takes too much memory for my needs, then I'm not sure I'll be able to help, but I think you should give as much details as  you can (e.g. put your code here,  tell the output you get on the serial monitor...)


Thanks. The Status LED (red) is always ON, the Netlight LED (green) is 64ms On/3000ms Off, which means it is able to find the network. I dont have any PIN for SIM card.

My code using GSM library is given in the above post. Its output is as follows:

--- Quote ---
GSM Shield testing.

--- End quote ---

-1 implies that the sms is not sent.

When I dont use the GSM library, I upload the following code to Arduino. It handles the serial communication between the Arduino and shield:

--- Code: ---
#include <SoftwareSerial.h>

SoftwareSerial GPRS(7, 8);
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count=0;     // counter for buffer array
void setup()
  GPRS.begin(9600);               // the GPRS baud rate   
  Serial.begin(9600);             // the Serial port of Arduino baud rate.


void loop()
  if (GPRS.available())              // if date is comming from softwareserial port ==> data is comming from gprs shield
    while(GPRS.available())          // reading data into char array
      buffer[count++];     // writing data into array
      if(count == 64)break;
    Serial.write(buffer,count);            // if no data transmission ends, write buffer to hardware serial port
    clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
    count = 0;                       // set counter of while loop to zero

  if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
    GPRS.write(;       // write it to the GPRS shield
void clearBufferArray()              // function to clear buffer array
  for (int i=0; i<count;i++)
    { buffer[i]=NULL;}                  // clear all index of array with command NULL

--- End code ---

And then I manually give AT commands for sending SMS using a serial tool. The output in the Serial monitor is as follows:

Only the final step of sending the msg text followed by Ctrl+Z doesn't work.
When I give AT command for reading SMS (AT+CMGR=1), it displays the top SMS successfully. Many other AT commands from the SIM900 datasheet are also working fine. Dont know what happens while sending SMS.  I've also tried feeding the SMS center number but that didn't help.

I am also using a Seeed GPS shield. I have a Mac computer and can not get sscom on it as it is a Microsoft program. Is there a way to load up the shield and send SMS with the Arduino terminal? What are some basic steps I can use to send an SMS message test without SSCOM and with a T-Mobile 2$ a day unlimited talk/text plan? This is my first post, I am a noob, please be kind! :)

I dont know if its any help, but i connected a Nokia 5310 via serial (hyperterminal) and worked with ATcommands.. this one worked:

--- Code: ---AT+CMGF=1  + Enter  //defines text mdoe
AT+CMGS="0123456789", + Enter   //defines receptor
BODY_OF_SMS //Message
--- End code ---

I think you are missing a "," on your ATcommand (not sure about the " " )


[0] Message Index

[#] Next page

Go to full version