ThingSpeak Temperature and Humidity IoT Device

In this blog post I will show you how to build a temperature and humidity IoT device with an ESP8266 NodeMCU board and a DHT11 sensor that sends data to a ThingSpeak channel. It is divided in five parts:

  1. Prerequisites
  2. Set Up Android IDE
  3. Prepare the Breadboard
  4. Write the Code
  5. Watch it Working


There are just a few components need to build this device:

  • ESP8266 NodeMCU board (or a similar ESP8266 board with I/O pins)
  • DHT temperature/humidity sensor (in this case it is a DHT11, but you can also use others, like the DHT22)
  • USB power bank
  • Breadboard (to connect the sensor with the board)

Set Up Android IDE

  1. Download and install the Arduino IDE from
  2. Go to „Preferences“ and insert into „Additional Boards Manager URLs“:
  3. Open the library manager: „Sketch => Include Library => Manage Libraries“
  4. Install the ESP8266 library: „esp8266 by ESP8266 Community“
  5. Install the DHT library: „DHT sensor library by Adafruit“

Prepare the Breadboard

The DHT is a digital sensor and needs to be connected to a GPIO pin of the board. The other 2 pins are for VCC and GND. In my case it fits perfectly on the D4 pin, because there is a 3V and GND pin right beneath.

The sketch above shows the schematic circuit, but with a DHT22. The value of the pull-up resistor is 10kΩ.

And the final breadboard looks like this. There we can plug in the ESP8266 NodeMCU board and the DHT11 sensor.

Write the Code

 ESP8266 DHT11 ThingSpeak Channel

Sends the temperature and humidity values from a DHT11 sensor to a ThingSpeak channel.

What you need:
 - ESP8266 NodeMCU board (or any other board with I/O pins)
 - DHT temperature/humidity sensor
 - USB power bank
 - breadboard (to connect the sensor with the board)

What libraries you need to install first:
 - esp8266 by ESP8266 Community (set "Additional Boards Manager URLs in preferences to
 - DHT sensor library by Adafruit

Blog Post:

#include <ESP8266WiFi.h>
#include <DHT.h>

#define DHTPIN 2 // digital pin the DHT11 is concected to
#define DHTTYPE DHT11 // DHT sensor type has to be defined

WiFiClient client;

// wifi
const char* ssid = "SSID";
const char* password = "PASSWORD";

// ThingSpeak
const int channelID = CHANNELID;
String writeApiKey = "WRITEAPIKEY";
const char* server = "";
const int interval = 60 * 1000; // send data every 60s

void setup() {
 pinMode(DHTPIN, INPUT_PULLUP); // set DTH pin to input mode
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {

void loop() {
 // send data to the ThingSpeak API
 // wait and then post again

void sendData() {
 if (client.connect(server, 80)) {
 // read sensor values
 float humidity = dht.readHumidity();
 float temperature = dht.readTemperature();

// request body
 String body = "field1=";
 body += String(temperature);
 body += "&field2=";
 body += String(humidity);

// send request
 client.println("POST /update HTTP/1.1");
 client.println("Connection: close");
 client.println("X-THINGSPEAKAPIKEY: " + writeApiKey);
 client.println("Content-Type: application/x-www-form-urlencoded");
 client.println("Content-Length: " + String(body.length()));

Set the WiFi SSID and password and the ThingSpeak channel ID and the write API key. Then you are ready to upload it to your ESP8266 NodeMCU, to do so your board needs to be in flash-mode. My board activates flash-mode by pressing the „FLASH“ and „RST“ button at the same time.

Watch it Working

Now you should see some Data in your ThingsSpeak channel.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.


Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.