In this project we will learn about IoT using GSM Module. We will use SIM900/800 GSM Module with Arduino and send the DHT11 Sensor data to Thingspeak Server.
Overview
Nowadays we use ESP8266 or ESP32 or any other wifi Modules to send any sensor data to the Internet wirelessly. Hence Wifi comes into action and thus we need Wifi Connection for wireless communication with any server. But the disadvantage of using Wifi is, it is not available everywhere. The wifi signal is limited to certain locations and to a certain range up to a few meters. For example, in order to use IoT Connectivity and to get data from the farmer’s fields, we can’t rely on Wifi due to unavailability. Similarly forest, river zone, mountains are the areas where wifi connection is not available.
So, GSM GPRS is the only alternative left as per the present scenario and current technology. GSM GPRS Module allows you to add location-tracking, voice, text, SMS, and data to your application. The big advantage of GSM/GPRS Connectivity is, it covers a wide area and signal/connectivity is available almost everywhere.
So in this project, we will learn about the Internet of Things using GSM GPRS Module, i.e Cellular IoT. We will take SIM900A as a reference GSM GPRS Module and Interface it with Arduino Board. We will sense the surrounding humidity and temperature using DHT11 Humidity/Temperature Sensor. The humidity & temperature data will be sent to Thingspeak server using AT Commands for GSM Module. ThingSpeak server is an open data platform and API for the Internet of Things that enables you to collect, store, analyze, visualize, and act on data from sensors. So let us learn all about GSM Module with Thingspeak & Arduino.
You can check one of our posts related to a similar system:
1. Arduino SIM: Cellular Connectivity Service for Arduino IoT Cloud
2. Send SIM800/900 GSM/GPRS Data to Thingspeak with STM32
If you want to send the data in JSON format using any API Server you can check our post here: SIM900/800 HTTP post request in JSON Format with Arduino
Bill of Materials
Following are the components required for learning the Cellular IoT project. All the components can be easily purchased from Amazon. The component purchase link is given below.
| S.N. | Components | Quantity | Purchase Links |
|---|---|---|---|
| 1 | Arduino UNO Board | 1 | Amazon | AliExpress |
| 2 | GSM Module SIM800/900 | 1 | Amazon | AliExpress |
| 3 | DHT11 Sensor | 1 | Amazon | AliExpress |
| 4 | 12/9V Power Supply | 1 | Amazon | AliExpress |
| 5 | Connecting Wires | 10 | Amazon | AliExpress |
| 6 | Breadboard | 1 | Amazon | AliExpress |
SIM900A GSM/GPRS Module
The SIM900A is a readily available GSM/GPRS module, used in many mobile phones and PDA. The module can also be used for developing IoT (Internet of Things) and Embedded Applications. It works on frequencies 900/ 1800 MHz. The Modem comes with an RS232 interface, which allows you to connect PC as well as a microcontroller with RS232 Chip(MAX232). The baud rate is configurable from 9600-115200 through AT command. The GSM/GPRS Modem is having internal TCP/IP stack to enable you to connect with the internet via GPRS. It is suitable for SMS, Voice as well as DATA transfer applications in the M2M interface.
The onboard Regulated Power supply allows you to connect a wide range of unregulated power supply. Using this modem, you can make & receive audio calls, Send & Read SMS, GPRS Internet, etc through simple AT commands.
SIM900A GSM/GPRS Modem Fetures
1. Input Voltage: 12V DC
2. Supports MIC, Audio Input & Speakers
3. Dual-Band GSM/GPRS 900/ 1800 MHz
4. RS232 interface for direct communication with computer or MCU kit
5. Configurable baud rate
6. Wire Antenna ( SMA connector with GSM Antenna Optional )
7. SIM Cardholder
8. Built-in Network Status LED
9. Inbuilt Powerful TCP/IP protocol stack for internet data transfer over GPRS
01. DATA GPRS: download transfer max is 85.6KBps, Upload transfer max 42.8KBps
Circuit/Connection between GSM Module Arduino & DHT11
Here is a circuit diagram for interfacing SIM800/900 GSM Module with Arduino & DHT11 for Sending data to Thingspeak Server. The connection is fairly simple as shown below.
SIM800/900 is a UART Module. We use the Software Serial command for Serial Communication. So, connect its TX & RX Pins to Arduino pin 2 & 3 respectively. Supply the GSM Module with 9V/12V Power supply. Similarly, connect the VCC & GND Pin of DHT11 Sensor to Arduino 5V & GND. Connect its output pin to A0 of Arduino.
Setting up Thingspeak
ThingSpeak provides very good tool for IoT based projects. By using ThingSpeak site, we can monitor our data and control our system over the Internet, using the Channels and web pages provided by ThingSpeak. So first you need to sign up for ThingSpeak. So visit https://thingspeak.com and create an account.
Then create a new channel and set up what you want. The tutorial in the video below. Follow the video for more clarifications.
Then create the API keys. This key is required for programming modifications and setting your data.
Now click on channels so that you can see the online data streaming
Source Code/Program
The source code/program to Send GSM SIM800/900 GPRS Data to Thingspeak with Arduino is given below. No libraries are required. You can simply copy the code and upload to the Arduino Board.
But before that, you have to make two changes in the code. Change your APN Services first. In my case, I am using Airtel SIM and the default APN for Airtel is airtelgprs.com. You can check your SIM APN from your google or cellular provider.
You also need to make changes to the API key from thingspeak.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
#include <SoftwareSerial.h> SoftwareSerial gprsSerial(2,3); #include <String.h> #include <DHT.h> #define DHTPIN A0 DHT dht(DHTPIN, DHT11); void setup() { gprsSerial.begin(9600); // the GPRS baud rate Serial.begin(9600); // the GPRS baud rate dht.begin(); delay(1000); } void loop() { float h = dht.readHumidity(); float t = dht.readTemperature(); delay(100); Serial.print("Temperature = "); Serial.print(t); Serial.println(" °C"); Serial.print("Humidity = "); Serial.print(h); Serial.println(" %"); if (gprsSerial.available()) Serial.write(gprsSerial.read()); gprsSerial.println("AT"); delay(1000); gprsSerial.println("AT+CPIN?"); delay(1000); gprsSerial.println("AT+CREG?"); delay(1000); gprsSerial.println("AT+CGATT?"); delay(1000); gprsSerial.println("AT+CIPSHUT"); delay(1000); gprsSerial.println("AT+CIPSTATUS"); delay(2000); gprsSerial.println("AT+CIPMUX=0"); delay(2000); ShowSerialData(); gprsSerial.println("AT+CSTT=\"airtelgprs.com\"");//start task and setting the APN, delay(1000); ShowSerialData(); gprsSerial.println("AT+CIICR");//bring up wireless connection delay(3000); ShowSerialData(); gprsSerial.println("AT+CIFSR");//get local IP adress delay(2000); ShowSerialData(); gprsSerial.println("AT+CIPSPRT=0"); delay(3000); ShowSerialData(); gprsSerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");//start up the connection delay(6000); ShowSerialData(); gprsSerial.println("AT+CIPSEND");//begin send data to remote server delay(4000); ShowSerialData(); String str="GET https://api.thingspeak.com/update?api_key=O13AOCHYYNU2LQ19&field1=" + String(t) +"&field2="+String(h); Serial.println(str); gprsSerial.println(str);//begin send data to remote server delay(4000); ShowSerialData(); gprsSerial.println((char)26);//sending delay(5000);//waitting for reply, important! the time is base on the condition of internet gprsSerial.println(); ShowSerialData(); gprsSerial.println("AT+CIPSHUT");//close the connection delay(100); ShowSerialData(); } void ShowSerialData() { while(gprsSerial.available()!=0) Serial.write(gprsSerial.read()); delay(5000); } |
Results & Observations
Once the code is uploaded to Arduino UNO Board, the module will start responding. You can open the Serial Monitor and see the following responses there.
Similarly, you can open the Thingspeak private view and see the temperature and humidity logged data there.
So this is how you can Send GSM SIM800/900 GPRS Data to Thingspeak with Arduino.
If you want to send the data in JSON format using any API Server you can check our post here: SIM900/800 HTTP post request in JSON Format with Arduino















