Earn Maker Points on Every Order! Learn More!

SIM800L GSM Module with Arduino | AT Commands | Library

Back to Blog
SIM800L GSM Module with Arduino | AT Commands | Library - SIM800L GSM Module with Arduino | AT Commands | Library - SIM800L GSM Module with Arduino | AT Commands | Library - SIM800L GSM Module with Arduino | AT Commands | Library

SIM800L GSM Module with Arduino | AT Commands | Library

SIM800L Module is a small GSM/GPRS Module and ideal for small ideal projects. The module supports quad-band GSM/GPRS network, available for SMS and GPRS message data remote transmission. SIM800L is advanced than its previous SIM900 modules.

There are other multiple versions of SIM800 is available. The choices of models depend upon the application needs. But SIM800L is used widely for common applications. The features of different models are given below.

  • SIM800L has FM functionality.
  • SIM800C has Bluetooth functionality.
  • SIM800F is pin compatible to the SIM900 module.
  • SIM868 is dual sim version with GNSS and small form factor.

The AT Commands are mostly the same for all GSM Modules based on SIMCOM AT Commands except its additional features like Bluetooth, FM will vary. Refer the datasheet for more details.

The SIM800L can work up to 2 Amps current at peak. It also has a low power consumption feature that consumes 1mA Current in sleep mode. You need to power the module from 3.7V to 4.4V as per the datasheet. More than that will damage the module. You can use a buck converter like LM2596 to achieve this voltage and current range.

Features:

  • 2G Quad-band 850/900/1800/1900MHz
  • Receive and make calls using the speaker and microphone outputs
  • Receive and send SMS
  • Listen to FM radio broadcasts
  • GPRS multi-slot class12 connectivity: max. 85.6kbps(download/upload)
  • GPRS mobile station class B
  • Controlled by AT Command (3GPP TS 27.007, 27.005 and SIMCOM enhanced AT Commands)
  • Supports Real Time Clock
  • Operating Voltage range 3.4V ~ 4.4V
  • Supports A-GPS
  • Low power consumption, 1mA in sleep mode
  • Micro SIM Card Support

 

LED Blinking status:

If the power to the SIM800L is enough, the onboard LED starts blinking according to its operation. If the power is not enough it will receive poor signal and search for network all the time (if still searching adjust the trimpot slightly but do not exceed much than 4.7v). The frequency of the blinking denotes the following:

  • Every second:  searching for a network.
  • Every three seconds: connected to a network.
  • Twice per second: connected through GPRS.

Note: The SIM800L accepts only 2G (No 4G)

In this tutorial, we will see how to use SIM800L GSM module with an Arduino.

Pin Details:

At the backside of the module, you can find the pin details printed on it. We will be using 5 Pins to connect with Arduino for basic operation. They are

NET – Antenna pin for the module (Spring Type included). You can use an external antenna via an uFL Connector available on the module for a better signal reception.

VCC – Power supply 3.4V to 4.4V with min 2 Amp. (LM2596 with a 9/12V 1Amp adapter input and it should be adjusted to 4.2V recommended).

RST – Reset

RXD – Receiver to the module – 3.3V Logic (To be connected to Arduino TX Pin. Voltage divider recommended).

TXD – Transmitter from the module (To be connected to Arduino RX Pin).

GND – Ground.

SIM800L PinOUT 

Circuit Diagram:

Before making connections, make sure the LM2596 output is set to 4.4V by adjusting the potentiometer on the LM2596 module. You can use a Multi-meter to check the voltage (or) you can use the LM2596 Module with Display. As we know the SIM800L accepts 3.6V – 4.4V and 2Amps, the SIM800L module can draw much current as needed from the LM2596 with a fixed voltage.

The RX Pin of SIM800L Module Should connects to TX Pin of the Arduino. Similarly, the TX Pin of SIM800L should connect to RX Pin of Arduino. In simple logic, a receiver can receive some data only if it is transmitted from somewhere. Similarly for the transmitter side, when some data is sent, the other should receive it to make use of it.

 

SIM800L With Arduino_bb

Note: For long time use a voltage divider is recommended as the TX & RX Pins of SIM800L is 3.3V Logic level. We only need a voltage divider at the RX Pin of SIM800L. Because a 3.3v from SIM800L can be able to handle by a 5V Arduino Pin (TX) (probably a lesser voltage, but it takes even a 2.7v as a high signal).

Voltage Divider for 5V to 3.3V is 

Vin = Arduino’s TX = 5V

Vout = SIM800L’s RX = 3.3V

R1 = 1.7K Ohm

R2 = 3.3K Ohm

Voltage_divider

 

Alternatively, you can use this Bi-Directional Level Shifter.

Simple Code to send AT Commands and display data from GSM Module on Serial Monitor:

