HUM: SIM800 GSM/GPRS MODULE-Uncategorized

You are a beginner with Dasduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by soldered where you will find all you need in order to begin working with your favorite module. Tutorials include technical characteristics, work principles, instructions on how to connect the module with Dasduino and the basic code. Everything else is left to your imagination.


In this tutorial, we will describe the GSM/GPRS module SIM800L, which is used to make and receive calls, messages and connect to the Internet through the GSM network. The module provides numerous possibilities because using it, we can set up projects connected to the Internet anywhere, without being dependent on home ADSL Internet or WiFi network. Within the tutorial, we will briefly describe how the module works and describe the process of making calls, sending messages, and connecting to the Internet.


This module uses GSM technology and it connects to the Internet, sends messages or makes calls using that same technology. GSM is a network technology mostly used for mobile communication. Within the GSM network, there are several units that enable communication jointly: the mobile station (our GSM module or mobile phone), the base station subsystem, and the network subsystem. The mobile station (MS) consists of a GSM device and a card known as the SIM card. The SIM card is device-independent, which means that the SIM cardholders can use GSM services on any device using their SIM card. It contains an IMSI number that identifies the user to the system. The mobile station connects to the nearest base station (transceiver) and exchanges data with it. The base station subsystem consists of a base transceiver station and a base station control section, but it also contains transceivers that are connected to mobile stations. The network subsystem contains a mobile service switching center that works like a regular switching node and registers users, authenticates, directs calls, etc. This system consists of several units that perform all the necessary functions and further connect to a fixed telephone network.

Our module is a mobile station that contains a SIM card and takes care of connecting to the base station, while it communicates with Dasduino via serial communication and uses the AT commands using which we control the module.



The module uses only 2 pins as it communicates via serial communication. Since we use serial communication and pins 0 and 1 to communicate with our computer and to program our microcontroller, we need to use the SoftwareSerial library and the pins we define ourselves to communicate with our GSM module. To power the module, we must use an external power supply because Dasduino cannot deliver the amount of current required by the module. The module can max up to 2A of current while connecting to the Internet, so we need to use the power supply that can provide as much current. For the power supply, we must make sure that the voltage does not exceed the value of 4.4 V and that it is not below 3.7 V, and to achieve this, we can use a step-down converter which we will adjust to 4.2 V. We can power supply the module using the LI-po battery whose rated voltage is 3.7V and the maximum voltage of a fully charged battery is 4.2V which is below the maximum module voltage. The scheme that uses the battery for power supply and the scheme that uses the source with a step-down converter is shown in the images below. The serial communication pins used in the schematics and in the example code are 9 for the RX line and 10 for the TX. Since the module is not 5V tolerant, the RX line is connected via a voltage divider, which is made up of 10 kOhm resistance and 5.6 kOhm.


We need to use the SoftwareSerial library to communicate with the module, but we do not need to download it because we already have it in the Arduino IDE.
The code example shows us how to use AT commands to make a call, send a message, and connect to the Internet. You can find the list of all AT commands here.
In the example, we choose what we want via Serial monitor. To call the number you have entered, use P, to answer the call J, and to cancel the call K. To send a message, we use S and to connect to the Internet and visit the desired web page, we use I.