21 Comments
excuse me sir, i wanna ask about this line :
gprsSerial.println((char)26);//sending
what is (char)26 mean?
thanks before
i have connected the GSM modem to my PC and then i am send commands to the GSM Modem using terminal Software.
This is what i am sending:
AT
AT+CPIN?
AT+CREG?
AT+CGATT?
AT+CIPSHUT
AT+CIPSTATUS
AT+CIPMUX=0
AT+CSTT=”www”
AT+CIICR
AT+CIFSR
AT+CIPSTART=”TCP”,”api.thingspeak.com”,”80″
AT+CIPSEND
GET http://api.thingspeak.com/update?api_key=X4L3QD19Q7YSLK3J&field1=125
#026
When i use GET instruction and then send 026 i get SEND OK from the modem and then CLOSED but thingspeak channel is not updated.
Please help
T
oni the line means you are terminating the message being sent. It basically tells the GSm that the message ends here hence executing the send command
I have loaded the code to my arduino uno. Everything seems to work except that my thingspeak channel is not updating temperature and humidity data. Pease guide me on the issue.
Add some delays between the thingspeak data sending command in the code. It should fix the issue
Hi,
Thanks on your reply. The data on my channel are now updating. The data are updated every 1.5 minutes (about 88 seconds). Is it possible to have data updated every 60 seconds? What part in the code should I change? Thanks again for the help.
Hi, I noticed that the GSM module needs an external power supply rather than being powered from the arduino board. What sort of current does the GSM module draw? I was hoping to power this from a battery and place the node in a remote area with small solar panel to trickle feed the battery.
The power supply varies depending upon the type of GSM Module used. The SIM800/900 GSM Module requires more than 1.5A of current. Hence 9V, 2A supply is good for the module.
Thanks for the reply. I have got it up and running now but it seems to be updating things speak at random intervals with some gaps as big as 25 minutes. Is this because the delays are not long enough and it times out before making connection?
Hi, I have the same issue. Can you please confirm exactly where this extra delay should be?
delay between each and every AT Commands should be increased.
Hi, I have uploaded the same code and thingspeak updates but at random intervals. What delays should I adjust to make sure I get data sent everytime the program runs. I have ‘send Ok’ back but thingspeak does not update and it tends to randomly update now and then.
#026 command is used for termination, so it varies from terminal program to program. the following terminal it will work.Take a try
https://sites.google.com/site/terminalbpp/
i am having +CME ERROR:50 , +CME ERROR:53 and +CME ERROR:58
Hello, is there a way to get the http status from ThingSpeak ie the 200 code ThingSpeak sends back when the post has been successful? I am using an A9 GSM/GPRS module with an ESP32 board to receive LoRa packets from my nodes and forward them to ThingSpeak. Thanks, Steve.
can we post data to a google sheet with similar code?
I am also facing the same issue. did you find a solution ??
Thanks for the well-explained tutorial. I was wondering if the same project can be implemented using esp32. what will be the necessary changes in the code in term of communication between esp32 and sim800L.
please do like this http://api.thingspeak.com/update?api_key=X4L3QD19Q7YSLK3J&field1=125 \r\n\r\n ctrl+z
Hello frnds, I’m sending data SIM900A GSM/GPRS to AWS IOT with esp32 but data not sending. can you solve issue?
Hi, how can I integrate two other sensors? For weight and humidity?Thanks