How to Interface GSM Module to Arduino-Send and Receive SMS

jojo August 11, 2018 171 Comments

In this article, we are going to see how to interface GSM Module to Arduino. There are different kinds of GSM modules available in market. We are using the most popular module based on Simcom SIM900 and Arduino Uno for this tutorial. Interfacing a GSM module to Arduino is pretty simple. You only need to make 3 connections between the gsm module and arduino. So lets get to business!

A GSM Module is basically a GSM Modem  (like SIM 900) connected to a PCB with different types of output taken from the board – say TTL Output (for Arduino, 8051 and other microcontrollers) and RS232 Output to interface directly with a PC (personal computer). The board will also have pins or provisions to attach mic and speaker, to take out +5V or other values of power and ground connections. These type of provisions vary with different modules.

Lots of varieties of GSM modem and GSM Modules are available in the market to choose from. For our project of connecting a gsm modem or module to arduino and hence send and receive sms using arduino – its always good to choose an arduino compatible GSM Module – that is a GSM module with TTL Output provisions.

GSM Module – Buyers Guide – are you looking to buy a GSM module? There are a handful of product variants for GSM module – like SIM900, SIM300, SIM800 etc. We have created this buyers guide to help you select the right GSM module for your project needs.

Notes on GSM Module

1. We use SIM900 GSM Module – This means the module supports communication in 900MHz band. We are from India and most of the mobile network providers in this country operate in the 900Mhz band. If you are from another country, you have to check the mobile network band in your area. A majority of United States mobile networks operate in 850Mhz band (the band is either 850Mhz or 1900Mhz). Canada operates primarily on 1900 Mhz band. Please read this wiki entry on GSM Frequency Bands around the World.

2. Check the power requirements of GSM module – GSM modules are manufactured by different companies. They all have different input power supply specs. You need to double check your GSM modules power requirements. In this tutorial, our gsm module requires a 12 volts input. So we feed it using a 12V,1A DC power supply. I have seen gsm modules which require 15 volts and some other types which needs only 5 volts input. They differ with manufacturers. If you are having a 5V module, you can power it directly from Arduino’s 5V out.

Note:- GSM Modules are manufactured by connecting a particular GSM modem to a PCB and then giving provisions for RS232 outputs, TTL outputs, Mic and Speaker interfacing provisions etc. The most popular modem under use is SIM 900 gsm modem from manufacturer SIMCom. They also manufacture GSM Modems in bands 850, 300 and other frequency bands.

3. Check for TTL Output Pins in the module – You can feed the data from gsm module directly to Arduino only if the module is enabled with TTL output pins. Otherwise you have to convert the RS232 data to TTL using MAX232 IC and feed it to Arduino. Most of the gsm modules in market are equipped with TTL output pins. Just ensure you are buying the right one.

So that’s all about the gsm module basics. Now lets power it up!

Arduino to GSM Modem - Sim 900 Modem

 

Booting the GSM Module!

1. Insert the SIM card to GSM module and lock it.

2. Connect the adapter to GSM module and turn it ON!

3. Now wait for some time (say 1 minute) and see the blinking rate of ‘status LED’  or ‘network LED’ (GSM module will take some time to establish connection with mobile network)

4. Once the connection is established successfully, the status/network LED will blink continuously every 3 seconds. You may try making a call to the mobile number of the sim card inside GSM module. If you hear a ring back, the gsm module has successfully established network connection.

Okay! Now let’s see how to connect a gsm module to Arduino!

Connecting GSM Module to Arduino

There are two ways of connecting GSM module to arduino. In any case, the communication between Arduino and GSM module is serial. So we are supposed to use serial pins of Arduino (Rx and Tx). So if you are going with this method, you may connect the Tx pin of GSM module to Rx pin of Arduino and Rx pin of GSM module to Tx pin of Arduino. You read it right ? GSM Tx –> Arduino Rx and GSM Rx –> Arduino Tx. Now connect the ground pin of arduino to ground pin of gsm module! So that’s all! You made 3 connections and the wiring is over! Now you can load different programs to communicate with gsm module and make it work.

Note:- The problem with this connection is that, while programming Arduino uses serial ports to load program from the Arduino IDE. If these pins are used in wiring,  the program will not be loaded successfully to Arduino. So you have to disconnect wiring in Rx and Tx each time you burn the program to arduino. Once the program is loaded successfully, you can reconnect these pins and have the system working!

To avoid this difficulty, I am using an alternate method in which two digital pins of arduino are used for serial communication. We need to select two PWM enabled pins of arduino for this method. So I choose pins 9 and 10 (which are PWM enabled pins). This method is made possible with the SoftwareSerial Library of Ardunio. SoftwareSerial is a library of Arduino which enables serial data communication through other digital pins of Arduino. The library replicates hardware functions and handles the task of serial communication.

I hope you understood so far!  Lets get to the circuit diagram! So given below is the circuit diagram to connect gsm module to arduino – and hence use the circuit to send sms and receive sms using arduino and gsm modem.

GSM Mdule to Arduino - Circuit

Make the connections as shown! Now lets get to the coding part. The program has two objectives as described below:-

1) Send SMS using Arduino and GSM Module – to a specified mobile number inside the program

2) Receive SMS using Arduino and GSM Module – to the SIM card loaded in the GSM Module.

The Program
 #include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10);

void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  delay(100);
}


void loop()
{
  if (Serial.available()>0)
   switch(Serial.read())
  {
    case 's':
      SendMessage();
      break;
    case 'r':
      RecieveMessage();
      break;
  }

 if (mySerial.available()>0)
   Serial.write(mySerial.read());
}


 void SendMessage()
{
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number
  delay(1000);
  mySerial.println("I am SMS from GSM Module");// The SMS text you want to send
  delay(100);
   mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}


 void RecieveMessage()
{
  mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
 }
 

so that’s the program/code to make arduino send sms and receive sms using gsm module! Let’s get to explanation of program!

The Program Explanation

We begin by including SoftwareSerial library into the program.  In the next line, we create a constructor of SoftwareSerial with name mySerial and we pass the digital pin numbers as parameters. The actual format is like SoftwareSerial mySerial (Rx, Tx);

So in our code, pin number 9 will act as Rx of Arduino and 10 will act as Tx of Arduino.  Lets get to the configuration part of program inside setup. The first task is to set baud rates of SoftwareSerial library to communicate with GSM module. We achieve this by invoking mySerial.begin function. Our second task is to set the baud rate of Arduino IDE’s Serial Monitor. We do this by invoking Serial.begin function. Both should be set at the same baud rate and we use 9600 bits/second here in our tutorial.  Configuration part is over with setting baud rates and its good to give a small delay of 100 milli seconds.

Now lets get to the actual program inside loop(). To make things simpler, I have developed a user input based program. The program seeks user input via serial monitor of Arduino. If the input is ‘s’ the program will invoke function to send an sms from GSM module. If the user input is ‘r’, the program will invoke the function to receive a live SMS from GSM module and display it on serial monitor of Arduino. The whole program is as simple as that!

Serial.available() – checks for any data coming through serial port of arduino. The function returns the number of bytes available to read from serial buffer. If there is no data available, it returns a -1 (value less than zero).

Serial.read() – Reads all the data available on serial buffer (or incoming serial data if put otherwise). Returns the first byte of incoming serial data.

mySerial.available() – checks for any data coming from GSM module through the SoftwareSerial pins 9 and 10. Returns the number of bytes available to read from software serial port. Returns a -1 if no data is available to read.

mySerial.read() – Reads the incoming data through software serial port.

Serial.write() – Prints data to serial monitor of arduino. So the function Serial.write(mySerial.read()) – prints the data collected from software serial port to serial monitor of arduino.

Lets get the functions SendMessage()  and RecieveMessage()

These are the functions in which we actually send commands to GSM module from Arduino. These commands to communicate with GSM module are called AT Commands. There are different commands to perform different tasks using the GSM module. You can read complete AT Commands Library to understand all that is possible with GSM module.

