How to Use ThingSpeak

by ahmnouira in Circuits > Wireless

272 Views, 1 Favorites, 0 Comments

How to Use ThingSpeak

iot-pixabay-cc0-100674648-primary.idge.jpg

In this tutorial we will learn another IoT application,

How to send data to ThingSpeak ?.

We will use only DHT11 module and ESP8266-based board ( NodeMCU).

THE BROAD OVERVIEW

ThingSpeak is an open source Internet of Things (IoT) application and API(Application Programming Interface) to store and retrieve data from things using the HTTP(Hypertext Transfer Protocol) protocol over the Internet or via a Local Area Network.

ThingSpeak enables the creation of sensor logging applications, location tracking applications, and a social network of things with status updates.

ThingSpeak was originally launched in 2010, as a service in support of IoT applications. It has integrated support from the numerical computing software MATLAB from MathWorks, which allows users to analyse and visualise their data using MATLAB, without requiring the purchase of a MATLAB license.

THE SETUP

Screenshot from 2018-05-15 13-23-37.png
Screenshot from 2018-05-15 13-24-22.png
Screenshot from 2018-05-15 13-28-44.png
1_.PNG

The first thing we need to do is to set up your ThingSpeak account.

Once you have created an account we need to do a couple of things before we can start programming.

1.Head over to the ThingSpeak website.

2.We need to create an account before we can use it.

3.Create a New Channel, which you will find under Channels > My Channels.

We are presented with several options that we need to complete. So give the channel a name.

In the next box is the description; here we enter a description of your ThingSpeak channel.
We are then presented with a series of field boxes, of which we need a minimum of 1 and a maximum of 8. Check the box to enable the field, and enter a field name.

THE VIEW DATA SCREEN

A.PNG
B.PNG
C.PNG
H.PNG

With our channel set up we can look at the data tools. Click on Channels > My Channels and you will be presented with all the channels you have created.

Click on your newly created channel and you will be greeted by your data, displayed as a basic bar graph.

ThingSpeak requires the use of API keys, and you will find these in the API Keys.

The API itself, is quite simple in terms of how it works.
We need to do a basic URL call, to read and write to the channel.The examples below show how this is structured

API REQUESTS

  • Update a Channel Feed:

GET https://api.thingspeak.com/update?api_key=8DS5DM3...

  • Get a Channel Feed:

GET https://api.thingspeak.com/channels/367828/feeds....

  • Get a Channel Field:

GET https://api.thingspeak.com/channels/367828/fields...

  • Get Channel Status Updates:

GET https://api.thingspeak.com/channels/367828/status...

Now that we have an understanding of how ThingSpeak works let’s do something with if, and getting some data in.

TESTING

4.jpg
5.jpg
kk.PNG

The following example use a simple DHT11 sensor and NodeMCU.

  • Connect DHT11 temperature and humidity sensor to the D4 pin of NodeMCU.

Another option would be to use the Arduino with an Ethernet shield.

The core code to write to ThingSpeak will work, but you will need to import the Ethernet library, and change the WiFi library object.

  • Make sure you have the ESP8266, DHT, Adafruit-Sensor libraries installed.

1. For ESP8266 library, start Arduino and open the Preferences window.Enter :

http://arduino.esp8266.com/versions/2.4.2/package_...

in additional boards manager URLs filed.

Open the Boards Manager from the Tools > Board menu and find the ESP8266 platform. Select the version you need, then click the install button. select the ESP8266 board from Tools > Board menu.

2. For DHT library, go to Sketch > Include Library > Add .ZIP Library and choose DHT-sensor -library (see files below).

3. For Adafruit-Sensor library, follow the same method as DHT library.

  • Download the code below.

THE RESULT

B.PNG
Send Data To ThingSpeak

First of all you must change the code a bit :

  • change ssid wih your WiFi's name.
  • change password with your WiFi's password.
  • change API_KEY with your API Key from ThingSpeak.

If everything is alright, upload the code to your board.

Check the video if you stuck.

WHERE TO FROM HERE?

Now that we have our data in ThingSpeak, what can we do with it?

There is a myriad of ways to slice and dice your data.
If you have any experience with MATLAB then the code will switch easy to you. We have many options for visualisations, but the simplest is to plot our data with line graphs overtime

  • Get humidity and temperature data over the course of several days.

CONCLUSION

ThingSpeak offers a simple and fast way of collecting your data and makes it easy to download into a speadsheet format, for further processing.

If you need a way of easily collecting large volumes of data over time, we would highly recommend using this service.

For any question of course you can leave a comment.
myYoutube

myFacebook

myTwitter

Thanks for reading this tutorial.

have a nice day.

See ya.

Ahmed Nouira