How to send and receive SMS with GSM/GPRS & GPS shield

By on May 30, 2013

 GSM shield_COP_s

This post is one in a series showing you the main features of the GSM /GPRS/GPS shield and of its related library. The examples are great to have inspiration and reuse the material to create your own solutions. We already talked about how to use the shield to make calls, send DTMF tones and check whether the sender of an incoming call and command was in the trusted phonebook.

This is possible thanks to the call.h class contained within the call management library. Here we will show you few examples about how to deal with SMS management. The sms.h file, shows you how to send a text message in correspondence to a particular condition or how to extrapolate the content of a received text message and how to interprete the commands contained within it.

 Download_GSM_library

EXAMPLE 1

Let’s start from a sketch that can be used to send a text message to a preset number in case an alarm condition is happening. This example is similar to the one we shown regarding placing calls, it has been obviously tweaked to send a text message instead of placing a call.

In this case, the triggering condition is reached when the Arduino board reads an analog value that is below to one that has been  preset as a threshold value and the notification is done by sending a text message.

As for each sketch concerning this shield, first thing to do is to include the library (in this case the sms.h file) and then instantiate an object. This procedure can be done with the following commands:

#include “sms.h”

SMSGSM sms;

Each function belonging to this class must be initialized as follows:

object_name.function_name(parameters)

In case the alarm status condition is verified, in order to send a message you simply call the following function:

sms.SendSMS(number,message);

The first parameter contains the message recipient, while the second one is the string containing the message body.

For example:

char message[]=“Hello world”;

char number[]=“3921234567”;

sms.SendSMS(number,message);

In this way the string “Hello world”  will be sent.

 In this example, in addition to sending the static string containing the warning message, we’ve also chosen to communicate the value that triggered the alarm condition: we must therefore transform the analog integer value read from the converter, in a string to be concatenated to the static one.

 

The function that takes care of this conversion is the on that follows:

 itoa(int integer, char* string, int base)

where base is usually 10 since we work in decimal base. If we were to work with numbers in different bases we just need to change this value as appropriate.

 

The function used to concatenate a string to another is:

strcat(char* string1, char* string2)

 

#include "SIM900.h"

#include <SoftwareSerial.h>

#include "sms.h"

SMSGSM sms;

char number[]="3921234567";

int value=0;

int value_old=0;

char message[40];

char value_str[4];

int pin=A0;

void setup()

{

 Serial.begin(9600);

 if (gsm.begin(2400))

   Serial.println("\nstatus=READY");

 else Serial.println("\nstatus=IDLE");

 value=analogRead(pin);

 value_old=analogRead(pin);

};

void loop()

{

 value=analogRead(pin);

 Serial.println(value);

 if(value<50&&value_old>=50){

   message[0]='\0';

   strcat(message,"ALLARME LOW, VAL=");

   itoa(value,value_str,10);

   strcat(message,value_str);

   sms.SendSMS(number,message);

 }

 value_old=value;

 delay(1000);

};

 

As said in the previous post, it is highly recommended to set a hysteresis or a low-pass filter to avoid repeatedly sending text messages in the case of oscillations around the threshold value.

In case you wish to add a message to communicate the return to the starting condition, you just need add the following piece of code before the update of the value_old variable.

 

else if(value>50&&value_old<=50){

 message[0]='\0';

 strcat(message,"ALLARME HIGH, VAL=");

 itoa(value,value_str,10);

 strcat(message,value_str);

 sms.SendSMS(number,message);

}

 

gsm-shield-SIM908_s

EXAMPLE 2

Let’s have a look to the sketch used to interpret the commands received via text message. We’ll check the status of a digital output by sending simple text messages to the shield.

Will be possible, therefore, to give the Arduino some remote commands, by simply sending a text message.

To keep a minimum security level (in order to prevent unauthorized persons to execute commands) without imposing limitations to the sender number, the use of temporary password is provided.strstr(char* string, char* string2)

 

The first step is to check the presence of a new, unread, message and, in case, store the position in which it is stored on the SIM thanks to the following command:

sms.IsSMSPresent(SMS_UNREAD);

which returns an integer containing the position of the first unread message. If no new messages are found it will return 0.

To analyze the content you need to ‘open’ the message and read the contents.

sms.GetSMS((int)pos,number,message,180);

 The GetSMS function takes care of reading the message in the position shown and to save the sender number and the message body (up to a maximum of characters as indicated by the last parameter).

Once this is done you just need to control the text of the message to interpret the commands that have been sent.

First, we’ll verify that the password is contained in the message body (the password used in the examplse is ‘testpwd‘). To do this we’ll use the strstr(char* string, char* string2) function that checks if the second string passed is contained within the first, returning a pointer to the first character of the substring.

