dht11 sensor

Interfacing of DHT11 Sensor With ESP8266 nodemcu

ESP8266 / NodeMCU IoT IoT Tutorial


Hello geeks, we are back with a new post in the series of nodemcu tutorials. Today we will learn how we can measure the temperature and humidity using a nodemcu board and a DHT11 sensor. If you are new to our website then please also check out our projects on IoT and final year projects.


  • You just have to complete the circuit and then upload the given code to the nodemcu. We are sharing all the details regarding this project below.

Let’s don’t waste more time and move to the working of the project. We have also discussed a project on a weather station in our previous blogs, you can read the article for full details.

DHT11 Sensor

This project is useful where you have to find the temperature and humidity in the air. If you understand the concept of this project then you can modify the code and make other different projects out of it.

dht11 sensor

  • This project can print the values of the temperature and humidity on the serial monitor screen.
  • When to provide the power to the nodemcu then the sensor starts working and continuously print the values on the serial monitor.
  • dht11 sensor with esp8266 is a good combination for iot projects.
  • The temperature values are in degree celsius and the humidity values are in percentage.
  • We use readtemperature function for taking the readings of the temperature and readhumidity function for taking the values of the humidity.
  • The thing about this sensor is that it is easy to use and small in size also. It can calculate the humidity and temperature with the help of electrodes present inside its plastic casing.

How the Activity will look like

dht11 sensor

Components Required

Connection Table/buy link

S.No Component Name Quantity Buy Link
1. Nodemcu esp8266 1 amazon
2. Nodemcu cable 1 amazon
3. DHT 11 Sensor 1 amazon
4. Breadboard 1 amazon
5. Jumper wire 40 amazon


Circuit Diagram for the Project

dht11 sensor

Connection Table

Nodemcu esp8266 Dht11 Sensor
VV, Vin ( +5V ) ( V ) VCC ( Positive + )
G, GND ( Ground ) ( G ) GND ( Ground – )
D4 Pin ( S )  OUT Pin

Make the connections as given in the above diagram.

  • There are three pins in the DHT-11 sensor out of which two are for power and one is for the output data transmission.
  • You have to connect all three pins to the nodemcu.
  • Connect the VCC pin of the sensor with the VIN pin of the nodemcu.
  • Join the GND pin of the sensor to the GND pin of the nodemcu.
  • At last, connect the remaining pin that is OUT pinned with the digital-4 pin of the nodemcu.

Before uploading the code please check that connections are correct and tight.

Code for the Project

NOTE: You have to upload this code to the nodemcu but before that install <DHT.h> library to the IDE software. Check here how to add a zip library to the Arduino IDE.

 // https://github.com/adafruit/DHT-sensor-library  
 #include "DHT.h"  
 DHT dht2(2,DHT11);  
 void setup()  
 void loop()  
   Serial.println("Temperature in C:");  
   Serial.println((dht2.readTemperature( )));  
   Serial.println("Humidity in C:");  

Do you like this project? Tell us in the comments section below and also if you have any doubts regarding the project then ask them. For better understanding try to make it on your own.

You can also check out projects on Arduino and Raspberry Pi written by us.

Video Sample

Spread the love, Share this post with friends

Leave a Reply

Your email address will not be published. Required fields are marked *