Home / Tutorials / ESP8266 Tutorial / Send Sensor Data to ThingSpeak via ESP8266
Soil moisture sensor to ESP8266

Send Sensor Data to ThingSpeak via ESP8266

In the previous tutorial, we set up a soil moisture sensor and have its data readable via WiFi. However, that data is only accessible if the NodeMCU and the client (smartphone, PC, etc.) is in the same network. In this tutorial, we will use a service that allows us to read the data from the sensor from any device connected to the Internet.

The service I’m talking about is ThingSpeak by MathWorks. Most engineering students and professors might be familiar with MathWorks which is the same company behind MATLAB. ThingSpeak has already been featured in one of my projects. However, in that project, I used cellular data to connect to the Internet. This tutorial will use the WiFi connection through the ESP8266 NodeMCU.

Video Tutorial

Setting Up a ThingSpeak Account

ThingSpeak requires a MathWorks account for login. So before anything else, go to mathworks.com/mwaccount/register and provide the required information:


Make sure you can access the email you provided as it's required to verify your email:


Open your email and click on the “verify” button. You will then be redirected to this page which asks for additional information:


If you or your university owns a licensed MATLAB software, you can enter the activation key or license number on the form shown:


If you don't have any MATLAB license, just skip this part. I haven't explored the benefits of adding a MATLAB license here but maybe your account gets upgraded.

After this, your MathWorks profile is now ready!

Creating a ThingSpeak Channel

Now that you have a MathWorks account, go to thingspeak.com/login:


Enter your MathWorks email and password to sign in. A pop-up window will appear. Select one of the options; the other field is optional.


You should now be in the "channels" page. ThingSpeak requires you to create a channel with up to 8 fields. Free users are limited to 4 channels and 255 characters per field.

Clicking the "New Channel" button directs you to this page:


Here, I named my channel Soil Moisture, gave a brief description and named 1 field. After creating the channel, you’ll be on a page where you’ll see an empty time plot of your created field.


Updating the field requires simple HTTP GET requests. For free accounts, the field updates every 15 seconds.

Click the API Keys tab:


Here we can see the possible API requests. For example, to update the field SoilMoisture, I copy the URL https://api.thingspeak.com/update?api_key=UTB05H415R3M0SIX&field1=0

The last part of this URL is the updates to the SoilMoisture field. We can test this by copy-pasting the URL above to a browser and just change the last number to any number. Here, I changed the number to 100 and pressed enter:


The time plot on the “private view” tab now updates:


Uploading Sketch to NodeMCU

Now that we know how to send data to ThingSpeak through HTTP GET request, it’s time to create a sketch for the ESP8266 NodeMCU board.

Modify the sketch below at lines 5 & 6 to your own WiFi SSID and password. Also, modify line 9 to your own ThingSpeak API key.

This sketch sends reading from the sensor with about 5 seconds interval. The sensor, from the previous tutorial, connects to the A0 pin of the NodeMCU.

The graph on the ThingSpeak private view now updates regularly (see video for output).

For the next part of this tutorial, we will embed the data from ThingSpeak to a website.

Check Also

solid state relay tutorial

Solid State Relay Tutorial | WiFi Switch

Relays in electronics are useful for controlling a high-power load using a smaller-power circuit. For …

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.