The following code will read the GSM data via Software Serial and print it on Serial Monitor. Similarly, it sends the user entered string from Serial Monitor to the GSM Module.

#include <SoftwareSerial.h>

String tempSerial, tempGSM;

SoftwareSerial gsm(10, 11); // RX, TX of Arduino



void setup() {



  Serial.begin(9600); //Set Serial Monitor Baudrate

  Serial.println("SIM800L Test");

  gsm.begin(4800); // Set GSM Baudrate



}



void loop() {



//Read from GSM and Print on Serial Monitor

  if(gsm.available())

  {

    tempGSM = gsm.readString(); // Read from GSM and Store it in this variable.

    Serial.println(tempGSM);    //Print the string from GSM to Serial Monitor.

  }



//Write to GSM from user given Serial Monitor Inputs(AT Commands)

  if(Serial.available())

  {

    tempSerial = Serial.readString(); //Read from Serial Monitor and store it in this variable.

    gsm.println(tempSerial);   //Send the Serial Monitor Strings(AT Commands) to GSM.

  }

}

 

By using the serial monitor, we send AT Commands to the GSM Module to perform various functions. But we will see few AT commands in this tutorial. You can refer the AT Commands datasheet for various AT Commands.

AT

If you send this, the GSM Module will reply ‘OK’. This means the GSM Module is communicating with Arduino.

ATD 98XXXXXXXX;

This command is used to dial a number. You need to add a semicolon (;) after this command. The syntax is ATD<space><mobilenumber>;

 

SMS Function:

To send or read SMS from the module we need to set the module to SMS mode and then use the AT Commands for SMS.

To set the GSM Module in SMS mode, use the following code.

AT+CMGF=1

Once it returns OK, then use the second command to read the SMS.

AT+CMGR=1

To Send an SMS, set the GSM Modem to SMS mode using ‘AT+CMGF=1’ and then use the following command.

AT+CMGS="98XXXXXXXX"

The modem will return an arrow to enter the message (>). Type the message and hit enter.

 

Note: To exit from SMS Mode we need to send ‘Ctrl+Z’ in ASCII Form. So after the SMS functions finished we need to send ’26’ to get back to normal mode. The ’26’ is the ASCII Character for ‘Ctrl+Z’.

Syntax to send the ASCII Character to GSM:

gsm.println((char)26);// 26 is ASCII code of CTRL+Z

How to use SIM800L Library?

To simplify the operation, there is a library available on GitHub to use SIM800L GSM module. You can download the SIM800L Library zip file and install it on your Arduino IDE. Once downloaded you can open File>Examples>SIM800L and upload the code. In this library, the Software Serial pins are assigned to 10(RX), 11(TX) and 2 (RST) of Arduino by default. You can modify it on the library if you want.

Sample Code to send SMS using SIM800L Library:

/*   

 *    PINOUT:

 *        _____________________________

 *       |  ARDUINO UNO >>>   SIM800L  |

 *        -----------------------------

 *            GND      >>>   GND

 *        RX  10       >>>   TX   

 *        TX  11       >>>   RX

 *       RESET 2       >>>   RST

 *                

 *   POWER SOURCE 4.2V >>> VCC

*/



#include <Sim800l.h>

#include <SoftwareSerial.h> //is necesary for the library!!

Sim800l gsmModule;  //to declare the library



void setup(){

                gsmModule.begin(); // initializate the library.

                gsmModule.sendSms("+91XXXXXXXXXX","the text go here"); // (Mobile Number, Text to be sent).



}



void loop(){

                //do nothing

}

We write the code only at the setup loop because it needs to be sent only once. Upload the code and you can receive the SMS on the number you entered on the code.

Share this post

