Interface DHT11 (Humidity Sensor) Using NodeMCU




About: " Work until you no longer have to introduce yourself " Show some love on Instagram & Motivate me on YouTube @TheCircuit

Hey Makers!

In this Instructables you will learn how to set up the DHT11 Humidity and Temperature sensor on your NodeMCU. And learn about how the Humidity sensor works, and how to check output readings from the Serial monitor.

Step 1: Components Required

Here is the list of components required to get started with the Instructable,

Hardware Components

  • NodeMCU
  • DHT11 Humidity and Temperature sensor
  • Breadboard
  • Jumper Wires (Optional)
  • Micro USB Cable

Software Components

  • Arduino IDE

Step 2: Description

The DHT11 detects water vapor by measuring the electrical resistance between two electrodes. The humidity sensing component is a moisture holding substrate with electrodes applied to the surface. When water vapor is absorbed by the substrate, ions are released by the substrate which increases the conductivity between the electrodes. The change in resistance between the two electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes, while lower relative humidity increases the resistance between the electrodes.

Step 3: Two Different DHT11

There are two different versions of the DHT11 you might come across.

One type has four pins, and the other type has three pins and is mounted to a small PCB.

The PCB mounted version is nice because it includes a surface mounted 10K Ohm pull up resistor for the signal line. Here are the pin outs for both versions.

Step 4: ​How to Setup DHT11 on an NodeMCU

Wiring the DHT11 to the NodeMCU is really easy, but the connections are different depending on which type you have either 3-pins or 4-pins.

The wiring connections are made as follows :
Pin 1 of the DHT11 goes into +3v of the NodeMCU.

Pin 2 of the DHT11 goes into Digital Pin D4 of the NodeMCU.

Pin 3 of the DHT11 goes into Ground Pin (GND) of the NodeMCU.

Step 5: Coding Time

Before you use the DHT11 with NodeMCU, you need to install the DHTLib library. It has all the functions needed to get the humidity and temperature readings from the sensor. It’s easy to install.

Open up the Arduino IDE, then go to Sketch > Include Library > Manage Libraries > Search DHTLib

After it’s installed, upload this program to the NodeMCU by download the attached code "DHT11.ino" below and check output in the serial monitor.


#include <dht.h>

dht DHT;

#define DHT11_PIN 2
void setup(){

void loop(){
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.print("Humidity = ");

Step 6: Output

You should see the humidity and temperature readings displayed at one second intervals.

If you don’t want to use pin 2 for the data signal, you can change the pin number in line 3 where it says

" #define DHT11_PIN 2 ".

That's all makers!
I hope you found this instructable most useful. You can contact me by leaving a comment. If you like this instructable probably you might like my next ones.



    • Toys Contest

      Toys Contest
    • Epilog X Contest

      Epilog X Contest
    • Cardboard Challenge

      Cardboard Challenge

    11 Discussions


    Tip 2 days ago on Step 6

    Use a library compatible with DHT sensor library for ESPx
    If not, you will be turning around and around why it does not work


    9 months ago

    Thanks for the intructable! :-)
    Had some trouble with the library dht, and I ended using the DHTStable that is compatible with the NodeMCU 12F.

    1 reply

    8 months ago

    Hi, I did not understand one thing: this library runs with the NodeMCU card but
    does not have in the code header the #include esp8266; So does it run with this #include esp8266 too? Thank you


    1 year ago

    very well explain one. Thanks. I am using Node MCU with BLYNK App. Board is not detected for Node MCU. Could you explain why?

    1 reply

    Reply 10 months ago

    the DHT sensor requires 5V to operate properly, so make sure you use the Vin pin from your ESP8266 that outputs 5V.


    1 year ago

    Hi, thanks a lot for the Instructable it was very helpfull. Very well explained.

    Yet the DTH 11 has the wrong pin out, as other people has signaled.


    1 year ago

    I don't know about the three pin version, but in the four pin version you have the diagram wrong (at least the one that I got). The leftmost pin goes to VCC, and the one to the right of it is the signal.




    1 year ago

    Absolutely love this project!
    I made one myself but every time I let the project check itself or try to upload it it says that «dth» isn't compatible with the nodemcu.
    Do you have any suggestions how to fix this?

    thx for the project!

    1 reply