Legal Info

When you visit any website, it may store or retrieve information on your browser, mostly in the form of 'cookies'. This information, which might be about you, your preferences, or your internet device (computer, tablet or mobile), is mostly used to make the site work as you expect it to. You can find out more about how we use cookies on this site, and prevent the setting of non-essential cookies, by clicking on the different category headings below. However, if you do this then it may impact your experience of the site and the services we are able to offer.

DHT11 sensor data to Thingspeak using a Wemos D1

In this example we will connect a DHT11 sensor to our Wemos D1, we will then send the temperature and humidity values to thingspeak.

DHT11 digital temperature and humidity sensor is a composite Sensor contains a calibrated digital signal output of the temperature and humidity. Application of a dedicated digital modules collection technology and the temperature and humidity sensing technology, to ensure that the product has high reliability and excellent long-term stability. The sensor includes a resistive sense of wet components and an NTC temperature measurement devices, and connected with a high-performance 8-bit microcontroller.

Typically a DHT11 can be bought in a basic breakout board format but can be bought as a standalone part as well, here is a picture of a typical breakout board, this board holds the sensor and a resistor, the resistor is connected between Vdd (3v3) and the signal pin on the board.

If you do not use a module like the one aboveyou can build a similar circuit on a breadboard. Here is a typical schematic, which is basically what the breakout above actually is

You will connect the Gnd of the module (DHt11) to a Gnd on your Wemos board, connect 5v or Vdd of the module (DHt11) to a 3v3 connection on your Wemos and the Sig pin (data pin on the DH11) goes to whatever input you decide to use on your Wemos, in the code below you can see this as

#define DHTPIN 2


You will now need to create a new account at thingspeak – https://thingspeak.com. Once done create a new channel and add two new fields, one will hold the temperature reading and the other will hold the humidity reading from our DHT11. This should look something like this


You will need an api key from thingspeak.

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

// replace with your channel’s thingspeak API key and your SSID and password
String apiKey = "thingspeak api key";
const char* ssid = "ssid name";
const char* password = "ssid password";
const char* server = "api.thingspeak.com";

const char* cr = "n";

const char* bar= "/";

#define DHTPIN D2
#define DHTTYPE DHT11

WiFiClient client;

void setup()

WiFi.begin(ssid, password);

Serial.print("Connecting to ");

WiFi.begin(ssid, password);

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 += "rnrn";

client.print("POST "+bar+"update HTTP"+bar+"1.1"+cr);
client.print("Host: api.thingspeak.com"+cr);
client.print("Connection: close"+cr);
client.print("X-THINGSPEAKAPIKEY: "+apiKey+cr);
client.print("Content-Type: application/x-www-form-urlencoded"+cr);
client.print("Content-Length: ");

Serial.print("Temperature: ");
Serial.print(" degrees Celsius Humidity: ");
Serial.println("Sending data to Thingspeak");

Serial.println("Waiting 20 secs");
// thingspeak needs at least a 15 sec delay between updates
// 20 seconds to be safe


If you login to your thingspeak account you can view live channel data like below

Thinkspeak DHT11 Temperature Chart view:

Thinkspeak DHT11 Temperature Chart view

Thinkspeak DHT11 Humidity Chart view:

Yuo can see our results projects in our Thinkspeak Channel

Buy now your kit. Click here to show the relates product: compraOra.jpg