Comments (35)

  • Bammidi Eswararao

    Sir pls.. At command not working
    Uploaded no
    (Class softwareserial’has no member named’redstring’) errr

    Library send me

    September 25, 2018 at 11:37 AM
    • Sharath

      Check this part of code. You might have deleted an ‘a’ in the readString();. Instead of readString() you mentioned redString()

      This is the correct part of the code.
       
      if(gsm.available())

      {

      tempGSM = gsm.readString(); // Read from GSM and Store it in this variable.

      Serial.println(tempGSM); //Print the string from GSM to Serial Monitor.

      }

      September 26, 2018 at 10:32 AM
  • Son Albea

    I think this internet site has some really wonderful information for everyone : D.

    December 19, 2018 at 11:25 AM
  • Akash Kumar

    Is there any AT command which can encode the DTMF signals?

    If yes, could you provide such library by which DTMF signals can be send through the gsm network to some other gsm module ( Library for sim800 and sim 900).

    February 1, 2019 at 9:13 PM
    • Sharath

      The tinyGPS library has this function.

      #define CALL_TARGET "+91XXXXXXXXXX" //Target mobile number (Reciever)
      SoftwareSerial SerialAT(10, 11); // RX, TX
      TinyGsm modem(SerialAT); //Creating object for TinyGsm as modem

      Inside loop


      #if defined(CALL_TARGET)
      Serial.println("Calling:", CALL_TARGET);
      bool res = modem.callNumber(CALL_TARGET);
      Serial.println("Call:", res ? "OK" : "fail");

      if (res) {
      delay(1000L); //delay with long datatype

      // Encode DTMF 'A' tone, duration 1000ms
      modem.dtmfSend('A', 1000);

      // Encode DTMF 0 to 4, default duration (100ms)
      for (char tone='0'; tone<='4'; tone++) { modem.dtmfSend(tone); } //Sending 1 code for 200ms modem.dtmfSend('1',200)// Encode and play 1 as DTMF tone for 200msdelay(5000);res = modem.callHangup(); Serial.println("Hang up:", res ? "OK" : "fail"); } #endif

      On the receiver side

      Set GSM Module in Auto answer mode and use AT+Commands to decode it. Check the AT Command datasheet manual.

      ATS0=2 //Command for auto answering (answers in 2 rings)
      AT+DDET=1 //Enabling DTMF Detection feature

      February 2, 2019 at 11:45 AM
      • Pranjal Gurav

        Can you share code for decoding plz.

        February 21, 2020 at 9:57 PM
  • Baha

    how can i set the gsm into receive sms mode and do “if” with it
    if (>Here?<){
    //do things
    }

    February 23, 2019 at 2:05 PM
    • Sharath

      In AT Commands mode:
      You need to create a variable to store data temporarily from the GSM Module. Then use gsm.print(“AT+CMGR=1”); // Sending AT command for SMS Read mode.
      Next read the data from GSM Received buffer.
      Then do if with that. Refer AT Commands datasheet so that you can find any simpler command to do your desired operation with parameters.

      February 24, 2019 at 9:54 AM
  • ayoub

    please ser how can i change the number phone from caracters to variable ?

    April 9, 2019 at 10:23 PM
    • Sharath

      char phone_no[] = “+91xxxxxxxxxx”;
      char phone_no2[]=”+91xxxxxxxxxx”;

      wherever you want the phone number you can just use this variable.
      Eg:

      gsmModule.sendSms(phone_no,”the text go here”); // (Mobile Number, Text to be sent).

      April 10, 2019 at 2:00 PM
  • Tonmoy

    The data pins 10 and 11 for Tx and Rx are 5v right ? Is the Rx and Tx od 800L 5v tolerant form the data pins 10 and 11 ? Or is it just for Vcc of 800L ?

    April 13, 2019 at 12:09 AM
    • Sharath

      Yes, It is 3.3v tolerant only. You can use a 10K Resistor at SIM800L’s RX Pin. For normal use, it works without that resistor. But for a long time use, you must use a level shifter.

      Proper 3.3V Voltage divider for 5v to 3.3v is
      R1 = 1.7K Ohm
      R2= 3.3K Ohm

      April 13, 2019 at 10:52 AM
  • Roslia Santamaria

    Thank you for sharing grateful information.

    June 15, 2019 at 12:16 PM
  • Srinath

    I am getting reverse question marks in serial monitor and I have followed all the connections recommended here. Can you help?

    June 19, 2019 at 10:46 AM
    • Sharath

      Whatever Baud rate you are choosing in this line
      Serial.begin(9600); //Set Serial Monitor Baudrate
      Should be set in the serial Monitor. At the bottom of serial monitor, you can change it.

      June 19, 2019 at 1:43 PM
  • sankar babu

    Hii I am trying to send and receive a message from GSM (sim800 ) and code also downloaded i type the message in serial monitoring through serial monitoring receive the message, to mobile through Sim 800L but I can’t receive any message from my mobile to serial mobile, please give some solution to transmit and receive message from sim800 module , I buy this sim800 module on this website http://uitechies.co.in/BBBcircuits/product.php?product=sim800l-gprs-gsm-module-microsim-card-core-boardquad-band-ttl-serial-port-pcbantenna .

    August 26, 2019 at 3:43 PM
  • Simin

    Hello
    Can u help me plz whit a gas security sensor using MQ5 and sim800l for sending a warning sms?

    September 3, 2019 at 12:46 PM
  • Jeevan

    Hii Iam interfaced sim800l outdoor side I getting signal from sim but didn’t get signal in room but my mobile signal was detected with same sim how to rectify this intreption to get signal at home please find out me

    September 30, 2019 at 6:28 PM
  • Pedro Lourenço

    Hello!

    It is possible to create my voltage divider with R1=10k Ohms and R2=20k Ohms?
    My project is working more or less fine with those resistances but the voltage that the SIM800L sends to Arduino is just 2.8V (Voltage coming out of voltage divider is 3.23V) and sometimes it looks like the serial communication between Arduino and SIM800L takes more time than it should…

    Thank you!

    October 25, 2019 at 3:39 PM
    • Sharath

      Yes you can use a voltage divider. You can use this calculator – http://www.ohmslawcalculator.com/voltage-divider-calculator

      Alternatively, there is a level shifter modules available. That will do the job simply on both directions (Bi-Directional). – https://www.factoryforward.com/product/4-channel-level-shifter/

      October 25, 2019 at 4:16 PM
      • Kiran jadhav

        Sir o use sim 800l but recived quation mark .i try all buad rate change and code..Please help ….

        December 12, 2019 at 7:23 AM
        • Sharath

          Have you changed the baud rate of SIM800L or Serial Monitor?
          SIM800L Has auto baud rate feature by default. If it is changed, you can set it by using following AT Commands:

          AT+IPR=0 // Enable auto bauding, this is enabled by default

          AT+IPR=9600 // Set baud rate to 9600 bps

          AT+IPR=115200 // Set baud rate to 115200 bps

          AT+IPR=38400 // Set baud rate to 38400 bps

          To do this, you can send AT Commands in the setup loop:
          gsm.println(“AT+IPR=0”);

          December 12, 2019 at 10:41 AM
  • Jeevan

    Hello sir,I am interced GSM Sim800L module with aurdino and powers are connected with buck but i didn’t get any signal from GSM module and also tried to Diode also but same problem. What i can do ?

    November 26, 2019 at 10:08 AM
  • Anu

    how to get connect anther gsm phone duration in sim800l in arduino

    November 28, 2019 at 9:33 PM
  • satya

    Hi sir. I tried sim 800l module interfacing to arduino uno and i connected as pre refereed circuit diagram but i connected DC-DC buck converter also in sim 800l module the signal was not defecting even buck-converter also connected and sim is also working please give replay.

    November 30, 2019 at 11:17 AM
    • Sharath
      • This GSM Module is 2G Only. So if you use 4G only SIM Cards like Jio, it will not work.
      • Make sure you have connected antenna properly.
      • Make sure you have given proper power supply (3.6V-4.2V) and the adapter with 2A DC Current is recommended.
      • Otherwise, the module might be cheap and cloned ones.
      December 12, 2019 at 10:23 AM
    • ekim

      i suggest you may use a lipo batery of phone that 3.7v output the gsm is easy to connect to a network

      February 12, 2020 at 1:27 PM
  • Jyothi

    hi sir,
    I want to send some data to server via GPRS modem with Pre shared keys ,I am using PUTTY terminal.How to setup TLS connection with Pre shared keys.?.please help me with this..
    https://stackoverflow.com/questions/59543440/sending-data-with-pre-shared-keys-to-server-via-sim800a

    January 1, 2020 at 3:08 PM
  • umar

    i want to receive sms and store its content like phone number date time and specially its content (message body) in variables up untill now i am able to receive sms from gsm module and display it on serial monitor by using AT+CMGR 25 and AT+CMGL after saving its content (message body) i want to conditional working on it.

    NEED HELP
    THanks in advance.

    January 21, 2020 at 3:37 PM
  • Pranjal Gurav

    Hello Sir,
    I am a student and I want to use dtmf for specific task and also want to play manu when call is auto answer, like a costumer care operation. It is for my college project.
    Can you help me Please.

    February 21, 2020 at 9:54 PM
  • Sara El Harrak Bennouna

    Hi Sir,

    I would like to ask you a few questions:

    1. If my phone number comes from Spain, which means that its dial is +34, shall I change this one to the one that’s already written in the code (+91xxxxxxxxx)?

    2. My SIM800L module has a light blinking, but didn’t achieve to know exactly how many times per second or how many seconds pass between each blink. What should I do if all hardware is ok, SIM card is charged with 5G internet connection and the blinking takes place each second?

    3. Can I use pins 2 and 3 on Arduino instead of 9 & 10 or 10 & 11? Those ones are already used for the connection to the NFC reader, and pins 5,6 and 7 are already used for the connection to the RGB led module.

    Thanks in advance and greetings from Lleida!

    April 9, 2020 at 10:21 PM
    • Sharath

      1. Yes the +91 is country code, you need to change yours.
      2. SIM800L Works with 2G Networks only. There are other modules available for 4G (Costlier). I didn’t see any 5G Modules yet in the market for DIY Purpose.
      3. Yes you can. Any free pins you can use as it uses softwareserial. But make sure to checkout the pinout as it wont conflict with SPI Pins or Libraries.

      June 11, 2020 at 8:16 AM

Leave a Reply

Back to Blog