//including the SoftwareSerial library for serial communication with the GPRS/GSM module
#include <SoftwareSerial.h>
String unos;// the string to which we save the text from Serial monitor
String str; // the string to which we save the text returned from the GSM module
String poruka="The message sent from the SIM800L module"; //the message we send when we call the sms function
String web=""; //the web page we visit when we call the internet function
String number="+385xxxxxxxxx"; //the number we call using the call function or to which we send the message (enter the number you want)
//the variables used in the functions
int br;
int mult;
char buf[10];
int flag;
//our library constructor, establishing serial communication on pins 9 and 10
SoftwareSerial gsm(9,10); // RX, TX
void setup() {
  Serial.begin(9600);//starting serial communication (9600 baud)
  Serial.println("GSM SIM800L initialization");
  gsm.begin(9600);//starting serial communication with the GSM module
  delay(500);//half a second pause
  gsm.println("AT");//checking whether Croduino communicates with the GSM module
  //the function that sends commands from the Serial monitor to the GSM module, and from the module to the Serial monitor
  Serial.println("Signal strength (0-31):");
  gsm.println("AT+CSQ");//the command for checking the signal strength
  gsm.println("AT+CREG?");//checking whether we are registered on the network (1-home network, 5- roaming network)
  Serial.println("Receiving messages");
  gsm.println("AT+CNMI=1,2,0,0,0");//the command that allows receiving messages with the GSM module
void loop() {
//the function we call when we want to connect to the Internet and visit a desired web page
void internet(){
  //setting the APN for our network ( A1>>> internet, T-Mobile>>>, you can find this information online for the desired operator (operator APN)
  //setting the web page we connect to
  //reading the web page and displaying data on the serial monitor (for the example web page it will display: It works fine!)
//the function for calling a desired number
void call(){
    gsm.println("ATD+ "+number+';');
    Serial.println("calling the number: " + number);
//the function for sending a message to the number we have entered
void sms(){
  //setting the module to the mode for sending messages
  gsm.print("AT+CMGS=");// the command using which we set the number we will send a message to and entering the message
  gsm.write(26);//ASCII value ctrl+Z, finish entering the message and send it
//the function that sends commands from the Serial monitor to the GSM module, and vice versa
  void updateSerial()
  delay(1000);//one second pause
  while (Serial.available())//as long as we have something in the Serial buffer, we are in the loop
    unos=Serial.readString();//saving the text from the Serial monitor to the unos String
    //checking whether the input from the Serial monitor matches the certain character, and according to that, we call the desired functions
      //calling the Internet function
      unos="";//deleting the value from the unos String
      internet();//calling the Internet function 
      unos="";//deleting the value from the unos String
      sms();//calling the function for sending the message
      unos="";//deleting the value from the unos String
      call();//calling the function for making the call
      unos="";//deleting the value from the unos String
      gsm.println("ATH");//end the call
      Serial.println("call ended");
      unos="";//deleting the value from the unos String
      gsm.println("ATA");//the answering command 
   //if the unos String was not any of the previous characters, we forward it to the GSM module
  //as long as we receive something from the GSM module, we are in the loop
  str=gsm.readString();//saving the text from the GSM module to the str String
  Serial.println(str);//forwarding the text to the Serial monitor
  //further code requires a certain command it returns to the GSM module while displaying the web page
  // from the return command, we take a number for the following command, so we must have this part
  //checking whether there is "+HTTPACTION:" within the str String, and if there is, we return the index about where it begins within the str String
  // if there is no such text, the return value is -1
  // checking whether the flag is above 0, i.e. whether we have had the desired text within the str Stringa st
    str.remove(0,flag);//deleting the text from the str String from the beginning(0) to the index flag (where the desired text begins)
    flag=str.indexOf("200,");//searching for the index in the String where the number is 200
    str.remove(0,flag);// deleting everything from the String until we reach the number 200
    str.toCharArray(buf,10);//turning String to the character field
    str="";//emptying the str String
    mult=1;// the variable for tens, hundreds and thousands
    br=0;// the variable to which we save the number we will use later
    for(int i=0;i<10;i++){ 
      // searching through the buf character field, looking for a comma
        //if there is a comma, we save the number behind it to the br variable
        // by saving each decimal separately 
      br += (buf[i+3] - '0') * mult;
      mult *= 10; // we use the mult to get tens, hundreds and thousands
      br += (buf[i+2] - '0') * mult;
      mult *= 10; // we use the mult to get tens, hundreds and thousands
      br += (buf[i+1] - '0') * mult;
      mult *= 10; // we use the mult to get the tens, hundreds and thousands