SendMessage() – is the function we created in our arduino sketch to send an SMS. To send an SMS, we should set our GSM module to Text mode first. This is achieved by sending an AT Command “AT+CMGF=1”  We send this command by writing this to SoftwareSerial port. To achieve this we use the mySerial.println() function. mySerial.println writes data to software serial port (the Tx pin of our Software Serial – that is pin 10) and this will be captured by GSM module (through its Rx pin). After setting the GSM module to Text mode, we should the the mobile number to which we shall send the SMS. This is achieved with AT command “AT+CMGS=\”+91xxxxxxxxxx\”\r” – where you may replace all x with the mobile number.

In next step, we should send the actual content of SMS. The end of SMS content is identified with CTRL+Z symbol. The ASCII value of this CTRL+Z is 26. So we send a char(26) to GSM module using the line mySerial.println((char)26); Each and every AT command may be followed by 1 second delay. We must give some time for GSM module to respond properly. Once these commands are send to GSM module, you shall receive an SMS in the set mobile number.

RecieveMessage() – is the function to receive an SMS (a live SMS). The AT command to receive a live SMS is “AT+CNMI=2,2,0,0,0” – we just need to send this command to GSM module and apply a 1 second delay. Once you send this command, try sending an SMS to the SIM card number put inside GSM module. You will see the SMS you had sent displayed on your Arduino serial monitor.

There are different AT commands for different tasks. If you want to read all SMS’s stored in your SIM card, send the following AT Command to gsm module – “AT+CMGL=\”ALL\”\r”

Okay! That’s all and you are done. And you have learnt how to use arduino to send sms and receive sms message with example code.

I shall summarize this tutorial on how to send/receive a text message using arduino and gsm module with the following notes:-

AT Commands to Send SMS using Arduino and GSM Module
AT+CMGF=1 // Set the GSM module in text mode
AT+CMGS=\"+YYxxxxxxxxxx\"\r // Input the mobile number| YY is country code
“the message” with stopping character (char)26 // ASCII of ctrl+z
AT Commands to Receive SMS using Arduino and GSM Module
AT+CMGF=1 // Set the GSM Module in text mode
AT+CNMI=2,2,0,0,0 // AT Command to receive live sms

Read the AT commands library and start playing with your GSM module and Arduino! If you have any doubts please ask in comments.

So that’s all about interfacing GSM module to Arduino. If you’ve any doubts, feel free to comment.

