How to send SMS from GSM modem using arduino

sim800 gsm module, interfacing sim900a with arduino

Interfacing sim800 / sim900A GSM module with arduino

Here describes the interfacing between a SIM 800 GSM / SIM 900A GSM module with an Arduino board via TTL serial communication.

Arduino gsm module pinout

Arduino pin GSM modem pin
RX TX
TX  RX
GND  GND

For a TTL serial connection, connect the pins from the GSM device to Arduino as,  Rx pin to TX pin and TX pin to Rx pin. Or if the software serial is used, connect to the declared Transmitter and Receiver pins. If the Arduino code uses the serial communication as Serial.begin(9600), the TX and RX pins will be default TX and RX pins of the AVR microcontroller which is labelled on the Arduino UNO board. So just plug to TX pin (pin 1) and the RX pin (pin 0).

E.g: – SoftwareSerial mySerial (2, 3); // RX digital pin 2, TX digital pin 3.

gsm module sim900 , GSM module interface , GSM module pin

GSM modems may also have a female RS232 serial port for direct connection to PC. In order to work directly with hyper terminal or similar serial terminals using AT commands.

GSM modem booting

Insert the SIM card into the SIM socket of the module and lock it.

gsm module sim900a , gsm module sim800

The GSM module requires a considerable amount of power to establish a network connection, and for operations. So power from the Arduino board will not be enough for it. So an external power is required for most GSM modules.

The GSM module Commonly has a 12V DC input, which can be connected either via DC socket or through connector pins. Plug a 12V adapter into the Socket or power it by connector pins on the board.

On powered up, the power LED gets ON and the Network Status LED starts to blink. The network LED blink every second and after when the Modem registers the network, the LED will blink in every 3 seconds. The GSM module takes some time, around 60 seconds to establish a connection with mobile networks.

Send sms using gsm module with Arduino

Here we are sending TEXT messages from GSM modem with Arduino UNO using AT commands.

Connect GSM device to Arduino as  Rx and TX pin of the GSM module to TX and Rx pin of the arduino respectively; as explained above in interfacing. Using the below code the GSM module can be directly connected to the Arduino serial pins.

Arduino GSM SMS code 

void setup()
{
  //Set Exact Baud rate of the GSM/GPRS Module.
  Serial.begin(9600);  
  Serial.print("\r");
  delay(1000);                  
  Serial.print("AT+CMGF=1\r");    
  delay(1000);
  /*Replace XXXXXXXXXX to 10 digit mobile number &  ZZ to 2 digit country code*/
  Serial.print("AT+CMGS=\"+ZZXXXXXXXXXX\"\r");    
  delay(1000);
  //The text of the message to be sent.
  Serial.print("HELLO WORLD");   
  delay(1000);
  Serial.write(0x1A);
  delay(1000); 
}
void loop()
{
}

The set of operation code is placed in the void setup (). Each time when the Arduino is powered ON’s an SMS will send, as the void setup function only run once. Or Resetting the Arduino board (press the reset switch on the Arduino board) also sends a message.

In the AT commands,

AT+CMGF=1\r,  put the modem in SMS text format mode.

AT+CMGS=\”+ZZ XXXXXXXXXX\”\r, The SMS will send to the 10 digit  number written as XXXXXXXXXX with 2 digit country code ZZ.

Here the TEXT is “Hello world”, replace it with the TEXT need to be sent.

0x1A, it is the hexadecimal of the decimal character code 26, which is  Substituted (SUB) symbol in ASCII control characters.

Send SMS using push switch

In this device whenever the switch is pressed, a text message (text in the code) will send to the number specified in the code. When the pushbutton is pressed, the Arduino sends the AT commands to the GSM module, for a text SMS; the GSM module works with the “AT commands”.

gsm send sms, arduino gsm

Connect the TX, RX and GND pins from the Arduino to the GSM as labelled in the diagram. Then connect the push switch between the 5V and pin2. Add a pull-down resistor across the pin2 and Ground. The Pin2 is configured as the input pin. When the pin2 reads an active high state, the sketch inside the if condition will be executed. And the SMS sends.

A variable called state is also added to the condition function of the program, it is to prevent multiple sending of SMS on a single switch press. The “if” condition becomes true only when the digitalRead at pin 2 is high and the value of variable state is ‘ 0 ‘. The value of variable state is initialized as ‘ 0 ‘. On pressing the switch, the “if” condition becomes true, that the SMS sends and the state value set to ‘ 1 ‘. Only when the switch is released the state value sets back to ‘ 0 ‘. Only the switch press after the setback of the state to ‘ 0 ‘ makes the if condition true. So a long press will not send multiple SMS, only press after a release sends the next SMS. That is, each consecutive press sends each SMS.

Arduino GSM send SMS code

int state = 0;
const int pin = 2;
void setup()
{
  //Set Exact Baud rate of the GSM/GPRS Module.
  Serial.begin(9600);
}
void loop()
{
  if (digitalRead(pin) == HIGH && state == 0) {
    Serial.print("\r");
    delay(1000);
    Serial.print("AT+CMGF=1\r");
    delay(1000);
    /*Replace XXXXXXXXXX to 10 digit mobile number & ZZ to 2 digit country code*/
    Serial.print("AT+CMGS=\"+ZZXXXXXXXXXX\"\r");
    delay(1000);
    //The text of the message to be sent.
    Serial.print("HELLO WORLD");
    delay(1000);
    Serial.write(0x1A);
    delay(1000);
    state = 1;
  }
  else {
    state = 0;
  }
}
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

