In this post we are going to learn step by step how to upload sensor data to Thingspeak server and visually analyze the data in real-time. By the end of this article you will be able to upload any kind of sensor data to Thingspeak IoT platform using (GPRS) GSM module – SIM 800 / SIM 900.
We will see:
- Quick overview: What we are going to do?
- What is Thingspeak IoT analytics Platform?
- What is API Key?
- How to Sign up for Thingspeak and get API Key
- What is APN?
- Block Diagram
- Circuit Diagram
- Program code
- Why we are using GSM instead of ESP8266?
- How much GPRS data will be consumed?
- Prototype Image
- How to operate this circuit
Quick overview: What we are going to do?
- We will be sending temperature and humidity data of your surroundings to thingspeak platform where you can store, analyse and visualize the data using graphs and much more.
- We will be using DHT11 sensor and GSM modem for accessing GPRS so that we can send the data to the server and Arduino will act as the brain of the project.
- Two graphs will be generated on Thingspeak platform as we are sending only two data: temperature and humidity.
- The data on the thingspeak will be updated every 15 seconds.
What is Thingspeak IoT analytics Platform?
Thingspeak is open source platform made for Internet of Things (IoT) device developers and learners where developers can send and log data to the server, analyse, retrieve and store results using graphs with matlab support.
We can send up to 8 data simultaneously to the thingspeak account; the data uploaded will be converted to graphical representation automatically as illustrated below:
The straight line signifies that there was no temperature or humidity change during data logging. You can hover the mouse cursor on these dots to see the numerical data recorded at a particular local time. Thingspeak updates the data/graph every 15 seconds.
To send your data to thingspeak you need something called API key from your account which needs to be inserted in the given program code.
What is API key in Thingspeak?
API stands for “Application programing Interface”, on thingspeak it is a string of random character contains alphabets of lower and upper case, numbers and even special characters to identify your account and ensures that your sent data doesn’t end on someone else’s account and vice-versa.
There are two API keys generated while creating an account; one is called read API key and another is called write API key. We will be using only the write API key as we are going to write data to the thingspeak.
Now let’s see how to sign up and get the API keys for our project.
How to Sign up for Thingspeak and get API Key
- Signing up for thingspeak is simple, just click this link: https://thingspeak.com/users/sign_up and fill the necessary fields.
- Once this is done a verification link will be sent to your e-mail and click the received link.
Now go to your account and click on the API key tab and you can see your read and write API keys. Always keep your write API keys confidential.
- Now click the channel settings, we will now enable the two channels (graphs) and will be writing necessary labels to make our readings easier. Just do the following changes in your account as shown below:
- After making the changes scroll down and press “save”.
- Now you are ready with your thingspeak account and API key.
Now let’s learn about “APN” which is necessary for enabling the GSM modem to access internet.
What is APN?
APN stands for Access Point Name it is the gateway between carrier’s network and internet. GSM modem or any mobile device accessing internet must be configured with APN to present the wireless carrier. APN helps in getting the IP address and decides which security protocols should be used.
We should write the correct APN name for the mobile network / SIM that you have installed on the GSM modem in the program code, only then GSM modem can access the internet and send data to thingspeak platform.
- Airtel: airtelgrps.com (Tested)
- BSNL: bsnlnet (Tested)
- Vodafone: www
- Idea: imis
If you installed a BSNL SIM card to your GSM modem you should write “bsnlnet” as APN name in the given program code, similarly for Airtel etc.
NOTE 1: To find the APN names of other SIM mobile carriers, please search on Google.
NOTE 2: Don’t use “Jio” SIM card with GSM modems as they are 4G only network and GSM modem can only access 2G network. Other carriers should work without any issue as they are 2G backward compatible.
The circuit consists of a GSM modem for accessing GRPS/internet, one DHT11 sensor for sensing the ambient temperature and humidity and an arduino board of your choice.
The DHT11’s output is connected to pin A0 and the sensor is power by 5V from Arduino’s power output pins. You can either power the arduino with USB port or from external 9V input. The GSM modem should be powered from a wall adapter with at-least 1A current capacity, do not power it from Arduino.
Download DHT11 library file here: Click here
Program code: Verified and Error Free
Note 3: Don’t forget to change the API key and APN in the above code.
Advantage of Using GSM Module:
We are utilizing GSM modem to access the internet instead of Wi-Fi boards like ESP8266 so that our projects will be independent of Wi-Fi which has limited range and you may not able to move your project anywhere as you wish or you might need to carry a Wi-Fi hotspot device beside the project.
Say your project need to be place somewhere at the top of a building to collect some data like air quality or atmospheric pressure, with GPRS based internet access you can carry the project anywhere, but if we utilize ESP8266 in the project to access internet you will need a Wi-Fi hotspot device near the project.
If you already own a GSM modem you no need to buy an ESP8266 module to access internet.
How much GPRS data will be consumed?
From our experiments and observation we found that, if the GSM modem sends data to thingspeak for straight 6 hours the data consumed is less than 10 KB.
You absolutely need not to worry that you will run out of mobile data. You can buy an entry level data pack plan from your carrier and you can run the project for several weeks, your bottleneck will your data pack’s validity period and not your data.
How to operate this project:
- With completed hardware setup install a valid SIM card with a data plan from your mobile carrier.
- Get the correct APN name for your SIM network carrier and paste it in the given program code.
- Paste the “write API key” from your thingspeak account to the given program code.
- Now upload the code to Arduino board.
- Open Serial monitor, you can see the sensor data.
- Now open the “private view” tab in the thingspeak site you will see dots appearing after 30 seconds, which is your temperature and humidity data from the sensor.
- You can logout of the thingspeak account from your PC and still the data will be uploading to the platform.
If you have any questions regarding this project feel free to express in the comment section, you will get a guaranteed reply from us.