Using the DHT11 Temperature Sensor with a WeMos D1 Mini (ESP8266)

In this blog post I talk about the additional steps needed to use the DHT11 temperature sensor with a WeMos D1 Mini (ESP8266) with the Arduino IDE.

Differences from running a DHT11 on an Arduino

There are two major differences to bear in mind when using the DHT11 on a Wemos D1 Mini (ESP8266) or similar chipset.

The first is that the pin out is different in the Arduino IDE than when using the Arduino. I go into more details in my blog post Pin numbering for WeMos D1 Mini (ESP8266) but simply put, you need to use different pin numbers. If you haven’t read this and are having trouble connecting your DHT11 properly I recommend having a read.

The second issue is that the standard DHT11 library doesn’t work very well with the WeMos. In my case it was failing to compile due to issues in the architecture. After trying a couple libraries I found the easiest to use and install was the “DHT sensor library for ESPx” by beegee_tokyo.

After doing some investigation the reason the standard DHT11 library doesn’t work is that the Arduino is a lot slower than the ESP8266. This affects the standard DHT11 library as the DHT11 has strict timing requirements with its interface. The increased speed of the ESP8266 causes issues communicating with the DHT11 and stops it working.

Wiring it up to a WeMos D1 Mini

Here I am connecting the DHT11 sensor to a WeMos D1 mini. For ease of connecting up the sensor I connect the 3.3 volt and GND line to the breadboard. From there I connect the 3.3 volt line to the first pin on the DHT11.

The third pin is connected to the GND line from the WeMos.

The central pin is used for data and is connected to the D5 pin on the WeMos. In addition I connect a 10k resistor between this data pin and the 3.3 volts line to act as a pull-up resistor.

It is important not to connect the DHT11 sensor to the 5 volt line. This is because the power is used at the data pins and would therefore flow back into the WeMos.

Unlike the Arduino, the WeMos data pins are rated at 3.3 volts max. This means connecting the 5 volts to them will damage the microcontroller. Since the DHT11 supports between 3 and 5 volts it is perfectly fine to use the 3.3 volts line.

Programming the Wemos with the DHT11

Here instead of using the standard DHT library I am using DHTesp. This library built specifically to use DHT devices on ESP8266 microcontrollers.

I was able to use this library to log the temperature and humidity and print it out on the serial connection.

#include "DHTesp.h"

DHTesp dht;

void setup() {
    dht.setup(D5, DHTesp::DHT11);

void loop() {
    float h = dht.getHumidity();
    float t = dht.getTemperature();

    Serial.print("{\"humidity\": ");
    Serial.print(", \"temp\": ");


The DHTesp::DHT11 constant is used in the setup function to tell configure the dht variable to talk to the sensor using the DHT11 protocol.


The DHT11 sensor is a useful and cheap temperature and humidity sensor that can be used with the WeMos D1 mini. Although the standard DHT11 libraries cannot be used there are similar libraries designed for ESP8266 chipsets such as the WeMos D1 mini.

For a full review of the DHT11 have a read of my previous post.

Add a Comment

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.