Home / Arduino / Arduino SIM800L Tutorial

Arduino SIM800L Tutorial

The SIM800L is a cheap and portable GSM breakout board with all the capabilities of the larger SIM900 shields. In this Arduino SIM800L tutorial, I will help you get started with this nifty device. Sending and receiving texts with your Arduino have never been easier!

Arduino sim800L breakout board

SIM800L Introduction

Here are the features of the SIM800L breakout board:

  • 2G quad-band @ 850/900/1800/1900 MHz
  • Receive and make calls using the speaker and microphone outputs
  • Receive and send SMS
  • Connect to the Internet via GPRS
  • Listen to FM radio broadcasts
  • Accepts AT Commands

Go to SIM900 Tutorial if you have that module instead

This SIM800L breakout board is ideal for projects that needs to save space. In fact, this is the one I used when I created my own cellphone. This board draws a maximum of 2 A with an input voltage of 3.7 V to 4.2 V. This means you must not connect its pins directly to a 5 V Arduino! It doesn't even run on 3.3 V.

SIM800L Pinout

The solution is either to use a regulator or just have the SIM800L draw from a Li-Po (cellphone) battery. That's what I did and it works!

Antennas are essential for this kind of module especially if your project is indoors. Without an antenna, there would not be enough transmitting power for the SIM800L to perform GSM services such as calls and SMS. I decided to purchase this one:

SIM800L Antenna

I found this antenna to be more effective than the one that comes with the SIM800L module by default:

As for the code, we can use Adafruit's FONA library. Download it here and install it on the Arduino IDE.

Once the library is installed, you can now explore the features of the SIM800L. Let's start with sending SMS using this wiring diagram:

Arduino SIM800L Connection

SMS Sending

The FONA library has a simple sendSMS() function that accepts the number and message as parameters and returns true if the message was sent through the network successfully. Here's an example code:

Let's start with this:

This part declares that the RX, TX and RST pins of the SIM800L must be connected to pin 2, 3 and 4 of the Arduino.

The lines above assigns the RX and TX pins as software serial pins. This is done so that the Arduino's hardware serial port remains to be used with the serial monitor. The FONA object is then initialized with the RST pin as parameter. The readline() declaration is needed for that last function you see on the full sketch. This function is a nifty way to read inputs from the user via the serial monitor.

Check out my GPRS tutorial to learn how to use the SIM800 module to connect to the Internet

The SIM800L is checked using the following sequence:

If "FONA is OK" appears in your serial monitor screen then the SIM800L is now ready to accept commands!

This part is the SMS sending part. The code asks for the recipient's number first then asks for the message. If the message is successfully sent, a "Sent!" appears on the serial monitor. Otherwise, a "Failed" appears.

Reading SMS

To read SMS stored in the SIM card, we just change the portion of the code above with this:

The function getSMSSender() returns true and places the SMS sender number to the replybuffer, while the readSMS() function returns true and places the SMS to that same buffer.

You also need to add the following functions for reading sms:

The readnumber() function returns the number of the sender of the SMS you are reading. The readBlocking() function is necessary to avoid reading the serial port when nothing arrives.

Making a Call

To make a call, we must attached a speaker to the SPKRP and SPRKRN terminals of the SIM800L and an electret microphone to the MICP and MICN terminals. Then we can replace the portion of the code above with this:

Calling a number is done using the callPhone() function. This function returns true if the call is successfully made. The number to be called is the parameter for this function.

Receiving a Call

Receiving a call is a bit more complicated because whatever the Arduino is doing must be interrupted to acknowledge the call. This is what the example IncomingCall sketch does:

The first thing that is noticeable is the change in the pin assignments for RX, TX and RST. This is because the D2 pin of the Arduino is the default interrupt pin. The SIM800L uses this pin to interrupt the Arduino whenever there is an incoming call. Thus, the D2 pin and the SIM800L's RING pin (above the DTR pin, if its not visible in yours) must be connected.

There's also an option to enable or disable Caller ID notification. Cool.

There are other options in the FONA library including reading the signal level of the GSM network, scanning FM networks, and enabling GPRS to connect to the Internet! I'll explore these features on my next post so stay tuned!


Buy Chip SIM800L Modules at AliExpress

Check Also

How to Use the MQ-7 Carbon Monoxide Sensor

