Go Down

Topic: Sending SMS using SIM900 GPRS Shield (Read 6847 times) previous topic - next topic



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 : http://www.seeedstudio.com/wiki/GPRS_Shield_V1.0
I use the GSM library which comes along with it. https://code.google.com/p/gsm-shield-arduino/

I uploaded the following code to Arduino:

Code: [Select]

#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))

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: [Select]

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);

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:


GSM Shield testing.

-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: [Select]

#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++]=GPRS.read();     // 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(Serial.read());       // 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

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: [Select]
AT+CMGF=1  + Enter  //defines text mdoe
AT+CMGS="0123456789", + Enter   //defines receptor
BODY_OF_SMS //Message

I think you are missing a "," on your ATcommand (not sure about the " " )
b'10 bit || !(b'10 bit)


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.

The problem is your error reporting is only giving you basic information (ie ERROR).  You need to enable a more advanced error reporting scheme.  Send the command AT+CMEE=1 in your setup before trying to send a message.  Now when you have an error, you will get a more detailed explaination of what is causing the error by way of an error code which you can look up.

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter


Absolutely same problem during SMS sending... Did you find reason or solution...?

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131