p=strstr(message,”testpwd”);

In case the substring is not present, a NULL pointer will be returned.

To verify the correct authentication simply insert the remaining code portion within the condition:

if(p){ […] }

Let’s recall that if(p) is equivalent to writing if (!=NULL).

At this point, when authentication is done, as done previously for the password, we’ll check the presence of predetermined command strings. Once we’ve got the message, we’ll proceed with the interpretation, by enabling or disabling the output.

Finally, we will delete the message, to avoid filling up the memory available on the SIM card. This will be done with the command:

sms.DeleteSMS((int)pos);

 

#include "SIM900.h"

#include <SoftwareSerial.h>

#include "sms.h"

SMSGSM sms;

char number[]="3921234567";

char message[180];

char pos;

char *p;

void setup()

{

 Serial.begin(9600);

 if (gsm.begin(2400))

   Serial.println("\nstatus=READY");

 else Serial.println("\nstatus=IDLE");

};

void loop()

{

 pos=sms.IsSMSPresent(SMS_UNREAD);

 Serial.println((int)pos);

 if((int)pos>0&&(int)pos<=20){

   Serial.print("NUOVO MESSAGGIO, POS=");

   Serial.println((int)pos);

   message[0]='\0';

   sms.GetSMS((int)pos,number,message,180);

   p=strstr(message,"testpwd");

   if(p){

     Serial.println("PSWD OK");

     p=strstr(message,"LEDON");

     if(p){

       Serial.println("LED ON");

       digitalWrite(13,HIGH);

     }

     else{

       p=strstr(message,"LEDOFF");

       if(p){

         Serial.println("LED OFF");

         digitalWrite(13,LOW);

       }

     }

   }

   sms.DeleteSMS((int)pos);

 }

 delay(5000);

};

 gsm-shield-TDGGSM_900_s

EXAMPLE 3

As previously mentioned, we can provide authentication also by checking the sender.

In the same way as, in previous examples, we checked whether the sender of an incoming call was authorized, you can do the same operation with SMS sender.

sms.GetAuthorizedSMS((int)pos,number,message,180,8,10);

Saving the trusted contacts on the within a specific range of the SIM will be enough: we just need to check what’s returned by the function in which we pass the range using the last two parameters.

In this case the authorized number is saved between position 8 and position 10 (both included) of the SIM.

