IoT Based Temperature and Humidity Monitoring using ThingSpeak and ESP8266

IoT based Temperature and Humidity Monitoring using ThingSpeak and ESP8266

ESP8266 Wi-Fi transceiver is one of the most popular WiFi module for IoT based Applications. In this DIY project we will use it to connect with ThingSpeak IoT cloud Platform.

In this project, we are going to send Temperature and Humidity sensor data to Thingspeak using DHT11. By this method we can monitor our DHT11 sensor’s temperature and humidity data over internet using ThingSpeak IOT server, and we can view the logged data and graph over time on the ThingSpeak dashboard. NodeMCU reads the current temperature and humidity from DHT11 and sends it to ThingSpeak server for live monitoring from anywhere in the world. We previously used ThingSpeak with Raspberry Pi and ESP32 to upload the data on cloud.

ThingSpeak is a data platform  for monitoring your data online, targeted to be used for IoT applications. In Thingspeak channel you can set the data as private or public according to your choice. ThingSpeak takes minimum of 15 seconds to update your readings. Its a great and very easy to use platform for building IOT projects.


Components Required 

  • NodeMCU
  • DHT11 Temperature and Humidity Sensor
  • Jumper Wires


Circuit Diagram

Circuit Diagram for IoT based Temperature and Humidity Monitoring using ThingSpeak and ESP8266


The circuit diagram above shows the ESP8266 and DHT11 connections. Follow the connections suggested in the below table: 














Step 1: ThingSpeak Setup for Temperature and Humidity Monitoring

For creating your channel on ThingSpeak you first need to sign up on ThingSpeak. In case if you already have account on ThingSpeak just sign in using your id and password.

For creating your account go to



Click on signup if you don’t have account and if you already have account click on sign in.

After clicking on signup fill your details.

 Signup for ThingSpeak


After this verify your E-mail id and click on continue.


Step 2: Create a Channel for Your Data

Once you Sign in after your account verification, Create a new channel by clicking “New Channel” button

Create Channel on ThingSpeak for IoT based Temperature and Humidity Monitor using ESP8266


After clicking on “New Channel”, enter the Name and Description of the data you want to upload on this channel. For example I am sending DHT11 sensor data (temperature and humidity), so I named it as “DHT11”.

Enter the name of your data ‘Temperature’ in Field1 and ‘Humidity’ in Field2. If you want to use more than one Field you can check the box next to Field option and enter the name and description of your data.

After this click on save channel button to save your details.


Step 3: API Key

To send data to ThingSpeak, we need an unique API key, which we will use later in our code to upload the Temperature and Humidity to ThingSpeak Website.

Click on “API Keys” button to get your unique API key for uploading DHT11 sensor data.

 APl Key for ThingSpeak for IoT based Temperature and Humidity Monitor using ESP8266.


Now copy your “Write API Key”. We will use this API key in our code.


Programing NodeMCU with Arduino IDE

To program NodeMCU with Arduino IDE go to File–>Perferences–>Settings.

Programing NodeMCU with Arduino IDE for IoT based Temperature and Humidity Monitor


Enter http:// into ‘Additional Board Manager URL’ field and click ‘Ok’.

 Add URL to Arduino IDE for IoT based Temperature and Humidity Monitor


Now go to Tools > Board > Boards Manager.

Manage Board in Arduino IDE for IoT based Temperature and Humidity Monitor


In Boards Manager window, Type esp in the search box, esp8266 will be listed there below. Now select latest version of board and click on install.

Install ESP8266 Library to Arduino IDE for IoT based Temperature and Humidity Monitor


After installation is complete, go to Tools >Board >and select NodeMCU 1.0(ESP-12E Module). Now you can program NodeMCU with Arduino IDE.


Programming ESP8266 for uploading data to ThingSpeak

Complete code is given at the end of this tutorial. Upload it in ESP8266 NodeMCU. If you successfully upload your program, Serial monitor will look like this:


Programming ESP8266 for Uploading data to ThingSpeak


After this, navigate to your Thingspeak page and open your channel in ThingSpeak and output will be shown as below.

 Getting Temperature and Humidity Monitoring using ThingSpeak and ESP8266


Also check our all the ThingSpeak related tutorial here.


#include <DHT.h>  
#include <ESP8266WiFi.h>
String apiKey = "Your API KEY";     //  Enter your Write API key here
const char *ssid =  "WiFi Name";     // Enter your WiFi Name
const char *pass =  "WiFi Password"; // Enter your WiFi Password
const char* server = "";
#define DHTPIN 4          // GPIO Pin where the dht11 is connected
 DHT dht(DHTPIN, DHT11);
WiFiClient client;
void setup() 
       Serial.println("Connecting to ");
       WiFi.begin(ssid, pass);
       while (WiFi.status() != WL_CONNECTED) 
      Serial.println("WiFi connected");
void loop() 
      float h = dht.readHumidity();
      float t = dht.readTemperature();
              if (isnan(h) || isnan(t)) 
                     Serial.println("Failed to read from DHT sensor!");
                         if (client.connect(server,80))   
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(t);
                             postStr +="&field2=";
                             postStr += String(h);
                             postStr += "\r\n\r\n";
                             client.print("POST /update HTTP/1.1\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             Serial.print("Temperature: ");
                             Serial.print(" degrees Celcius, Humidity: ");
                             Serial.println("%. Send to Thingspeak.");


Arduino: 1.8.13 (Windows 8.1), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, 115200, 4M (3M SPIFFS)"

In file included from C:\Users\ROMEO\Documents\Arduino\libraries\Blynk\examples\Boards_WiFi\ESP8266_Standalone\ESP8266_Standalone.ino:37:0:

C:\Users\ROMEO\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp8266.h:18:21: fatal error: version.h: No such file or directory

#include <version.h>


compilation terminated.

This report would have more information with
"Show verbose output during compilation option enabled in File -> Preferences.
how can i solved thid problen

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.