SIM800L tracking your IoT device

After a while testing the GPS NEO6 I ordered a new guy to play around with GSM connection and GPS at the same time. The sensor this time is the SIM800L, which basically is an interface between the SIM card and the Arduino Uno (could be any board, not Arduino Uno only).

The version used is the Arduino Uno, so everytime you see Arduino in the text I am talking about the Uno version.

For purpose of test I started using the Raspberry Pi (model B+) board but ended up with Arduino, the switch is given by the facility of send the skecth out to the Arduino. While in the Raspberry Pi you should wait till the board is up and running. Further tests can lead me back to the Pi, but for this post the examples will be on Arduino.

What you is going to see in this post:


The board used is the SIM800L without any specific breakboard or something like that. Newest versions of the SIM like SIM900 comes with a antenna and a bigger board.

Besides the board is needed to have a micro SIM card. In my case I had to use an adapter to transfor the nano SIM I have into the micro.



IMPORTANT: Make sure to have a SIM card with 2G, 3G or 4G anabled (you can test it plugin the SIM card on yout phone and try to access any web page), and have in hands the APN, the APN user and APN password.


This sensor requires just 4 wires to start with, but there is a gap in the voltage that it operates. The following table holds the pins where the wires should go to.

SIM800L Arduino Uno
NET Antenna connection
VCC 5v
RX 8
TX 9

To make it easier to understand, the following image illustrates how the wiring should be done.

SIM800L wiring

SIM800L Font:

Arduino Uno Font: Nooelec

If you are planning to use your device for a long time, it is good to mention that there is an resistor to add and deliver the 4.2v instead of 5v. For that check this repo and make sure to wire up using the resistor.

As this post has the goal to keep as simple as possible, I am not going to use the resitor.

Sketch (commands AT 101)

IMPORTANT 2: Here I assume that you can compile and run a scketch into the Arduino, if not, please find out how to to that and come back later.

Before we go any deeper on the libraries available out there, the proposal here is to upload a simple sketch to interact with the serial port. The reason behind it is that the SIM800L handles AT (instructions to command a modem) commands into the SIM card, and in order to understand what is going on we need to understand the AT commands first. The following sketch reads and writes to the serial port.

#include <SoftwareSerial.h>

SoftwareSerial gsm(9, 8);

void setup() {



   Serial.println("Ready to receive commands");

void loop() {


Once we have the sketch up and running in our Arduino, is time to understand the AT commands. The first thing to send trhough the serial interface is the command AT. This is the most basic command to see if the sensor is up and running, if everything is correct an OK is printed back.

AT command

The next step is to understand what is required to setup the GPRS mode in our SIM card. For that we are going to rely a lot on the SIM800L official documentation available here.

Enabling GSM location

By default the SIM cards doesn’t come with any configuration, we should setup manually for every action we would like to do with it. To enable the tracking (that is our goal) we should do the following:

  1. Enable the GSM location mode
  2. Authenticate with the APN
  3. Request the data regarding the SIM location

To enable the GMS location mode is a matter of sending the correct AT command through the serial.


Next step is to authenticate the APN, we do that in four steps, first setting the APN, followed by the username, the password and finally activate the bearer. Each command should be executed separately and before execute the next one, macke sure to get an OK response from the serial.

There is an website with the possible APNS around the world, if you don’t know which one is yours, access this link

AT+SAPBR=3,1,"APN","{here goes your APN}"

After the APN replace the text {here goes your APN} with your APN provider.

AT+SAPBR=3,1,"USER","{here goes your username}"

After the USER replace the text {here goes your username} with your APN username (sometimes it will be empty, so just leave as it is).

AT+SAPBR=3,1,"PWD","{here goes your password}"

After the PWD replace the text {here goes your password} with your password (sometimes it will be empty, so just leave as it is).


By now the led sensor should start blinking more frequently than it used to, it indicates that a connection has been stablished and now you can communicate freelly with the GSM network. To guarantee that everything is working as expected, there is one command to retrieve the current IP in use by the SIM card.


The command response should be something similar to the figure below, other than that or only indicates that something went wrong.

Finally we are ready to request the latitude and longitude to know where our SIM card is in the world. As you may have imagined it is done through an AT command as well.


It should return an string containing the latitude, longitude, current date, and current time. The figure below illustrates the response receive in the serial monitor.

Response from SIM800L after requireing the current location

Edit 04/03/2018

During a few tests with the SIM, it turns out that the accuracy in the latitude and longitude is not so good as expected. Sometimes it gives the same location even with 10 meters of change.


Tracking with GPS NEO 6

SIM (Subscriber Identity Module)

SIM Card types

Arduino Serial

AT commands

SIMCOM AT commands PDF

APN providers worldwide

About the author Articles Calendar Conferences and Talks Newbie's guide Resources Tests