The MQ-7 carbon monoxide sensor is especially designed to be sensitive to carbon monoxide (CO) …

17 comments

  1. Hello,thanks for your tutorial.
    I have a problem whit my madule, when I upload this code(for sending sms) in serial monitor appear "couldnt find fona"what is the problem?

  2. When I change the portion of the code to receive SMS I get this error "readnumber" was not declared in this scope, that's from uint8_t smsn = readnumber();

  3. hi sir. I am new in this sim800l module.. Can I use this module in Philippines?

    • Hello Gino,

      Yes it is usable in the Philippines. In fact, I am a Filipino using this device in the Philippines 🙂

      • char sendto[21], message[141];
        flushSerial();
        Serial.print(F("Send to #"));
        readline(sendto, 20);
        Serial.println(sendto);

        sir in this part, 11 numbers lang po yung dapat na iinput.
        tama po ba to ?

        char sendto[12], message[141];
        flushSerial();
        Serial.print(F("Send to #"));
        readline(sendto, 11);
        Serial.println(sendto);

  4. Hello dear,
    I am Reshad, from Bangladesh. I baught a SIM 800L and Arduino UNO R3. But I can not run SIM 800L. Would you please help me?

    Actually I want to make a little project. Like on/off a relay by sending SMS or DTMF system. Please help me. Thanks.

    • Hello Reshad,

      By "I can not run SIM 800L", do you mean you aren't getting any response from the module? Have you tried using the library I suggested in this post?

      • Thanks a lot for your kind reply dear. My SIM 800L run now. But serial monitor doesn't response. How can I do?? :-/

        • I am using this code as it is and wire connect SIM800L TXD, RXD, RST to UNO 3,2,4 pin. But serial monitor no response. Would you help me plz.

          #include
          #include "Adafruit_FONA.h"

          #define FONA_RX 2
          #define FONA_TX 3
          #define FONA_RST 4

          char replybuffer[255];

          SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);

          Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

          uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

          void setup() {
          while (!Serial);
          Serial.begin(115200);
          Serial.println(F("FONA basic test"));
          Serial.println(F("Initializing....(May take 3 seconds)"));
          fonaSS.begin(4800);
          if (! fona.begin(fonaSS)) {
          Serial.println(F("Couldn't find FONA"));
          while (1);
          }
          Serial.println(F("FONA is OK"));

          char sendto[21], message[141];
          flushSerial();
          Serial.print(F("Send to #"));
          readline(sendto, 20);
          Serial.println(sendto);
          Serial.print(F("Type out one-line message (140 char): "));
          readline(message, 140);
          Serial.println(message);
          if (!fona.sendSMS(sendto, message)) {
          Serial.println(F("Failed"));
          } else {
          Serial.println(F("Sent!"));
          }
          }

          void loop() {}

          void flushSerial() {
          while (Serial.available())
          Serial.read();
          }

          uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout) {
          uint16_t buffidx = 0;
          boolean timeoutvalid = true;
          if (timeout == 0) timeoutvalid = false;

          while (true) {
          if (buffidx > maxbuff) {
          break;
          }

          while(Serial.available()) {
          char c = Serial.read();

          if (c == '\r') continue;
          if (c == 0xA) {
          if (buffidx == 0) // the first 0x0A is ignored
          continue;

          timeout = 0; // the second 0x0A is the end of the line
          timeoutvalid = true;
          break;
          }
          buff[buffidx] = c;
          buffidx++;
          }

          if (timeoutvalid && timeout == 0) {
          break;
          }
          delay(1);
          }
          buff[buffidx] = 0; // null term
          return buffidx;
          }

      • Yes I got SIM800L response. Now I need code to operate a relay by SMS and DTMF.

  5. I have the GSM800L you described above. What did you use for an antenna? I got a sim not registered error when i run get network status of ADAFRUIT FONA library. Can you help? I assumed it was an antenna error but i cant seem to fix it.

  6. whether the part

    Serial.print(F("Send to #"));
    readline(sendto, 20);
    Serial.println(sendto);
    Serial.print(F("Type out one-line message (140 char): "));

    should i change with the destination phone number and the message?

    • Hi Danny,

      No, you can't insert a number there unless other modifications are made. That code is for sending messages via the IDE's serial monitor. Thus, the number should be printed on the monitor rather than in-code.

Leave a Reply

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