if(stat==GETSMS_AUTH_SMS){

Thanks to the previous condition we will enter the routine associated with the condition in which the SMS is received from a trusted number.

Differently from the previous case, in this example we will analyze a string containing the logic states (0 or 1) that must be set on the digital outputs (for example: “LEDCONF0000” or “LEDCONF1001” and so on.)

Using the substrings search function we will identify the command for the allocation of the states and then we will move forward analyzing it character by character and then setting the appropriate status to its output.

In this example, the “LEDCONF0000” string, sent to turn off all outputs, is composed of the first part (LEDCONF) that relates to the command type (in fact we could send different commands within a single message) and by a following part containining 0000 as the states to be set on the outputs ranging from 9 to 12.

Recalling that the search function, if successful, returns a pointer to the first character of the substring, you will need to move forward of a number of characters that is sufficient to reach the first value containing the information on the first output.

We’ll do this thanks to the strlen(char* string) function that gives back an integer with the length of the string passed as a parameter.

Then we translate the pointer of a number of characters that is equal to the length of the command:

p=p+strlen(“LEDCONF”);

In this way the p pointer will refer to the first numeric character.

will be sufficient to check if this is equal to 1 or 0 to activate or not the output to it associated with it.

if(p[0]==’1′)

For your convenience we will put everything in a loop equipped with some diagnostic messages (not strictly necessary) sent to the hardware serial port.

As we did before, at the end of the cycle we first delete the SMS and then add a a few seconds delay to avoid making continuous queries to the shield.

 

#include "SIM900.h"

#include <SoftwareSerial.h>

#include "sms.h"

SMSGSM sms;

char number[]="3921234567";

char message[180];

byte stat;

char pos;

char *p;

int i=0;

void setup()

{

 Serial.begin(9600);

 if (gsm.begin(2400))

   Serial.println("\nstatus=READY");

 else Serial.println("\nstatus=IDLE");

 pinMode(9,OUTPUT);

 digitalWrite(9,HIGH);

 pinMode(10,OUTPUT);

 digitalWrite(10,HIGH);

 pinMode(11,OUTPUT);

 digitalWrite(11,LOW);

 pinMode(12,OUTPUT);

 digitalWrite(12,LOW);

 pinMode(13,OUTPUT);

 digitalWrite(13,LOW);

};

void loop()

{

 pos=sms.IsSMSPresent(SMS_UNREAD);

 Serial.println((int)pos);

 if((int)pos>0&&(int)pos<=20){

   Serial.print("NUOVO MESSAGGIO, POS=");

   Serial.println((int)pos);

   message[0]='\0';

   stat=sms.GetAuthorizedSMS((int)pos,number,message,180,8,10);

   if(stat==GETSMS_AUTH_SMS){

     p=strstr(message,"LEDCONF");

     if(p){

       p=p+strlen("LEDCONF");

       i=9;

       while(p[0]!='\0'&&i<13){

         Serial.print("P= ");

         Serial.write(p[0]);

         Serial.println("");

         if(p[0]=='1'){

           Serial.print(i);

           Serial.println(" HIGH");

           digitalWrite(i,HIGH);

         }

         else if (p[0]=='0'){

           Serial.print(i);

           Serial.println(" LOW");

           digitalWrite(i,LOW);

         }

         Serial.println("");

         p++;

         i++;

       }

     }

   }

   //Serial.println(message);

   sms.DeleteSMS((int)pos);

 }

 delay(5000);

};

 

EXAMPLE 4

In this last example we chosen to create a sketch using both the classes we created: that for the management of phone calls and that to manage SMS.

Upon the reception of a call from a trusted number, the program will check the status of the inputs (digital ones have been chosen but you can be easily extend to analog ones) and will communicate this information through an SMS to a specified number.

Since this sketch uses functions already explained in this and in the previous article, we will just post the code without explaining in detail each step.

 

#include "SIM900.h"

#include <SoftwareSerial.h>

#include "sms.h"

#include "call.h";

CallGSM call;

SMSGSM sms;

char number[]="3921234567";

char message[180];

byte state;

int i=0;

char pin_str[2];

char pin_val[1];

void setup()

{

 Serial.begin(9600);

 Serial.println("GSM Shield testing.");

 if (gsm.begin(2400))

   Serial.println("\nstatus=READY");

 else Serial.println("\nstatus=IDLE");

 pinMode(9,INPUT);

 pinMode(10,INPUT);

 pinMode(11,INPUT);

 pinMode(12,INPUT);

 pinMode(13,INPUT);

};

void loop()

{

 number[0]='\0';

 state=call.CallStatusWithAuth(number,8,10);

 if(state==CALL_INCOM_VOICE_AUTH){

   Serial.println("Chiamata in corso da numero autorizzato");

   Serial.println(number);

   call.HangUp();

   message[0]='\0';

   for (i=9; i<=13; i++){

     strcat(message,"PIN");

     itoa(i,pin_str,10);

     strcat(message,pin_str);

     strcat(message,"=");

     itoa(digitalRead(i),pin_val,10);

     strcat(message,pin_val);

     strcat(message," ");

   }

   delay(2000);

   Serial.println("INVIO SMS");

   sms.SendSMS(number,message);

 }

 delay(1000);

};

About Boris Landoni

Boris Landoni is the technical manager of Open-Electronics.org. Skilled in the GSM field, embraces the Open Source philosophy and its projects are available to the community.
  • Pingback: How to send and receive SMS with GSM/GPRS &...()

  • Pingback: The GSM/GPRS & GPS Shield: some Http connections examples | Open Electronics()

  • Pingback: How to use GPS functions with GSM/GPRS & GPS shield | Open Electronics()

  • Filippos

    Hi there,

    I keep getting this error:

    Trying to force the baud-rate to 9600

    ERROR: SIM900 doesn’t answer. Check power and serial pins in GSM.cpp

    status=IDLE

    I am using the GSM shield sold by OpenElectronics and your code but nothing seems to work! I changed 6 arduino Uno and tried 3 different power supply units.

    Any Idea why it doesn’t work

    Thanks in advance

    • BorisLandoni

      Have you chose the soft serial?
      There are two jumper to select hardware serial or soft.
      Please select soft

  • Kostas

    Hello there,I try example2 and wrks perfect.But when ill try to change the pin number that i want to make HIGH, nothing happent.For example if I change pin13 to pin12 on pin12 i havent HIGH when I send sms.Any saggestions?
    Wait answer asap.
    Have a nice day.
    Kostas

    • BorisLandoni

      Try to set the pin as output
      pinMode(12,OUTPUT);

  • Nazmul Hasan Pias

    Hi , I’m a beginner . I want to use your library without aurduino , in any avr microcontroller using available compilers . How can I do this ?

    • 4routing (ADMIN)

      did you implement something on atmega?

  • Tom

    Hi there,

    I can send SMS messages but whenever I try and read a new SMS it doesn’t return the text message (it returns nothing at all). The GetSMS function returns GETSMS_OTHER_SMS. I know the message is on the phone as I can put the SIM in a standard phone and it shows up. Any ideas?

    • Martin

      I have the same problem, but when I active DEBUG it prints one message over and over again.

      How do I fix this?

      • Martin

        I ended up using this code;

        char position;
        char phone_num[20]; // array for the phone number string
        char sms_text[15]; // array for the SMS text string
        if (started){
        position = 1;
        if (position) {
        // there is new SMS => read it
        sms.GetSMS(position, phone_num, sms_text, 100);
        /* #ifdef DEBUG_PRINT
        sms.DebugPrint(“DEBUG SMS phone number: “, 0);
        sms.DebugPrint(phone_num, 0);
        sms.DebugPrint(“rn SMS text: “, 0);
        sms.DebugPrint(sms_text, 1);
        #endif*/
        }}

        Since I was only looking for one message thats always the first one. It contains settings for gprs.

  • karlcedrick

    what programming tool is used in developing the program?

    • BorisLandoni

      ? Arduino IDE

  • Juan Alexis Vidal Gonzales

    I’m connecting a gps and sd card ublox whith gprs shield (separated work well) and together the gprs shield does not turn on, please help

    • BorisLandoni

      Be sure that the memory doesn’t overflow

  • Martín

    Hello, I need some help please.
    I’m trying to get to work example 2 without success.
    I tried with a power supply of 12 V @ 1,5 A and the jumper are configured as software serial.
    Is it possible obtain a detailed step by step to check this shield and get to work example 2?
    Thanks in advance for your help.
    Best regards

    • BorisLandoni

      The other examples work?
      What the problem?

      • Martín

        Hi Boris, I tried example 4 too without success.
        The problem is I have no idea why doesnt work, there is no response from the shield and Arduino Uno.
        There is anything I can do in order to check the shield?
        There is a guide step by step in order to make work these shield with example 2 or 4?
        Merry christmas by the way!!!
        Thank for your help.
        Regards

        • BorisLandoni

          Check the power, the serial connection anche the library installation.
          The compiler works?

          • Martín

            The power supply is 12V 1.5 A.
            The jumper are configured as software serial.
            The library is OK and the compiler work fine, without errors.
            This shield came with a guide in italian, that I cant understand.
            How I can activate the DEBUG? and where I can see what’s happening.
            Do you have any ideas?
            Thanks!!!

          • BorisLandoni

            From the terminal you can see the debug.
            You can also enable other debug message modifing the library

          • Martín

            Hi Boris, Now I can see the debug in the serial monitor.
            I tried example 3, from call examples, and works very good.
            Thanks for your help.
            Best regards

        • Murad Hijjawe

          How to program the arduino uno with gsm/gprs sim900A which I am connecting the following sensors to them :
          1- tech sensor
          2- temp. sensor
          3-co2 sensor
          4-pulse sensor
          please ?

  • benzon sunday

    Hello, I’m a student and currently building my design project. I want to ask if i can use AT commands while using the library?. For example i want to check the battery level, I want to issue AT command to the SIM908 : gsm.println(“AT+CBC”). Is this possible? thank you. This post is very helpful, i’ve learned a lot.

    • BorisLandoni

      Hi, yes of course, in the examples you can find a sketch to do that

  • Julia Pérez del Río

    Hi, Boris
    Firstly, I wanted to congratulate you on your wonderful posts, they are very clear and easy to follow!
    Secondly, I wanted to ask you a few questions. I have a customer who wanted to make voice calls from the location of its installation, in case an alarm happened. So I don’t need the ability to make a lost call, but to be able to perform a real conversation. I understand that with the GSM/GPRS & GPS Shield and the SIM900 or SIM908 it’s possible, right?
    The Arduino can be powered to the installation’s power, but in case of power failure, they have to be able to make the phone calls, so it would be necessary to have the ability to be powered through an external battery. I understood through your post that this can only be done with the SIM908, did I get it right?
    And lastly, I read that the GSM/GPRS & GPS Shield is Arduino Duemilanove, UNO and MEGA compatible. Could you make a complete list of the compatible devices? Just to be able to choose the best one according to the installation’s requirements.

    Thank you so much in advance!

    • BorisLandoni

      Hi,
      With both SIM900 and SIM908 you can perform audio comunication, but only SIM908 includes can manage the battery.
      You can add an external battery to the shield but not controlled by SIM90x.
      The shield can be used with UNO, 2009, mega. We tested these devices.

      • Julia Pérez del Río

        Great, thanks for your answer! I was thinking of buying the 1A lithium battery charging module with a Polymeter Lithium Ion Battery. I understand that this can only be done with the SIM908, right?
        But if I power my Arduino with the 1A lithium battery charging module and then the shiedl through the Arduino? Would I be able to use the SIM900 then?

  • Bhanu teja

    Hey, I brought Sim900 module from local store. Trying to use your library with MEGA, Changed library for MEGA’s compatibility but no Response,
    Connecting it to pins 2 & 3 of mega and also to 4 & 5

    Getting this error:

    DB:NO RESP

    DB:NO RESP

    Please help!!

    • BorisLandoni

      Are you using our shield?

    • DeanSaunders

      I had the same problem. I solved it with more volt (9v), and less serial speed (9600)

  • Gordon

    Hi Boris

    I have the GPRS Shield V2.0 and the Intel Galileo Board, I need to receive an sms to

    my GPRS Shield and be able to recognize the number of the sender and the body of

    the message.

    How can I do it?

    I tried to use the sotwareserial but it doesn’t work on Galileo.

  • Carvelle Smith

    Boris, Please Help, bought the Arduino UNO R3 SIM908 and the GSM/GPRS and GPS shield a month ago. But now we can’t even get Exmaple 2 on your demonstration to work. when we send an sms for the 1st time, it turns on the Lamp, but when we try to send LEDOFF, the arduino freezes and prints out this junk on the serial monitor:

    ATT: OK

    RIC: ààààààðààààààðàààààààààààðààààààðààààààààààðàààààààààààðààààààààðàààààààààðàààààààààààààààààððààààààààààðààààààðàààààààààààðààààààðààààààààààðàààààààààààðààààààààðààààààààðààààààààààààààààààðààààààààà

    when we doing the test, both the USB and external 12VDC are plugged in. What are we doing wrong, Please help

    • BorisLandoni

      Hi, Are you using our shield?
      The power supply?

  • Hi,
    If a message is sent to a GSM module interfaced with a micro-controller through UART, can the information about the message (text, number) be read on the UART lines? Is it possible to wake the MCU after receiving any message?

    • BorisLandoni

      There is a function to get the Sender and the Message.
      You have to call this function

  • thank you for share!

  • thanks for share!

  • nice articles

  • thank you for share!

  • thanks for share!

  • good articles

  • nice articles

  • thank you for share!

  • Chathuranga

    Hi.. an example code on the library gives this error ” avrdude: stk500_getsync(): not in sync: resp=0x00 ”

    what is this about.. please help me…

    • BorisLandoni

      This is a comunication problem. Not due to library

    • Siddharth

      Disconnect your gsm module with arduino and then upload the code.

  • Adrian Sima

    Hello Boris,

    Problem:

    I can not use the shield, neither the small breakout to send an SMS.

    Description:

    I have Arduino UNO.

    I have purchased http://www.open-electronics.org/small-breakout-for-sim900-gsm-module/ and

    the shield that works with this breakout.

    I tried the library you provide but it keeps on reseting, which is a know issue due to

    insuficient memory capacity.

    The next thing I tried is to open up a software serial communication using this code:

    #include

    SoftwareSerial SIM900(2, 3);

    void setup()

    {

    SIM900.begin(19200);

    SIM900power();

    delay(20000); // give time to log on to network.

    }

    void SIM900power()

    // software equivalent of pressing the GSM shield “power” button

    {

    digitalWrite(9, HIGH);

    delay(1000);

    digitalWrite(9, LOW);

    delay(5000);

    }

    void sendSMS()

    {

    SIM900.print(“AT+CMGF=1r”); // AT command to send SMS message

    delay(100);

    SIM900.println(“AT + CMGS = “+4xxxxxxxxx””); // recipient’s mobile number, in international format

    delay(100);

    SIM900.println(“Hello, world. This is a text message from an Arduino Uno.”); // message to send

    delay(100);

    SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26

    delay(100);

    SIM900.println();

    delay(5000); // give module time to send SMS

    SIM900power(); // turn off module

    }

    void loop()

    {

    sendSMS();

    do {} while (1);

    }

    I checked the power on the shield and on the small breakout board and it is OK, 4.4 V.

    Also I checked D3 from Arduino with an oscilloscope and everything looks fine.

    I checked the RX pin from SIM900 connector on the shield and also it looks fine ( half voltage compared with D3 ).

    The green led on the small break-out blinks for a while ( 1Hz ).

    But the SIM900 processor doesn’t respons in any way. No waveform on D2. No SMS :).

    Do you have any idea what is going on?

    Thank you,

    Adrian Sima

    • BorisLandoni

      And the current of the power supply?
      You need >1A

  • Enrique Ramirez

    Hello Boris, please how I can pass the gsm.SimpleRead() to an string variable. I want display this value on lcd.

  • Velt

    Hello Boris, I’ve tried your code on example2, it compiled successfully but nothing was shown in the serial monitor…can you please guide me, Im new in this programming and Id be greatful if you help me, thank you in advance

  • Velt

    Ive tried and tried but nothing is shown in the serial monitor, im using your code on example2

    • BorisLandoni

      Other examples works?

  • samrat

    hi guys i m making my semester project fingerprint and gsm lock it is not working properly finger print works great but mu gsm in put is not working nice once i start the audrino. Gsm works nice after that when program runs another time it wont work can any one tell me how to check conditions again and again and plz dont say that us if else condition

  • Tor Ocsalev

    Why am I getting this? right pin allocations and right volts and amperes. At first I used the readSMS commad and I did not get this from my serial monitor. It was able to go status=ready but keeps on complaining that I should use the GetSMS. When I used the GetSMS, this is what I got. WHY?

    GSM Shield testing.
    DB:NO RESP
    DB:NO RESP
    DB:NO RESP
    Trying to force the baud-rate to 9600

    1200
    2400
    4800
    9600
    19200
    38400
    57600
    115200
    ERROR: SIM900 doesn’t answer. Check power and serial pins in GSM.cpp

    status=IDLE

    • BorisLandoni

      Power supply?

      • Siddharth

        Hi,

        I am getting the same serial output.
        The power is correct.
        Also, to change the pins in GSM.cpp, I opened that file in dev c++ and changed the pins and saved it.

        Is that the right way to do it?

        Regards

        • Tom

          Hi,

          I got the same output too.
          I’ve followed every single steps with the help of youtube videos, but still no luck.
          Btw, i can use adruino mega without a problem.
          But my project need to use arduino uno instead.
          any help will be much appreciated.

          Thanks

          • BorisLandoni

            Sorry for my late.
            With Mega it works?
            For uno check the setting beacuse Mega use the Serial Hardware and UNO the soft serial.
            Also I suggest you to use the softserial from the distribution, not from the Arduino IDE

      • eva

        Hi,

        Me too got the some output. i use arduino uno.
        however, i didnt face any problem when i use arduino mega.
        i followed all the steps provided. i use 9V/2A adapter.

        looking forward for you kind help..thanks

  • Abhimanyu Muraleedhara Warrier

    pls help me..my project is access control system,if un authorized entry is detected(by RFID & PIC),i just want to send a sms from SIM900A. how can i do it ???

    • Nazmul Hasan Pias

      you can use this function to send sms , its simple . you need to connect your gsm modem with arduino via TX and RX pin or you can also use software Serial library for doing this .

      void send_sms( char *m , char *cm )

      {

      Serial.println(cm);

      delay(300);

      Serial.println(m);

      Serial.write(26);

      delay(300);

      }

  • Dan G.

    Hi,

    I uploaded GSM_GPRSLibrary_SMS.ino on my Arduino Uno.

    I have an issue, after module is ready (status=READY), I receive in continuous mode (in serial monitor), the following lines:

    This method is deprecated! Please use GetSMS in the SMS class.
    ATT: +CMGL
    RIC:
    OK

    And I’m not able to send any other commands. Any Idea?

    The GPS library is working well!

  • Vineeth Cherupalath Illam

    Can Any one post the MikroC code for sim900a with pic16f877a to send message and recieve msg???
    kindly help

  • Rahul Maheshwari

    hello, my question is through any at command send sms to all in which number stored in sim memory

  • Siddharth

    Hi,

    I tried using the code that you have posted but got the following error –

    sketch_apr07a.cpp.o: In function `__static_initialization_and_destruction_0′:

    /Streaming.h:27: undefined reference to `LOG::LOG(int)’

    sketch_apr07a.cpp.o: In function `loop’:

    C:UsersnishantAppDataLocalTempbuild3685541356291295312.tmp/sketch_apr07a.cpp:70: undefined reference to `gsm’

    C:UsersnishantAppDataLocalTempbuild3685541356291295312.tmp/sketch_apr07a.cpp:70: undefined reference to `gsm’

    C:UsersnishantAppDataLocalTempbuild3685541356291295312.tmp/sketch_apr07a.cpp:70: undefined reference to `SIMCOM900::read()’

    sketch_apr07a.cpp.o: In function `setup’:

    C:UsersnishantAppDataLocalTempbuild3685541356291295312.tmp/sketch_apr07a.cpp:40: undefined reference to `gsm’

    C:UsersnishantAppDataLocalTempbuild3685541356291295312.tmp/sketch_apr07a.cpp:40: undefined reference to `gsm’

    C:UsersnishantAppDataLocalTempbuild3685541356291295312.tmp/sketch_apr07a.cpp:40: undefined reference to `GSM::begin(long)’

    C:UsersnishantAppDataLocalTempbuild3685541356291295312.tmp/sketch_apr07a.cpp:52: undefined reference to `InetGSM::attachGPRS(char*, char*, char*)’

    C:UsersnishantAppDataLocalTempbuild3685541356291295312.tmp/sketch_apr07a.cpp:60: undefined reference to `InetGSM::httpGET(char const*, int, char const*, char*, int)’

    Can you please help me out?

    Thanking you

  • M Hilmi Shah

    hi,,i don’t know what to say..there are these errors when i’m compiling the example..what should i do?? 🙁

  • Murad Hijjawe

    How to program the arduino uno with gsm/gprs sim900A which I am connecting the following sensors to them :
    1- tech sensor
    2- temp. sensor
    3-co2 sensor
    4-pulse sensor
    please ?

  • mehdi

    I try with example 2 but when I send an sms to the module sim900 I only receive in serial monitoring consul 0 over and over…….why I can not receive sms with that …..other function is perfect

  • Deepak CG

    Trying to force the baud-rate to 9600

    ERROR: SIM900 doesn’t answer. Check power and serial pins in GSM.cpp

    status=IDLE

    why the serial monitor gives this

    • Michael Kimollo

      The most possible cause would be RX and TX pin serial pin configurations in GSM.cpp,

      If you are using UNO, try to change these two line from GSM.cpp

      #define _GSM_TXPIN_ 2 ——-> #define _GSM_TXPIN_ 7

      #define _GSM_RXPIN_ 3 ——–> #define _GSM_RXPIN_ 8

      Then tell me how it responds!!

  • wooja kurosaki

    good day sir! i tried to display the text that the GSM shield sends out on the serial monitor. the output was this

    +CMT: “+639XXXXXXXX”,””,”16/03/02,8:31:09:+32″
    hello world

    what does +32 mean? and where is it from?

  • franck Moussounda

    Hi! i want to send a int data with sms gsm shield SIm900. i send the first message but i don’t send the value with itoa function; please could you help me

    #include “SIM900.h”
    #include “SoftwareSerial.h”
    #include “sms.h”
    SMSGSM sms;
    #include “call.h”
    CallGSM call;
    #include “GSM.h”

    int numdata;
    boolean started=false;
    char smsbuffer[160];
    char n[20];
    char sms_position;
    char phone_number[20];
    char sms_text[600];
    int i;

    char P1_apres_cpr_str [6];
    char P2_apres_secheur_str[6];
    char P3_apres_filtre_str[6];

    int analogPin5=A0;
    int analogPin6=A1;
    int analogPin7=A5;

    int analogValue5=0;
    int analogValue6=0;
    int analogValue7=0;

    int P1_apres_cpr=0;
    int P2_apres_secheur=0;
    int P3_apres_filtre=0;

    int voltageP1=0;
    int voltageP2=0;
    int voltageP3=0;

    unsigned long previousTime=0;
    unsigned long interval1=140000;
    unsigned long interval2=75000;
    unsigned long interval3=250000;
    unsigned long interval4=195000;

    void setup()
    {

    Serial.begin(9600);
    Serial.begin( 9600);
    Serial.println(“GSM Shield testing.”);
    if (gsm.begin(9600)){
    Serial.println(“nstatus=READY”);
    started=true;
    }
    else {Serial.println(“nstatus=IDLE”);}

    }

    void loop()
    {
    analogValue5=analogRead(analogPin5);
    int g1=analogValue5+20;
    int g2=analogValue5-20;
    int g=(g1+g2)/2;
    voltageP1=((g*5)/1024);
    P1_apres_cpr=(2.83*voltageP1);
    // Serial.print(“analogValue5:”);
    // Serial.println(analogValue5);
    //
    // Serial.print(“voltageP1: “);
    // Serial.print(voltageP1);
    // Serial.println(” V”);
    //
    Serial.print(“P1_apres_cpr: “);
    Serial.print(P1_apres_cpr);
    Serial.println(” bar”);

    unsigned long currentime=millis();
    Serial.print(“currentime:”);
    Serial.println(currentime);
    delay(1000);

    if (( P2_apres_secheur>6 && P3_apres_filtre>6)&& (P1_apres_cpr>0 && P1_apres_cpr=interval2)&& ((P1_apres_cpr=3)||(P1_apres_cpr=4)||(P1_apres_cpr=5)||(P1_apres_cpr=6)||(P1_apres_cpr=7)))
    { if(started){

    if(sms.SendSMS(“+3362331XXXX”, “Degradation de performance de l’UPA (blocs vis ou le niveau d’huile), intervenez le plus tot possible (moins de 7 jours)”))
    {

    Serial.println(“nSMS sent OK”);}
    }
    else
    { Serial.println(“nError sending SMS.”);}

    Serial.println(“Degradation de performance de l’UPA (blocs vis ou le niveau d’huile), intervenez le plus tot possible (moins de 7 jours)”);
    previousTime = currentime;
    }
    else if ((((unsigned long)(currentime-previousTime))>=interval1)&& ((P1_apres_cpr=8)||(P1_apres_cpr=9)))
    {if(started){ if (sms.SendSMS(“+3362331XXXX”, “Degradation de performance de l’UPA (blocs vis ou le niveau d’huile), vous maximum 2 semaines pour intervenir)”))
    { Serial.println(“nSMS sent OK”);
    }
    else
    { Serial.println(“nError sending SMS.”);}
    }
    Serial.println(“Degradation de performance de l’UPA (blocs vis ou le niveau d’huile), vous maximum 2 semaines pour intervenir”);
    previousTime = currentime; }
    else { Serial.println(“Ok”);}
    }
    // else if (( P2_apres_secheur<7.5 && P3_apres_filtre0&& P1_apres_cpr<=9.5 ))
    else if (( P2_apres_secheur<6 && P3_apres_filtre0 && P1_apres_cpr=interval3) && ((P1_apres_cpr=8)||(P1_apres_cpr=9)))
    {if(started){

    if (sms.SendSMS(“+3362331XXXX”, “Degradation de performance de l’UPA (blocs vis ou le niveau d’huile), vous avez maximum 2 semaines pour intervenir”))
    {
    Serial.println(“nSMS sent OK”);
    }
    else
    { Serial.println(“nError sending SMS.”);}
    }
    Serial.println(“Degradation de performance de l’UPA (blocs vis ou le niveau d’huile), vous avez maximum 2 semaines pour intervenir”);
    previousTime = currentime; }
    else if ((((unsigned long)(currentime-previousTime))>=interval4) && ((P1_apres_cpr=4)||(P1_apres_cpr=5)||(P1_apres_cpr=3)||(P1_apres_cpr=6)||(P1_apres_cpr=7)))
    {if(started){
    if (sms.SendSMS(“+3362331XXXX”, “Degradation de performance de l’UPA (blocs vis ou le niveau d’huile), intervenez le plus tot possible (moins de 7 jours)”))
    { analogValue5=analogRead(analogPin5);
    float g1=analogValue5+20;
    float g2=analogValue5-20;
    float g=(g1+g2)/2;
    voltageP1=((g*5)/1024);
    P1_apres_cpr=(2.83*voltageP1);
    itoa(P1_apres_cpr, P1_apres_cpr_str, 10);
    Serial.println(P1_apres_cpr_str);
    sms.SendSMS(phone_number,P1_apres_cpr_str);
    Serial.println(“nSMS sent OK”);
    }
    else
    { Serial.println(“nError sending SMS.”);}
    }
    Serial.println(“Degradation de performance de l’UPA (blocs vis ou le niveau d’huile), intervenez le plus tot possible (moins de 7 jours)”);
    previousTime = currentime; }
    else { Serial.println(“Ok”);}
    }}

  • franck Moussounda

    Hi!, so i want to send to multiple receiver. It’s possible to send in same time the same sms to multple receivers?

  • franck Moussounda

    How i can send to multiple receivers in the same time?

    • Bo Herrmannsen

      sms.SendSMS(number1,message);
      sms.SendSMS(number2,message);
      ……

      you get the idea…. just change the number you want to send to

  • Ronnel

    Hi sir Good Day! im having a difficulty on the code that you have provided above.. it says…(picture below).. i have used the library from https://github.com/MarcoMartines/GSM-GPRS-GPS-Shield
    hoping to get your reply

    • Ronnel

      i have used your example 2 bdw

      • Bo Herrmannsen

        arduino ide has a GSM lib and you need to remove that one first

        this is just a guess 😀

  • Muhammad Usman Khan

    where is the Library sms.h. means from where to download?

  • Pingback: دریافت sms()

  • Bo Herrmannsen

    Hi

    Got the shield and want to build a remote control with it

    i use example 3 to start with and i wonder what the purpose of this line is:

    char number[]=”3921234567″;

    the sketch use pos 8 to 10 to auth what numbers are allowed

    so why the need to supply the sketch with a phone number

  • Bo Herrmannsen

    stat=sms.GetAuthorizedSMS((int)pos,number,message,180,8,10);

    that one gives the error:

    no matching function for call to ‘SMSGSM::GetAuthorizedSMS(int, char [11], char [180], int, int, int)

    taken from example 3