You may also like...

26 Responses

  1. Pradeep Bhikaji Thombre says:

    Sir how to send current location via sms to phone using gsm module and aurdino

  2. admin says:

    This is the complete code to display almost all the available data in the GPS. If you need only the latitude and longitude values use the code given in the article.

    #include <SoftwareSerial.h>
    #include <TinyGPS.h>
    
    TinyGPS gps;
    SoftwareSerial serialgps(4,3);
    int year;
    byte month, day, hour, minute, second, hundredths;
    unsigned long chars;
    unsigned short sentences, failed_checksum;
    
    void setup()
    {
    
    Serial.begin(9600);
    serialgps.begin(9600);
    Serial.println("");
    Serial.println("GPS Shield QuickStart Example Sketch v12");
    Serial.println(" ...waiting for lock... ");
    Serial.println("");
    }
    
    void loop()
    {
    while(serialgps.available()) 
    {
    int c = serialgps.read(); 
    if(gps.encode(c)) 
    {
    float latitude, longitude;
    gps.f_get_position(&latitude, &longitude);
    Serial.print("Lat/Long: "); 
    Serial.print(latitude,6); 
    Serial.print(", "); 
    Serial.println(longitude,6);
    gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
    Serial.print("Date: "); Serial.print(month, DEC); Serial.print("/"); 
    Serial.print(day, DEC); Serial.print("/"); Serial.print(year);
    Serial.print(" Time: "); Serial.print(hour, DEC); Serial.print(":"); 
    Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC); 
    Serial.print("."); Serial.println(hundredths, DEC);
    Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude()); 
    Serial.print("Course (degrees): "); Serial.println(gps.f_course()); 
    Serial.print("Speed(kmph): "); Serial.println(gps.f_speed_kmph());
    Serial.print("Satellites: "); Serial.println(gps.satellites());
    Serial.println();
    gps.stats(&chars, &sentences, &failed_checksum);
    }
    }
    }
    
    
  3. Ss says:

    Can I send sms to multipal mobile no with single gsm card

  4. Niki says:

    Sir how to send data of ultrasonic sensor using Arduino and gsm

  5. mawe says:

    sir the module i have is SIM800L EVB which is the version 2 of SIM800. .my problem is the NET(LED) is blinking every seconds whch means it does not connected to the network. how can i possibly fix this ? thank you for the help. more power !

    • admin says:

      Maybe its due to lack of signal strength. Make sure the spot has enough signal coverage, or try at different locations, also adjust the antenna. You should try it for a few minutes to register a connection with the service provider.
      Many times I had brand new but defective modules, so first make sure it is working.

  6. prathamesh says:

    sir i need a code in which sms is send by sim900 by push button and by receiving the sms by sim900( on or off)sms relay activate or off plz i need help

  7. Hari says:

    Hi sir I am using sim900a GSM module how to send SMS to multiple numbers using esp8266 please share if any code

  8. SK AMIRUL says:

    I need a code for make a voice call by sim900 by push button.

  9. Ellysssa says:

    The sms keep sending mutiple times even i don’t press the button

  10. Harika says:

    sir I want the code for sending current location via latitude and longitude to the mobile phone by using gsm 900a module, Neo 6mGps module
    and arduino uno

    • admin says:

      Integrate the code for GPS receiver with the code for GSM.
      Refer : GPS receiver using arduino
      Under the area for – “//The text of the message to be sent” in the code for GSM. Use,

            Serial.print("Latitude :");
            Serial.println(slat, 6);
            Serial.print("Longitude:");
            Serial.println(slon, 6);
      
  11. Sanket Bhaute says:

    How can I send SMS and current location from GSM900A and GPS SIM28ML using switch

  12. SRUITH says:

    I want how to gsm send the message .full details and working of gprs,interfacing of GSM and ARDUINO.

  13. darji hadik says:

    I am making smart dustbin. In it I have used Ultrasonic sensors, I have used aurdino Uno, Ultrasonic sensor and gsm 800.Whenever someone comes against Ultrasonic sensor, you can write a program to get messages from gsm’s help.

  14. Beena says:

    How to send SMS to multiple no.

    • admin says:

      You can either add the same code repeating once again with another number. Or you can add number numbers to an array and use “for loop” to call array.

  15. Sizzy says:

    sir, the code for send sms using push button, sends sms even without me pushing the button…how do i fix that

    • Sizzy says:

      my code:
      #include
      SoftwareSerial sim808(7,8);

      int state = 0;
      const int pin = 2;
      void setup()
      {
      sim808.begin(9600);
      //Set Exact Baud rate of the GSM/GPRS Module.
      Serial.begin(9600);
      delay(100);
      }
      void loop()
      {
      if (digitalRead(pin) == HIGH && state == 0) {
      sim808.print(“\r”);
      delay(1000);
      sim808.print(“AT+CMGF=1\r”);
      delay(1000);

      sim808.print(“AT+CMGS=\”+2348176996281\”\r”);
      delay(1000);

      sim808.print(“Distress Signal, HELP!!!”);
      delay(1000);
      sim808.write(0x1A);
      delay(1000);
      state = 1;
      }
      else {
      state = 0;
      }
      }

      im using sim808

    • admin says:

      Most probably it is due to false input. Check and ensure that the pull-down resistors are properly connected between the Input and GND terminals.

Leave a Reply

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