How to use SIM800L GSM Module | Arduino | Send and Receive SMS

Introduction

There are actually a lot of GSM module available in the market but I personally recommend and prefer SIM800L due to its size and simplicity. It has a small footprint so it occupies a very small space. This is because SIM800L only provides the basic core of GSM. Meaning to say, you need to provide additional circuitry to use it but don’t worry I will show you the simplest way to use it.

To send SMS:

  1. Send AT+CMGF=1 <CR><LF>
    – this is to configure the GSM module to text mode
    CR – Cariage Return, ASCII character 13 or r
    LF – Line Feed, ASCII character 10 or n
  2. Sent AT+CMGS=”+ZZxxxxxxxxxx”<CR><LF>
    – this is for entering the sim number
    ZZ – is the country code
    xx – is the 10-digit mobile number
    CR – Cariage Return, ASCII character 13 or r
    LF – Line Feed, ASCII character 10 or n
  3. Wait for the ‘>’ reply from SIM800L before sending the next
  4. When the GSM replied with ‘>’, this is the time to send your message such as:
    “Hello from SIM800L”<CR><LF>
    Hello from SIM800L – is the SMS you want to send.
    CR – Cariage Return, ASCII character 13 or r
    LF – Line Feed, ASCII character 10 or n
  5. Send a CTRL+Z character or ASCII character 26.

To receive SMS:

  1. Send AT+CMGF=1 <CR><LF>
    – this is to configure the GSM module to text mode
    CR – Cariage Return, ASCII character 13 or r
    LF – Line Feed, ASCII character 10 or n
  2. Send AT+CNMI=1,2,0,0,0<CR><LF>
    – this is to configure the GSM module to forward via serial when SMS is receive.
    CR – Cariage Return, ASCII character 13 or r
    LF – Line Feed, ASCII character 10 or n

Video Demonstration

Source Code

 1
 2#include "SoftwareSerial.h"
 3SoftwareSerial mySerial(2, 3);
 4String cmd = "";
 5
 6void setup()
 7{
 8  mySerial.begin(9600);
 9  Serial.begin(9600);
10  Serial.println("Initializing...");
11  delay(1000);
12  mySerial.println("AT");                 // Sends an ATTENTION command, reply should be OK
13  updateSerial();
14  mySerial.println("AT+CMGF=1");          // Configuration for sending SMS
15  updateSerial();
16  mySerial.println("AT+CNMI=1,2,0,0,0");  // Configuration for receiving SMS
17  updateSerial();
18}
19
20void loop()
21{
22  updateSerial();
23}
24
25void updateSerial()
26{
27  delay(500);
28  while (Serial.available()) 
29  {
30    cmd+=(char)Serial.read();
31    if(cmd!=""){
32      cmd.trim();  // Remove added LF in transmit
33      if (cmd.equals("S")) {
34        sendSMS();
35      } else {
36        mySerial.print(cmd);
37        mySerial.println("");
38      }
39    }
40  }
41  
42  while(mySerial.available()) 
43  {
44    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
45  }
46}
47
48void sendSMS(){
49  mySerial.println("AT+CMGF=1");
50  delay(500);
51  mySerial.println("AT+CMGS="+639175291539"r");
52  delay(500);
53  mySerial.print("Hi! TechToTinker!");
54  delay(500);
55  mySerial.write(26);
56}

Call To Action

If you find article helpful, please kindly Subscribe to my channel. Thank you and have a good day.



Posts in this series



No comments yet!

GitHub-flavored Markdown & a sane subset of HTML is supported.