Microcontroller Tutorials

Arduino, Raspberry Pi, PIC, Beaglebone Resources

Sending Data via SIM800L GPRS to ThingSpeak

This project demonstrates how to send data to ThingSpeak using a SIM800L breakout board. The data will be coming from a BMP085 atmospheric pressure sensor and will be using the SIM800L GPRS connection to publish this data to ThingSpeak.

Setting up ThingSpeak

First, you need to sign-up for a free account on ThingSpeak. After successfully signing-up, you will be prompted to create a channel. Here is a screenshot of the channel I created:

ThingSpeak Example Channel

Here I only have one field named Atmospheric Pressure. You can have up to 8 fields.

Once the channel is created, go to the API keys tab:

ThingSpeak API Keys

On the lower right, you have the API requests fields. Copy the URL for “Update a Channel Feed”. For example, mine is:

This is the url used to update data on the channel. The last value on the url is the value to be sent to the channel. Here it says zero.

You can paste the url above on your browser and change the last number. For example, I paste this url:

When I go see the Private View tab, the chart has now been updated:

ThingSpeak Updated Chart

Using Putty for Testing

Of course, we will not be using a browser to update the channel on ThingSpeak. We need to create HTTP requests via GPRS. But before that, we must know the correct HTTP request. For that we can simulate using Putty.

Open Putty, select Raw connection type and use api.thingspeak.com for Host Name and 80 for Port:

Putty ThingSpeak Settings

Open the session and type the following:

Press enter three times; The Putty terminal window should close itself.

After that, check the Private View tab again on ThingSpeak. The chart should now be updated:

ThingSpeak Updated Chart with Putty

The line drops from 100 to almost 0. This is because the data value written using Putty is 2.8.

Sending Data via GPRS Connection with SIM800L

Now that we’ve confirmed that the HTTP request works, we start using an Arduino and SIM800L. I will still be using Adafruit’s FONA library just like my other SIM800L articles. Also, since I’m using the BMP085, I used Adafruit’s library as detailed in my BMP085 tutorial.

Wiring Diagram

This is how I connected the Arduino, SIM800L and BMP085:

SIM800L TX D8
SIM800L RX D9
SIM800L RST D7
SIM800L VCC 3.7V BAT
SIM800L GND 3.7V GND / Arduino GND
BMP085 SDA A4
BMP085 SCL A5
BMP085 VCC Arduino 3.3V
BMP085 GND Arduino GND
Arduino 5V 3.7V BAT+

Here’s the Fritzing diagram:

SIM800L ThingSpeak Fritzing Diagram

Arduino Sketch:

The sketch follows a specific sequence to be able to send data to ThingSpeak successfully. First, the SIM800L must be turned on. This is checked here:

If the SIM800L is not connected, the sketch goes to the while(1) loop and will not proceed.

Next, we check if the BMP085 is connected:

Similarly, the sketch will not continue down if there is no BMP085 connected.

Next, we must make sure the SIM800L is connected to the network. I created a loop that checks the network status until it is registered to the home network:

When the SIM800L is now connected to the home network, it’s time to turn on GPRS:

Again, this is looped to make sure that GPRS is on before proceeding.

Inside the loop() function, the pressure data is read and then converted to char array:

The dtostrf() function accepts the double number, whole number precision, fraction precision and the char array to which the converted value is stored.

Next, the pressure value is concatenated to the API URL:

To make an HTTP request, we use the HTTP_GET_start function:

The http_cmd is a char array that contains the API URL and the pressure value. Statuscode is an integer that stores the server response and length is the length of the response. I placed this function inside a loop:

The string Success! Is printed on the serial monitor when a status code of 200 is received, which is the OK status.

The project continues to send data to the ThingSpeak server unless the GPRS connection is cut off.

Here’s a video of the project:

I hope this project is useful to you! Please drop a comment below!

28 thoughts on “Sending Data via SIM800L GPRS to ThingSpeak

  1. Can i use SIM900A gsm module instead of sim 800L module and what are the changes which i have to do regarding this.Please reply as soon as possible

  2. Hello there Roland. Nice tutorial. I wanted to ask how did you add the APN of your SIM card. Did you add it in the adafruit fona library. Will appreciate your response

  3. So this here is a typical fraud. How you send data from 5 v uart to 3.3 v uart? if you go on sim800 l datasheet you will se that it only receives 3.3 v uart communication. Its more than miracle how you achieved that.

    1. Hi,

      There's no miracle actually. If you looked at my diagram, you'll see that I'm using a 3.7 V battery, so the Arduino here is not really producing 5V out of its UART.

  4. Can this program work on the simcomm 5320e for sending a post request to a python API?
    If we modify Http get start() to Http post Start() according to the fona library

  5. Hi Roland,

    Thank you for the tutorial!

    I am using BME 280 sensor instead of DHT. I am sending the data to my thingspeak channel.
    Although I am not able to get my GPRS working.

    Here is my serial monitor response.

    Failed to turn on GPRS
    Trying again...
    ---> AT+CIPSHUT
    AT+CGATT=1
    AT+SAPBR=3,1,"CONTYPE","GPRS"
    AT+SAPBR=3,1,"APN","Vodafonemobileconnect"
    AT+CSTT="Vodafonemobileconnect"
    AT+SAPBR=1,1
    <--- ERROR

    The code is stuck inside the while loop.
    I am sure there is no power supply issue, because I can connect my GPRS using the AT commands, but I want to try using Adafruit fona library.

    Also, an interesting happens after I let the code run for some time.
    The LED on the sim800L starts to blink at a faster rate( like when it is connected to the GPRS)

  6. Great thanks. I tried this project and was successful. Very very thank you. Although I edited my way but this project helped me to understand. Thanks again.

  7. hi man, thank you for this great work it was very helpful for me.
    but I've faced a problem
    i got this error
    ---> AT+HTTPTERM
    AT+HTTPINIT
    AT+HTTPPARA="CID"
    AT+HTTPPARA="UA"
    AT+HTTPPARA="URL"
    AT+HTTPACTION=0
    AT+HTTPREAD
    <--- OK
    Failed!
    Trying again...
    why is this happening?
    when I remove the https:// for thingspeak api url the channel get a single data every 3 minutes with an error in serial
    please help me, and thanks alot

  8. Hi,

    Can I use my own server to show data using mysql?
    I have created a script like website.com/update.php?field1=11&field2=22
    Working fine in url bar I can see data in mysql. But in arduino not working.

    Can you help?

    1. I am not sure what you want here but it looks like you want to issue POST commands using Arduino. I suggest you use HTTP requests which can be inserted as string in an arduino sketch with internet functions. This is an example request:

      POST update.php HTTP/1.1
      User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
      Host: website.com
      Content-Type: application/x-www-form-urlencoded
      Content-Length:
      Accept-Language: en-us
      Accept-Encoding: gzip, deflate
      Connection: Keep-Alive

      field1=11&field2=22

    1. Hi,

      Is your SIM good if inserted in a phone? If it is, it might be a power problem. Make sure you use the recommended power supply for the module.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.