Comments
  • Tushar
    November 7, 2018

    I have used the code as per ur guide but I am not getting any output at the serial monitor

  • shashank hegde
    June 7, 2018

    I have this requirement. I need to collect data from RS232 of a certain equipment and has to be sent to mobile. If i send some command to the GSM module it has to read data from RS232 and send me back the data. Is it possible ?if so can you just give a hint of how to proceed. Interfacing of RS232 and GSM module to be done as well for that.

  • Edwin
    April 30, 2018

    Hi, pls i’ve been working on a sim800 project and been having some issues, would be glad if you could help out. The sim module sends sms normally using the example code, but for my project, it is meant to send a message to a number when the heart rate sensor detects an abnormality in the heart beat. the serial monitor shows the reading but when it is meant to send the message, it shows error CMGF. Pls i need help urgently.

  • adnan
    March 23, 2018

    sir i want to use this code to send a message,its a part of my drunk driver detection project.My target is to send a sms to registered number that the driver is drunk.Do i have to change anything from this code?IF i want to register a number number how will I do that.Please i need your help

  • Akshay
    March 22, 2018

    Hiiii sir,
    I am Akshay from India…….we tried ur code..but when we want to send sms we go through ‘s’ case……then on my mobile its shows <>
    whats the problem sir……..
    While msgs of receiving successfully done……
    Connections are also correct…….
    Whats the problem?????
    Plzz convey solution as soon as possible

  • ken
    February 3, 2018

    Hi sir good day. I would like to ask for help. I was able to send text messages using the above code. But my arduino uno module resets after the mySerial.println((char)26); line, prompting other codes after that line not executed. Please kindly help assess and advise.Thanks in advance.

  • ken
    February 3, 2018

    Hi sir good day. I would like to ask for help. I was able to send text messages using the above code but my Arduino Uno module resets after executing the line mySerial.println((char)26); prompting the code to reset as well. The following codes after that line resulted to not being executed. Please kindly help assess. Thank you in advance.

  • Banjing
    January 7, 2018

    Hi, how to do a code that it will not be needing user input. If someone send a text message to the module it will be automatically displayed on the serial monitor? Thanks a lot. And is someone will call, it will automatically hangup and send a message like “This is a machine”

  • Shinn
    December 18, 2017

    Sir how about changing the number w/out touching the code or shall we say it has UI (application) that can change the number into a new one. Is it possible? Do you have any similar project w/ that? Badly need your thoughts for our project. 🙁

  • December 11, 2017

    hello sir i am trying to make 360 servo motor to run continously using GSM module can you help me for that program?

  • sachin
    December 10, 2017

    hii,

    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

    but i want display only “hello world” and skip other content then what should i do ?

    • sachin
      December 10, 2017

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

      hello world

      I want to display only “hello world” and skip this >>>>

      “+CMT: “+639XXXXXXXX”,””,”16/03/02,8:31:09:+32″”
      what code should i use???

  • Boeurn Beng
    November 29, 2017

    if i live in Cambodia, me should use how many gsm frequency rang ?

  • Joshboye
    November 28, 2017

    Sir,
    I want to send this message to multiple recipients … can you help me in the code?

  • vivek
    November 28, 2017

    if the same message has to be sent for every 10 minutes what has to be done?

  • rose
    November 16, 2017

    will the same work for SIM800A?

  • sai charan
    November 14, 2017

    hello sir i want help for a program the led will turn on when the recieved message is ON,then led will turn off when the recieved message is OFF, please help me for this program.

  • nitish kumar
    November 13, 2017

    Good day sir,
    Can you send me email of takudzwa muswaka who had same doubt as mine. I want to contact with him for this problem. He contacted you at 16 Feb 2016.
    Please sir help me for my project pls pls pls help

    problem was
    am trying to make a system that responds to any user who sends an sms command to the sim900 module using the exact step that you had provided ,but using mySerial.println(“AT+CMGS=\”+91xxxxxxxxxx\”\r”); will only allow the system to send a response to one number , how can i implement a system that responds to multiple phone numbers wich send a command to the sim900 or a function that Retrieves the phone number an from an incoming SMS message and stores it in a named array , just like the function “remoteNumber()” wich is present in the aduino “GSM.h” library .

  • sai charan
    November 12, 2017

    hello sir i am working on the program to turn on the led when the recieved message is ON,and turn off the led when the recieved message is OFF.but its faling every time i tried please help me

  • Kapila
    November 11, 2017

    The article is very useful with all details about connections and software.
    I have followed exactly still My sim 900 a is not sending messages. kindly help where
    I have gone wrong?

  • deepak
    November 6, 2017

    how can i continuously receive sms for gsm module (sim900) on my arduino uno and display it as output on led matrix

  • Sohel
    October 28, 2017

    Hi sir
    I am making a project in which the gsm operates the relay and by the reading of the soil moisture output the relay is turned off would you help me with the program

    • Sohel
      October 28, 2017

      Hi sir
      I am making a project in which the gsm is use to turn on the relay and the output reading of soil moisture the relay should turn off would you help me with the program

  • Lince
    October 25, 2017

    Hi sir,
    I’m doing a project using arduino,gsm and gps.i have programmed the arduino.
    But i’m confused how to include lacation information(lattitude & longitude) information in my sms along with AT command.Can you help me out please..

  • Uday
    October 24, 2017

    Sir,your way of teaching is very nice. I tried to call to the SIM inside GSM module ,I got ring back.so,its working perfectly but when I compiled, got an error (stray/242).so, could you please recorrect the code and send.

  • October 18, 2017

    I am not receiving sms to my gsm module number it read the message which we are sending so pls me,thank u

  • Vikrant Patil
    October 14, 2017

    Hello,
    I am not able to receive sms on GSM module, although I am able to send a message.
    When I tried on Putty, I was able to receive message from GSM modem.

    Here is the code which I used.

    #include

    SoftwareSerial mySerial(6,7);

    void setup()
    {
    mySerial.begin(9600); // Setting the baud rate of GSM Module
    Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
    delay(100);
    }

    void loop()
    {
    if (Serial.available()>0)
    switch(Serial.read())
    {
    case ‘s’:
    SendMessage();
    break;
    case ‘r’:
    RecieveMessage();
    break;
    }

    if (mySerial.available()>0)
    Serial.write(mySerial.read());
    }

    void SendMessage()
    {
    mySerial.println(“AT+CMGF=1”); //Sets the GSM Module in Text Mode
    delay(1000); // Delay of 1000 milli seconds or 1 second
    mySerial.println(“AT+CMGS=\”+919845340671\”\r”); // Replace x with mobile number
    delay(1000);
    mySerial.println(“I am SMS from GSM Module”);// The SMS text you want to send
    delay(100);
    mySerial.println((char)26);// ASCII code of CTRL+Z
    delay(1000);
    }

    void RecieveMessage()
    {
    mySerial.println(“AT+CMGF=1”); //Sets the GSM Module in Text Mode
    mySerial.println(“AT+CNMI=2,2,0,0,0”); // AT Command to receive a live SMS
    delay(1000);
    }

  • sandeep
    September 16, 2017

    In your code where is gsm hearder file?

  • satyam
    September 5, 2017

    hiii there, your sms sending code works well but your sms receiving code doesn’t displaying any thing to the serial port could u help me out. thnakyou

  • Jh
    August 30, 2017

    I do have a question, hope you answer me. I am confused with the Arduino. Why do we need that if we can manipulate the GSM module (SIM 900) directly connected to the computer using AT commands?

  • Dehin Wasantha
    August 18, 2017

    i have installed my GSM module in a remote place. send me acord to automaticaly reset the gsm module when it is possible

  • Kenneth Holan
    August 17, 2017

    Hello Sir.
    First of all a thank you for your brilliant description.
    Then to my problem. I am sitting in Sweden (not the problem…) but the sim cards here are. I’ve used simcards from Telenor on several modules also the sim900 but I cannot get any connection to the GSM net??? I am sitting close to the center in Stockholm, so connection should not be an issue, besides it worked on the A6 module. The funny part is that it sometimes work on the A6, sometimes not. On the sim900 it never worked so far. This issue is driving me mad. Any suggestions. In advance thank you.

  • August 3, 2017

    sir the program given is working perfectly.
    I want a program where i can receive a immediate reply from the GSM as soon as someone send any text to the GSM SIM.plz Help me to get this program

  • August 2, 2017

    Thank u for all the above information,it all worked well for me.But now i wand my GSM to send a replay back whenever a particular message is being encountered.
    for example;Whenever i send “hello” to my GSM it should automatically replay back with “Hi”.
    Plz help me out to slove this problem.

  • Sanjida Rahman
    June 22, 2017

    I. have uploaded the cod3? What will I do next?

  • Thisara Rathnaweera
    June 11, 2017

    i get the receiving sms from gsm.but i didnt get sms from mobile phone to gsm..what is the p roblem and plz advice me

  • farooq
    June 6, 2017

    sir i need code for receiving message using gsm sim900+arduino uno
    thanks

  • naim
    June 5, 2017

    i use the code as above but nothing happen it just display s in serial monitor but does not send the message

  • RITHIK
    May 4, 2017

    can i use arduino mega in place of arduino uno

  • balaji
    May 1, 2017

    how to receive sms on lcd 16×2

  • Willy
    April 15, 2017

    Hi there. I’m using arduino uno with sim900, followed each step you mentioned, but still no results displayed. I’ve entered the serial monitor, enter s or r for messaging but nothing showed up. I can use smartphone to call the sim card in the gsm shield though. Not sure what happened. I’m new to these stuffs.

  • naresh
    April 11, 2017

    i need to get the message from gsm module when we snd message to gsm module

  • Shubham kumar
    April 10, 2017

    “”AT+CMGF=1

    OK
    ŠiêUÒåNL¢’‚¢‚²ºšþ0”

    >

    > EMERGENCY // message written in the code
    >

    +CMGS: 59

    OK
    “”

    the message is showing in the serial port but a blank message received in the given mobile no.

  • sanjeevi
    April 3, 2017

    Hi. I need to send sms for multiple users using the same program…?
    Kindly give me a solution as soon as possible

    • jojo
      April 7, 2017

      @ sanjeevi – Save mobile numbers of users into an array. Execute the AT Commands to send SMS in a loop and call mobile numbers from array via loop iteration.

  • March 24, 2017

    HI sir:
    je voudrais d’envoyer un sms via gsm SIM800L contient la température et les coordonnées GPS(latitude et longitude, la vitesse), si tu peux m’aider monsieur dans l’établissement d’un code,
    les équipements utilisés sont:
    arduino uno
    capteur de température LM35
    sim800l
    gps ne06mv2
    afficheur 16*2
    un buzzer
    si la temperature est superieur à 12°C uue sonnette d’un buzzer sera établie, si elle supérieur de 15°C une alarme via SMS sera transmis via réseau GSM.

  • Bhavesh Motiwala
    March 23, 2017

    Hello Sir,
    I want need help for doing program to getting only text contain from my sms .
    for that i have choose algorithm which is only taking a part of text contain which is in between of * and # symbol.for that i am create this code but its not getting any result.

    I am using GSM 300 module and interface done with ARDUINO UNO.

    Plz give me help for my project work

    #include
    #include
    #include

    SoftwareSerial mySerial(2, 3);
    LiquidCrystal lcd(3,4,5,6,7,8);

    int temp4=0;
    int lenth,lenth1,i=0,temp=0;

    String str=””;
    String name=””;
    String number=””;
    String datam=””;

    void setup()
    {
    lcd.begin(16,2);
    Serial.begin(9600);
    mySerial.begin(9600);
    lcd.print(“WEL COME”);
    pinMode(13,OUTPUT);
    digitalWrite(13,HIGH);
    vw_set_tx_pin(19);
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);
    delay(3000);
    Serial.println(“ATE0\r\n”);
    delay(10);
    Serial.println(“AT+CNMI=2,2,0,0,0”);
    Serial.println(“AT+CMGF=1”);
    delay(500);

    }

    void loop()
    {
    gsmmsgRead();

    }

    void gsmmsgRead()
    {
    while(temp!=0)
    {
    i=0;
    while(i<lenth)
    {
    if(str[i]=='"')
    {
    temp4++;
    }
    if(temp4==1)
    {
    for(int j=0;j<15;j++)

    {
    number+=str[i];
    i++;
    }
    temp4=2;
    }
    if(str[i]=='*')
    {
    i++;
    lcd.clear();
    while(str[i]!='#')
    {
    name+=str[i];
    lcd.print(str[i]);
    i++;
    }
    datam=str;
    }
    i++;
    }

    delay(2000);

    temp=0;
    temp4=0;
    name="";
    lenth=0;
    str="";
    number="";
    delay(1000);
    }

    serialEvent();
    delay(100);
    }

    void serialEvent()
    {
    while (Serial.available())
    {
    char inChar = (char)Serial.read();
    str+=inChar;
    lenth++;
    if (inChar == '\n')
    { temp=1;
    inChar=0;
    }
    }
    }

  • Mian Sami
    March 20, 2017

    char phone_no[]=”03117070917″;
    void setup()
    {
    Serial.begin(9600);
    delay(2000);
    Serial.println(“AT”);
    Serial.print(“ATD”);
    Serial.print(phone_no);
    Serial.println(“;”);
    delay(3000);
    Serial.println(“ATH”);

    // put your setup code here, to run once:

    }

    void loop() {
    // put your main code here, to run repeatedly:

    }

  • tushar gagerna
    March 18, 2017

    This code is not working
    #include
    #include
    #include
    SoftwareSerial Sim900Serial(9,10);
    byte buffer[64]; // buffer array for data recieve over serial port
    int count=0; // counter for buffer array
    SoftwareSerial GPS(11,12);
    TinyGPS gps;
    unsigned long fix_age;
    long lat, lon;
    float LAT, LON;
    void gpsdump(TinyGPS &gps);
    bool feedgps();
    void getGPS();
    void setup()
    {
    Sim900Serial.begin(19200); // the SIM900 baud rate
    GPS.begin(9600); // GPS module baud rate
    Serial.begin(9600); // the Serial port of Arduino baud rate.
    delay(500);
    Sim900_Inti();
    }

    void loop()
    {
    Sim900Serial.listen();
    if (Sim900Serial.available()) // If date is comming from from GSM shield)
    {
    while(Sim900Serial.available()) // reading data into char array
    {
    buffer[count ]=Sim900Serial.read(); // writing data into array
    if(count == 64)break;
    }
    Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
    Cmd_Read_Act(); //Read the ‘COMMAND’ sent to SIM900 through SMS
    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
    Sim900Serial.println(Serial.read()); // write it to the GPRS shield
    }
    void clearBufferArray() // function to clear buffer array
    {
    for (int i=0; i<count;i )
    { buffer[i];} // clear all index of array with command NULL
    }
    void Sim900_Inti(void)
    {
    Sim900Serial.println("AT+CMGF=1"); // Set GSM shield to sms mode
    Serial.println("AT+CMGF=1");
    delay(500);
    Sim900Serial.println("AT+CNMI=2,2,0,0,0");
    Serial.println("AT+CMGF=1");
    delay(500);
    }
    void Cmd_Read_Act(void) //Function reads the SMS sent to SIM900 shield.
    {
    char buffer2[64];
    for (int i=0; i<count;i )
    { buffer2[i]=char(buffer[i]);}

    if (strstr(buffer2,"GNRK")) //Comparing password entered with password stored in program
    {
    Serial.println("Password Authenticated.");
    Serial.println("Sending reply SMS. ");
    SendTextMessage();
    }

    }
    void SendTextMessage()
    {

    Sim900Serial.print("AT+CMGF=1\r"); //Sending the SMS in text mode
    delay(100);
    Sim900Serial.println("AT+CMGS = \"+919868590006\"");//The predefined phone number
    delay(100);
    Sim900Serial.println("Please wait while Module calculates position");//the content of the message
    delay(100);
    Sim900Serial.println((char)26);//the ASCII code of the ctrl z is 26
    delay(100);
    Sim900Serial.println();
    int counter=0;
    GPS.listen();

    for (;;)
    {
    long lat, lon;
    unsigned long fix_age, time, date, speed, course;
    unsigned long chars;
    unsigned short sentences, failed_checksum;
    long Latitude, Longitude;

    // retrieves /- lat/long in 100000ths of a degree
    gps.get_position(&lat, &lon, &fix_age);
    getGPS();
    Serial.print("Latitude : ");
    Serial.print(LAT/1000000,7);
    Serial.print(" :: Longitude : ");
    Serial.println(LON/1000000,7);
    if (LAT == 0 && LON == 0)
    {
    continue;
    }
    counter ;
    if (counter<30)
    {
    continue;
    }

    Sim900Serial.print("AT+CMGF=1\r"); //Sending the SMS in text mode
    delay(100);
    Sim900Serial.println("AT+CMGS = \"+919868590006\"");//The predefined phone number
    delay(100);
    Sim900Serial.print("Latitude : ");
    Sim900Serial.print(LAT/1000000,7);
    Sim900Serial.print(" :: Longitude : ");
    Sim900Serial.println(LON/1000000,7);//the content of the message
    delay(100);
    Sim900Serial.println((char)26);//the ASCII code of the ctrl z is 26
    delay(100);
    Sim900Serial.println();
    counter=0;
    break;
    }
    }

    void getGPS()
    {
    bool newdata = false;
    unsigned long start = millis();
    while (millis() – start < 1000)
    {
    if (feedgps ())
    {
    newdata = true;
    }
    }
    if (newdata)
    {
    gpsdump(gps);
    }
    }
    bool feedgps()
    {
    while (GPS.available())
    {
    if (gps.encode(GPS.read()))
    return true;
    }return 0;
    }
    void gpsdump(TinyGPS &gps)
    {
    gps.get_position(&lat, &lon);
    LAT = lat;
    LON = lon;
    {
    feedgps();
    }
    }

  • Nicky
    March 17, 2017

    Hi, all commands works….send message, receive message, send call, disconnect call
    but what the output should be displayed when the module is supposed to receive call because my serial monitor is showing ERROR for receive call command.

  • darshan
    March 15, 2017

    Can I interface single gsm module to 2 Arduino boards

  • T Yashaswini Reddy
    March 3, 2017

    Is it possible to connect the GSM to 3,2 and load the program to the arduino?

  • rushitha
    February 22, 2017

    how can i send and receive message as string?

  • Parman Josan
    February 11, 2017

    hello,
    I am making the same project but I found some trouble, my serial shows “ÿÿÿÿ” if I type “hi” on my serial monitor and also it’s not sending the message to provided number.

    plz help me

  • Himanshu Bansal
    February 8, 2017

    New to Arduino but in the field or mobile repairs, will just be asking you everything.
    I need a Uno or Uno R3?
    Gsm shield 900a(5v dc)
    Pir sensor
    And what else?
    I don’t want sms notifications. I want calling feature. And also tell me the code to stop the alarm.

    Regards
    Himanshu Bansal

  • Aloysius Teo
    February 3, 2017

    Hi, how to make the sending of msg to be automatic instead of the need to click ‘s’ and enter?

  • Aloysius Teo
    February 1, 2017

    Hi, i tried the code with SIM5320E, its not working. pls help.

    for the AT+CMGS=\”+YYxxxxxxxxxx\”\r // Input the mobile number| YY is country code,
    the mobile number is the sim card’s number on the shield or the number we want to sent the message to?

    how can i tried it out with the serial monitor?

    Thanks for ur help!!!

  • J3
    January 22, 2017

    Hey i have used arduino uno for object detection sensor. i want to receive the messege whenever there is object in front of sensor. How to put code to receive msg from gsm module which is to be interface with arduino uno. help me to put gsm code in my program.
    my code for sensor is as follows ..

    int slottwo=9;
    int slotone = 8;
    void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    pinMode(slotone, INPUT);
    pinMode(slottwo, INPUT);

    }

    void loop() {
    int slot1_val = digitalRead(slotone);
    int slot2_val = digitalRead(slottwo);

    //Serial.println(slot1_val);
    //Serial.println(slot2_val);
    delay(1000);
    int state1val = digitalRead(slotone);
    int state2val = digitalRead(slottwo);

    if((state1val == 0)&(state2val == 0))
    {Serial.println(“all slots are full”);}
    else if((state1val == 0)&(state2val == 1))
    {Serial.println(“slot2 is empty”);}
    else if((state1val == 1)&(state2val == 0))
    { Serial.println(“slot1 is empty”);}

    else if((state1val == 1)&(state2val == 1))
    {Serial.println(“all slots are empty”);}

    // put your main code here, to run repeatedly:

    }

  • January 21, 2017

    Hi!..

    Thanks for the source code…but the receive SMS part is not working…I use exactly the same code…I’m using arduino mega 2560…

  • ace rhael
    January 16, 2017

    hello, i cant get any words shown in the serial monitor, am using arduino mega. and whenever i call the number i can hear the ringback, but i dont have display from my serial monitor. please help me what to do

  • Gokul
    January 7, 2017

    Hi,
    I need to store the value sent through gsm to a variable in the arduino. What should be my coding.

  • Rajiv Shandilya
    December 22, 2016

    If find gsm monitering system of battery & load input & output Dc voltage & current with sensor how to use microcontroller board & their codings

  • W
    October 19, 2016

    hello sir, im trying to use GSM sim900A in malaysia with using the exact step that you had provide. but the GSM still does not sending any text or receive text. but when im trying to establish the network connection of GSM, i had heard the ringing. so what is the problem ? can you help sir ? its important to me. thank you????

  • Soumyak Dutta
    October 13, 2016

    It’s working!

  • Himanshu Aggarwal
    October 12, 2016

    I was trying to turn on/off led’s by sending a message to gsm modoule (sim900A+arduino uno).

    But i get stuck at the point when the gsm receives the message. It receives the first message and displays on the serial monitor but after that it doesn’t shows other msg that are being received.
    And on trying to read those messages using serial monitor manually i get different situations:

    1). Sometimes it doesn’t shows messages next to first msg.
    2). Sometimes the list of the messages suddenly appears at the same time in spite of being sent at different times.
    3). Sometimes the msg gets displayed after 5-8min of entering the command to display received msgs. And some of these msgs have no data to display.

  • vaibhav
    September 22, 2016

    how to send multiple sms at a same time

  • Avinash Baldi
    September 15, 2016

    Hello Sir,

    I want a button(keypad) connected with Aurdino to send AT commands. Please help how to do this?

  • priyanka
    September 6, 2016

    sir we tried this code,it is compiling but the message is not received by the given number.Could you please help us.thanks in advance

  • tapan
    August 13, 2016

    hello sir i am making automation system in which i have to receive message
    if message is from one particular number than i have check the number and text
    and if it match with the predefined string than i have to make any one of the pin of arduino high
    can u sir please provide the code for this i am from the mechanical department and don’t have enough programming skills

  • Marlyn
    August 5, 2016

    Can you please help us to make our gsm works well? We have a problem in sending and receiving sms. We have a lot of codes but none of them were working.
    Can you help us send codes about the said problems/? Thankyou!

  • Kuck Noel
    August 4, 2016

    I have tried several public domain arduino sketches with a SIM900 shield. The led on the shield flashes slowly showing connection established. However, I cannot send AT commands to it from my computer, and not able to send any sms messagrs to my cellphone. It worked a few months ago, but now nothing. Puzzeled about where to look. Any help would be appreciated. Thanks.

  • Richmond
    August 2, 2016

    Can someone help me? This is my code.

    #include
    #include “SIM900.h”
    #include “sms.h”
    #include
    //#include
    #include
    SMSGSM sms;
    boolean started = false;
    char buffer[160];
    char smsbuffer[160];
    char n[20];
    //LiquidCrystal lcd(4,2,3,7,8,9);
    int buttonState;
    int lastButtonState = LOW;
    long lastDebounceTime = 0;
    long debounceDelay = 50;
    boolean st = false;
    int buzzer = 12;

    void setup() {

    //lcd.begin(16, 2);
    Serial.begin(9600);
    if (gsm.begin(2400))
    {
    started = true;
    }
    if (started)
    {
    delsms();
    }
    sms.SendSMS(“+60142646978” , “Gas Sensor and GSM module activated”);

    }

    void loop() {

    //lcd.setCursor(0, 0);

    //lcd.print(“Detektor Gas SMS”);
    int val = analogRead(A0);
    val = map(val, 0, 1023, 0, 100);
    //lcd.setCursor(0,1);
    //lcd.print(“Kadar: “);
    //lcd.print(val);
    //lcd.print(“% “);

    //code using sensor detection
    if (val > 10) {
    tone(buzzer,800,500);
    delay(1000);
    st = true;
    }
    else st = false;

    if (st != lastButtonState) {
    lastDebounceTime = millis();
    }

    if ((millis() – lastDebounceTime) > debounceDelay) {

    if (st != buttonState) {
    buttonState = st;

    if (buttonState == HIGH) {
    PString str(buffer, sizeof(buffer));
    str.begin();
    str.print(“Gas Detected! Gas leakage at “);
    str.print(val);
    str.print(“%”);
    //String a=str;
    sms.SendSMS(“+60142646978”, buffer);
    }
    }
    }

    //code using sms lapor.
    lastButtonState = st;
    int pos = 0;
    if (started)
    {
    pos = sms.IsSMSPresent(SMS_ALL);
    if (pos)
    {
    sms.GetSMS(pos, n, smsbuffer, 100);
    delay(2000);
    if (!strcmp(smsbuffer, “lapor”))
    {
    PString str(buffer, sizeof(buffer));
    str.begin();
    str.print(“Rate of gas leakage currently at “);
    str.print(val);
    str.print(“%”);
    //String a=str;
    sms.SendSMS(“+60142646978”, buffer);
    }
    delsms();
    }
    }
    }

    //delete sms yang dihantar
    void delsms()
    {
    for (int i = 0; i < 10; i++)
    {
    int pos = sms.IsSMSPresent(SMS_ALL);
    if (pos != 0)
    {
    if (sms.DeleteSMS(pos) == 1) {} else {}
    }
    }
    }

    I'm using arduino uno, sim900 module, mq2 gas sensor and buzzer to create a gas sensor detector based on sms.
    I have to 2 option :
    1. The mq2 gas sensor detects and send the result via sms to the number set in the code.
    2. We can send a specific string to know the surrounding gas percentage and send the result to the specific number set in the code.

    But I want to change the second option to be auto reply to any incoming number. What should I do?

  • trivedi dilpesh
    July 21, 2016

    received signal from the GSM is how to read in ardiuno?

  • Eric Roque
    July 20, 2016

    Hello. Your code works perfectly, although I have a question. When I receive the text message, it is displayed on the serial monitor as it should. Is there any way to save that message and do with I as I wish? For example, if a text says “STOP”, I want to turn an LED off (using a relay). Thanks in advance.

  • jane
    July 19, 2016

    only the sending sms part works well but with the receiving part it doesn’t. my serial port doesnt show anything in it, its a plain blank space.

  • Navonita Sharma
    July 15, 2016

    Hi,
    Thanks for the tutorial and program. I have implemented your code but while running the program with my arduino UNO and GSM module SIM900A, no message is received in the provided mobile number. The serial monitor shows error in sending the message. Kindly suggest the possible cause for this error.

    • Raji
      May 3, 2017

      I have also implemented the above code with arduino uno & Sim 800c. Receiving part works well. But in sending part, I have received error message and the message didn’t come to my mobile. can u find the solution of above problem?

  • Siddarth Jawahar
    July 11, 2016

    Hello, your code is not working on my device. Any suggestions for elementary mistakes I may be making? I’ve connected UNO to the gsm board with rx tx and the nwk led is blinking once in 3 seconds. There doesn’t seem to be anything wrong but nothing is happeneing. what could it be./

  • Siddarth Jawahar
    July 10, 2016

    Hi. I’ve inserted the SIM card into the gsm module and the NWK lED is blinking once in 3 secs. But if I try to make a call to the number, it says “not reachable”. As specified, I’ve connected the RX TX of the gsm module to ppins 9 and 10 on the arduino uno. The SMS program also isn’t working. Help please…

  • Sagarika
    June 28, 2016

    my serial monitors notifies me when a msg is received but doesnt show what the msg is?

  • Ola
    June 18, 2016

    Thanks a lot for this useful project, sir, can I use SIM800l for this project instead of Sim900?

  • Ola
    June 18, 2016

    Dear sir, thanks for this beautiful program, please can I use sim800l for this purpose instead of Sim900?

  • K Naveen Kumar
    June 15, 2016

    And I tried with different codes and SIM 900A also working good sir(If I make a call I am hearing ringing sound),what is the problem I don’t sir.

  • K Naveen Kumar
    June 15, 2016

    sir,I connected all the connections what you told that and code also same but I got 10 times message and didn’t get received message on serial monitor.Now I am not getting send and received message.I am using SIM 900A,Arduino AT Mega 2560.Please help me sir.

  • Jeremy
    June 15, 2016

    Hi thanks for the code the send message works perfectly but the receive message does not work the receive message does not appear on the serial monitor

  • June 7, 2016

    hi .. i have made all the connections,same as explained above but no message is being received on the number i have mentioned in the code, the code uploads correctly but no message is received.. im using GSM SIM900A miniv3.8.2 and arduino UNO.. please help

  • ANURAJ C P
    June 1, 2016

    Sir,I have been trying to interface arduino(ARDUINO UNO) with gsm module(SIM900A) to receive a message.Nothing is shown in the COM monitor of ardino .i used the programme which you provided above.please help me.I dont want to sent message.can you please give me the programme .I want to complete my project with in 30 days.so help me please
    my email id is “anuraajcp333@gmail.com”

  • afreen
    May 22, 2016

    I am doing project “WIRELESS WEATHER MONITORING SYSTEM”using arduino uno, GSM sim900a, LCD 16×2, temperature and humidity sensor dht11…now I request yourgood self to please provide me a program that will display current temperature and humidity on LCD. also if we send SMS from any mobile number to a mobile number of simcard that is in GSM to send current temperature or humidity it must send back SMS to the mobile number from which it received SMS with current temperature or humidity..

  • raghu
    May 11, 2016

    sir i want to interface rain sensor with gsm module ie it shoul detect rainfall and send sms could please help me out?
    I tried using your code can you verify below code:-
    #include

    SoftwareSerial mySerial(9,10);
    int nRainIn = A1;
    int nRainDigitalIn = 2;
    int nRainVal;
    int gsm=12;
    boolean bIsRaining = false;
    String strRaining;

    void setup() {
    mySerial.begin(9600);
    Serial.begin(9600);
    pinMode(2,INPUT);
    pinMode(gsm,OUTPUT);
    }
    void loop() {
    nRainVal = analogRead(nRainIn);
    bIsRaining = !(digitalRead(nRainDigitalIn));

    if(bIsRaining){
    strRaining = “YES”;
    digitalWrite(gsm,HIGH);

    }
    else{
    strRaining = “NO”;
    digitalWrite(gsm,LOW);
    }

    Serial.print(“Raining?: “);
    Serial.print(strRaining);
    Serial.print(“\t Moisture Level: “);
    Serial.println(nRainVal);

    delay(200);
    if (digitalRead(12) == HIGH){

    mySerial.println(“AT+cmgf=1”);
    delay(1000);
    mySerial.println(“AT+cmgs=\”+91xxxxxxxx\”\r”);
    delay(1000);
    mySerial.println(“leak detected”);
    delay(100);
    mySerial.println((char)26);
    delay(1000);
    }}

  • amanrawka
    May 9, 2016

    Sir i am using your code to receive sms but i have found that the code is not working , i have changed mySerial to Serial3 as i am using mega , plzzz help me out with it

    ***the code****
    //#include

    //SoftwareSerial mySerial(9, 10);

    void setup()
    {
    Serial3.begin(9600); // Setting the baud rate of GSM Module
    Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
    delay(100);
    }

    void loop()
    {
    if (Serial.available()>0)
    switch(Serial.read())
    {
    case ‘s’:
    SendMessage();
    break;
    case ‘r’:
    RecieveMessage();
    break;
    }

    if (Serial3.available()>0)
    Serial.write(Serial3.read());
    }

    void SendMessage()
    {
    Serial3.println(“AT+CMGF=1”); //Sets the GSM Module in Text Mode
    delay(1000); // Delay of 1000 milli seconds or 1 second
    Serial3.println(“AT+CMGS=\”+91xxxxxxxxxx\”\r”); // Replace x with mobile number
    delay(1000);
    Serial3.println(“I am SMS from GSM Module”);// The SMS text you want to send
    delay(100);
    Serial3.println((char)26);// ASCII code of CTRL+Z
    delay(1000);
    }

    void RecieveMessage()
    {
    Serial3.println(“AT+CMGF=1”);
    delay(1000);
    Serial3.println(“AT+CNMI=2,2,0,0,0”); // AT Command to receive a live SMS
    Serial.println(“AT+CMGL=\”ALL\”\r”);
    delay(1000);
    if (Serial3.available())
    Serial.println(Serial3.read());

    delay(1000);
    }

  • midhun
    April 15, 2016

    hii…sir
    can I use gsm 300 insted of gsm 900
    pls reply to my mail

  • Salil
    April 14, 2016

    hi my sim has a pin number , how do i add that in the program.
    Thanks

  • Sahil Thakur
    April 12, 2016

    hello sir.
    i am not able to receive sms. i cannot figure out the problem. to select ‘s’ or ‘r’ this should be send through serial monitor?

  • Shobhit
    April 11, 2016

    Hi,
    Please help me how to send SMS to Mobile Number Stored in Variable.
    ie
    please edit SendMessage function as-

    SendMessage(String no){
    //help me with the code
    }

  • Stan
    April 3, 2016

    Hi Jojo,
    I follow the steps you described.
    Everything works well.
    But when I try to plug the shield onto my UNO, nothing works..
    Currently I use this shield
    http://www.embeddedartists.com/products/acc/cell_3g_pos_shield.php
    As I said, even with this shield, your tutorial does the job.
    I suppose I have to change the pins ?
    Any Idea ?

    • MARTIN
      April 23, 2016

      I have a question:
      Is it possible to program the code in such a way that gsm module could be used to send sms to a preset number as well as manually entered numbers simultaneously using arduino?

    • May 14, 2016

      I WANT TO DESIGN ARDUINO BASED REMOTE PATEINT MONITORING SYSTEM BY USING GSM ,PLEASE WOULD YOU HELP BY PROGRAMMING C CODES FOR RECEIVER CIRCUIT

    • May 14, 2016

      THANK’S BEFORE,I WANT TO DESIGN ARDUINO BASED REMOTE PATEINT MONITORING SYSTEM BY USING GSM ,PLEASE WOULD YOU HELP BY PROGRAMMING C CODES FOR RECEIVER AND TRANSMITER CIRCUIT WITH CIRCUIT DIAGRAM

    • uma
      March 13, 2017

      I have implemented the code but while running the program with my arduino UNO and GSM module SIM900A, no message is received in the provided mobile number. The serial monitor shows error in sending the message. Kindly suggest the possible cause for this error.
      please tell me how to solve this problem

  • arushi doshi
    April 3, 2016

    Hello Sir,
    Thanks for the tutorial. I have a query:
    I want to read the mobile number from an SMS sent to the GSM Module and then send msg from GSM module to the mobile number received. Can you please help me out with this?

  • Dibyendu Sur
    April 2, 2016

    we have used this code:

    char phone_no[]=”9062261355″;
    void setup()
    {
    Serial.begin(9600);
    delay(2000);
    Serial.println(“AT”);
    Serial.print(“ATD”);
    Serial.print(phone_no);
    Serial.println(“;”);
    delay(50000);
    Serial.println(“ATH”);

    // put your setup code here, to run once:

    }

    void loop() {
    // put your main code here, to run repeatedly:

    }

    __________________________________________________________________________
    In serial monitor the following characters are printed

    AT
    ATD9062261355;
    ATH

    But no phone calls are forwarded to the phone number 9062261355
    Please help in this matter

    • jojo
      April 2, 2016

      Please try adding country code. Also the delay seems to be very high. Just a 1 second or 2 second delay is enough.

      • Dibyendu Sur
        April 2, 2016

        I have just used country code(India +91)
        I have reduced the delay before ATH to 2000 (2 second) as well as 10000 (10 second)
        every time, only the text is printed in serial monitor, but no call is forwarded to the phone number
        9062261355

        • Dibyendu Sur
          April 2, 2016

          I am using Arduino Uno version 1.7.8

          • DIBYENDU SUR
            April 2, 2016

            Please reply soon

          • Danish Ilyas
            April 28, 2016

            Use mySerial instead of Serial !

          • mani
            December 19, 2016

            i don’t know for sure but you need an interface to connect your gsm to arduino. “Serial”gives connection just to monitor not GSM,Use”SoftwareSerial” to interface both.May be this helps..

        • chinta jyothi
          March 29, 2017

          try this code/*
          Make Voice Call

          This sketch, for the Arduino GSM shield, puts a voice call to
          a remote phone number that you enter through the serial monitor.
          To make it work, open the serial monitor, and when you see the
          READY message, type a phone number. Make sure the serial monitor
          is set to send a just newline when you press return.

          Circuit:
          * GSM shield
          * Voice circuit.
          With no voice circuit the call will send nor receive any sound

          created Mar 2012
          by Javier Zorzano

          This example is in the public domain.
          */

          // libraries
          #include

          // PIN Number
          #define PINNUMBER “”

          // initialize the library instance
          GSM gsmAccess; // include a ‘true’ parameter for debug enabled
          GSMVoiceCall vcs;

          String remoteNumber = “9xxxxxxxxx”; // the number you will call
          char charbuffer[20];

          void setup() {

          // initialize serial communications and wait for port to open:
          Serial.begin(9600);
          while (!Serial) {
          ; // wait for serial port to connect. Needed for native USB port only
          }

          Serial.println(“Make Voice Call”);

          // connection state
          boolean notConnected = true;

          // Start GSM shield
          // If your SIM has PIN, pass it as a parameter of begin() in quotes
          while (notConnected) {
          if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
          notConnected = false;
          } else {
          Serial.println(“Not connected”);
          delay(1000);
          }
          }

          Serial.println(“GSM initialized.”);
          Serial.println(“Enter phone number to call.”);

          }

          void loop() {

          // add any incoming characters to the String:
          while (Serial.available() > 0) {
          char inChar = Serial.read();
          // if it’s a newline, that means you should make the call:
          if (inChar == ‘\n’) {
          // make sure the phone number is not too long:
          if (remoteNumber.length() < 20) {
          // let the user know you're calling:
          Serial.print("Calling to : ");
          Serial.println(remoteNumber);
          Serial.println();

          // Call the remote number
          remoteNumber.toCharArray(charbuffer, 20);

          // Check if the receiving end has picked up the call
          if (vcs.voiceCall(charbuffer)) {
          Serial.println("Call Established. Enter line to end");
          // Wait for some input from the line
          while (Serial.read() != '\n' && (vcs.getvoiceCallStatus() == TALKING));
          // And hang up
          vcs.hangCall();
          }
          Serial.println("Call Finished");
          remoteNumber = "9xxxxxxxxx";
          Serial.println("Enter phone number to call.");
          } else {
          Serial.println("That's too long for a phone number. I'm forgetting it");
          remoteNumber = "9xxxxxxxxx";
          }
          } else {
          // add the latest character to the message to send:
          if (inChar != '\r') {
          remoteNumber += inChar;
          }
          }
          }
          }

    • Sagarika
      June 28, 2016

      you need to put in command “ATD 98xxxxxxxxxx;”

    • Mohan
      May 2, 2017

      do not print semicolon (;) after no..
      instead of this print \r\n

  • April 1, 2016

    Hello sir , I have a querry what should i do if i wanted to replace the number in

    mySerial.println(“AT+CMGS=\+YYxxxxxxxxx\”\r”);

    with a variable which can store the number , For example

    num=+xxxxxxxxxxx;
    mySerial.println(“AT+CMGS=\num\”\r”);

    • Deepam Das
      April 4, 2016

      char num[14]=”+91xxxxxxxxxx”;
      mySerial.print(“AT+CMGS=\”);
      mySerial.print(num);
      mySerial.println(“\”\r”);

  • raam
    March 29, 2016

    hai, your code is working perfectly with my arduino mega. but I need to send GPS coordinates via SMS. how can I do that cos softwareserial can’t be used two times at a time. Can you advise on this?? when I use hardware serial for GPS delay was not taken.

    • friday
      August 8, 2016

      if u r trying to communicate the modules one at a time, u can use 4066 switch. check if it is suitable for ur project.

  • smruthi
    March 25, 2016

    Sir,im doing a project including arduino and gsm.i need the code for entering the phone number manually using keypad and send sms to it.will you please help me…..

  • Mohamad Hafiz
    March 21, 2016

    When i upload and try to run the program… nothing display on my serial monitor why is that?

  • March 20, 2016

    Hay sir,
    I already tested your code. it works perfectly.
    But, i want to modify to turn on/off the LED and not success.
    Could you help me, for this problem?
    Just simple, i want turn on LED 13, after recieve sms “on”.

    thank you,

    • jojo
      March 20, 2016

      @albert – It is very simple. I assume you want to turn an LED at pin 13 ‘ON’ after receiving an sms. First assign a variable name to pin 13 with command – const int LED = 13; In the next step configure pin as OUTPUT. Inside void setup() – write command – PinMode(LED,OUTPUT). Now write the following command inside RecieveMessage() method after delay(1000); – command – digitalWrite(LED,HIGH); delay(1000); For more details – refer – http://www.circuitstoday.com/blink-led-with-arduino

      • albert
        March 21, 2016

        Dear Sir,
        I already know how to control on/off the LED in arduino. The problem is, if i want to turn on the LED by send sms “ON_LED” and then send sms “OFF_LED” to turn off the LED.
        This my code, still not working for turn on/off the LED.

        char inchar;

        void RecieveMessage()
        {
        SIM900.println(“AT+CNMI=2,2,0,0,0”); // AT Command to receive a live SMS
        delay(1000);
        if (inchar==’ON_LED’)
        {
        digitalWrite(led, HIGH);
        }
        else if (inchar==’OFF_LED’)
        {
        digitalWrite(led, LOW);
        }
        delay(1000);
        }

        whats the problem?
        thank you

        • Soubhik Kumar Dey
          April 23, 2016

          inchar will read each character one by one serially. You cannot just compare inchar with a string. Do Serial.read everytime for all the letters in your input (ON_LED). Like do Serial.read, compare inchar with ‘O’, then Serial.read, compare with ‘N’, Serial..read etc….

        • Ed Hearne
          May 6, 2016

          Have you managed to get your program working.
          I am trying to do the same but cannot get the LED to flash on receiving a text message

    • chintajyoti
      June 24, 2017

      please can any one help me with program code without switch case i want to impliment the circuit with a battery supply.

  • hemanth
    March 18, 2016

    hi sir …..
    i am gud with ur program…i need some help in creating a new program in which i am using ultrasonic sensor hc sr-04 and interfacing sim900…arduino should send the mesg to the no. when the distance from the ultrasonic sensor reaches 15cms…can u please send me the code for that

  • siva
    March 18, 2016

    My gsm module responds to first received message but not for the second one. what exactly is the problem ?

    • jojo
      March 18, 2016

      @siva – the program we have written is an example for interfacing GSM Module to Arduino. The program is written in such a way that it scans any input from serial monitor of arduino continuously. Once you press ‘r’ on serial monitor, the program will call method to receive message from GSM module. This message is then written to serial monitor of arduino for display. Once that process is over, program again scans for a command (‘s’ or ‘r’) from serial monitor. So if you want to receive second message from gsm module, press ‘r’ again on serial monitor. If you to receive 3rd message, press ‘r’ again (after second message is displayed on serial monitor)

      Note:- You need to alter this program to receive messages continuously.

    • divya
      December 23, 2017

      we are doing project on smart sensor for agricultural field using GSM with AURDINO interfacing . according to different conditions of motor turn on and off for this how i have to write code for sending and receiving different messages. plz …..reply soon ….as soon as possible….

  • SHAYAN
    March 18, 2016

    hai, i am from SriLanka. new to this field. I have tried this but this is not working for me. I am using Arduino Mega and SIM900A GSM/GPRS module which is shown in this link http://arduino.stackexchange.com/questions/21499/connecting-sim900a-gsm-gprs-module-arduino-mega/21552#21552
    Please can you help me on this??

    • jojo
      March 18, 2016

      I have seen your GSM Module image here – http://i.stack.imgur.com/AxKag.jpg
      Here are my thoughts!

      1. You should connect it to TTL pins Rx, Tx and Ground. GSM Rx to Arduino Tx and GSM Tx to Arduino Rx. GSM Gnd to Arduino Gnd.
      2. Dont worry about other jumper pins. Just make the connection.
      3. After inserting SIM Card, Press and Hold Power button. Notice the Network Status LED marked as NET_STA on your GSM board. This LED should blink in 3 seconds delay continuously.
      4. Make a call to the sim card number inside GSM module. If you hear ringing sound on your phone,the interfacing of GSM module to Arduino is perfect.

      • SHAYAN
        March 18, 2016

        Hi again,
        I have followed your way already and I was able to hear ring back tone. But when try the code, Serial.available was not read in serial monitor. I don’t know what is wrong. Can you guess what will be the reason for this? but my Arduino serial ports are working properly.

        • jojo
          March 18, 2016

          Which pins are you using ? If you are using SoftwareSerial library for communicating with Arduino, then select any 2 PWM enabled pins instead of Rx and Tx of Arduino (like pins 9 and 10 in Arduino uno)

          • SHAYAN
            March 19, 2016

            Thank you for your information. i have tried but there is no response yet. could you please tell me that do i need to edit coding rather than change the pin (in mega2560 PWM pins can be 4-12) and the destination mobile number??

          • jojo
            March 19, 2016

            Note these points.

            Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

            Refer – https://www.arduino.cc/en/Reference.SoftwareSerial

            1.Make sure pins are configured in software correctly.
            2. Try changing the delay given in program (inside SendMessage() method)
            3. Make sure your country code is given correctly in mobile number. +91 – is country code of India. Change it to your country.

          • SHAYAN
            March 19, 2016

            Hi Sir, there is improvement in sending a SMS. I have used 50,51 pins and my no is given correctly. How can I use Mega Rx,Tx directly to interface SIM900A with Arduino?? Could you please explain??

          • SHAYAN
            March 19, 2016

            Hi Sir, there is no improvement in sending a SMS. I have used 50,51 pins and my no is given correctly. How can I use Mega Rx,Tx directly to interface SIM900A with Arduino?? Could you please explain??

          • SHAYAN
            March 23, 2016

            Hello sir,
            your code works perfectly. really really thanks for guiding me. there is one more change that i wanted to do to get successful. finally works with pin 11 and 12.

        • June 18, 2016

          Hey sir , i am also using a mega 2560 but still not working can you give me your all connection whether you used rs232 or not

  • nsimi
    March 18, 2016

    Kindly explain how to send this ‘s’ and ‘r’ variables as input in order to call receive or send message function.

    • jojo
      March 18, 2016

      @nismi – Open the “Serial Monitor”of Arduino. Type s and hit enter. Once you are finished with sending message, type r and press enter button.

      • bonface otieno
        November 13, 2016

        Are all GSM Modules the same?

  • March 17, 2016

    I am not getting serial commends for this program? what to do for getting

    • jojo
      March 18, 2016

      @suraj – What is the problem you are facing ? Serial commands are written in the program. To send ‘s’ and ‘r’ commands serially, open the serial monitor of Arduino.

  • Chandar
    March 14, 2016

    In my project I am out off all digital pin except Rx and Tx. Can I use the software serial library for Rx and Tx. Like instead of mentioning Softwareserial myserial (9,10) , can I mention Softwareserial myserial (Rx,Tx)?
    If not can you send the code for Rx,Tx.

    • jojo
      March 15, 2016

      @chandar – Software Serial actually makes use of the Rx and Tx hardware internally. You better connect directly to Rx and Tx and use the serial communication commands of Arduino. Refer – https://www.arduino.cc/en/Reference/Serial

  • chandra mouli
    March 13, 2016

    hi sir

    do we require any converter from rs232 to ttl in between the microcontroller and the sim900 modem

    • jojo
      March 14, 2016

      @chandra mouli – Check if your GSM module has TTL output provision. Most of the GSM modules available in market has TTL output provisions. If the module has only RS232 output provision, you need to use an RS232 to TTL converter to interface that particular module with Arduino.

  • March 12, 2016

    hi iam trying your program but it not working

    the message not send automatically…..
    what can I do now

    • jojo
      March 13, 2016

      @Karthikeyan – We have tested this code many times repeatedly and it was working 100% all the time. Your issue may not be with the code. Double check hardware connections! Also check if you have input the mobile number correctly!

  • Ali
    March 9, 2016

    Good day sir,
    Please can you explain how can we send the input reading through GSM modem. For example i want ardinuo to take input reading and then send it through sms. How can we implement this please?

    • jojo
      March 9, 2016

      @Ali – Its very simple. Save the input to a variable or array. Now write the variable values one by one serially to GSM module using Serial.println() command. In our example we are using Software Serial method, so we use mySerial.println() method. If input variable is val_input, then write the following to GSM module – mySerial.println(val_input);

  • March 6, 2016

    sir we have to perform operation based on sms coming to that no
    eg: if on is come then blow a light
    otherwise off the light
    plzzz help me out for this

    • jojo
      March 6, 2016

      @Abdul Malik – Its actually simple. You first learn AT Commands to receive an SMS. Once you receive the SMS, save its content to a variable or array. Scan the array to check for required number/digit/character.

      • Sai Charan
        June 9, 2016

        How can i save the data to array or variable, can you give me the code.

  • wooja
    March 1, 2016

    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?

    • jojo
      March 1, 2016

      @wooja – I don’t have a good idea of the +32. It could be some number of characters sent or something like that. Refer AT Commands Datasheet.

  • February 16, 2016

    can you please help me with a simple example of how the aduino can respond to any remote number from a mobile phone using the sim 900 module without specifying any number

    • jojo
      February 16, 2016

      I did not understand your question. Please explain it again.

      • February 16, 2016

        am trying to make a system that responds to any user who sends an sms command to the sim900 module using the exact step that you had provided ,but using mySerial.println(“AT+CMGS=\”+91xxxxxxxxxx\”\r”); will only allow the system to send a response to one number , how can i implement a system that responds to multiple phone numbers wich send a command to the sim900 or a function that Retrieves the phone number an from an incoming SMS message and stores it in a named array , just like the function “remoteNumber()” wich is present in the aduino “GSM.h” library .

  • aiman ramlan
    November 12, 2015

    hello sir, im trying to use GSM sim900A in malaysia with using the exact step that you had provide. but the GSM still does not sending any text or receive text. but when im trying to establish the network connection of GSM, i had heard the ringing. so what is the problem ? can you help sir ? its important to me. thank you

    • jojo
      February 16, 2016

      @aiman – It can be an error with your program. Double check the program.

  • BS
    October 10, 2015

    thanks, it is working fine!!

  • Aman
    July 11, 2015

    We are using ” \” in “AT+CMGS=\”+91xxxxxxxxxx\”\r” to differentiate mobile no & AT command Stringset. I want to know how arduino reads this code?

  • Sai Abhinay
    June 3, 2015

    Could you please specify the syntax for call commands. I tried different combinations but I am unable to figure it out and Thank you for this SMS information, it worked perfect

  • June 3, 2015

    please i need the pdf format of this project. i will be very glad if you can send it through my e-mail address above. thanks

  • Victor
    May 9, 2015

    Yea thanks for this. I found out that output of the gsm module is static, i mean is only what we have input is what is doing. Is there no way it could check for out box messages and be able to re-send any in it to the controller. Maybe some other dynamic functions too.

    • jojo
      May 19, 2015

      @Victor Its possible to read inbox and many other functions using GSM module. Learn AT Commands thoroughly for that.

  • sajal nagwanshi
    May 2, 2015

    Hi,

    Thank you very much. The information about software serial was very helpful.

    • VijayJay
      May 17, 2018

      Hi.. Frnds..can anyone say, the Tx, Rx terminals of arduino should connected to which port in GSM Module either Serial port or Rs485..?

Leave a Reply to Dibyendu Sur Cancel reply

Your email address will not be published. Required fields are marked *