In this tutorial i will teach you how to interface dht-11 temperature and humidity sensor with nodemcu esp8266-12e WiFi module and monitor temperature of an area. One can see the temperature and humidity level of a room or a particular place in his desktop or mobile browser by making this diy project. Their are also other family members of DHT-11 temperature & humidity sensor available in market such as DHT-21 and DHT-22. The same code of this tutorial can be utilized to interface other dht family members with nodemcu WiFi module with slight modifications in dht library.
DHT-11 Temperature and Humidity Sensor
Like old methods of measuring temperature DHT-11 also uses thermistor with high accuracy to measure the temperature of surroundings. For humidity measurement it uses capacitive humidity sensor. Its a low cost temperature and humidity sensor. Power requirements of the sensor is between 3 volts to 5 volts and needs continuous 25 mA of direct current. It outputs data in digital form. It can measure temperature between 0 degree to 50 degree Celsius with 2% margin of error. Humidity level it can measure lies between 20% to 80% with 5% margin of error. DHT-11 can update its data after every 2 seconds so its a pretty low speed sensor. DHT-11 outputs default temperature in Celsius.
DHT-11 sensor has 3 or 4 pins depending on the manufacturer. Normally it has four pins. Two pins a power pins. Gnd and Vcc respectively. The third one is data_out pin. At this pin sensor outputs the temperature and humidity values. Fourth pin is void. Data_out pin requires a pull up resistor. The sensor i am using has a build in pull up resistor.
DHT-11 sensor has 3 or 4 pins depending on the manufacturer. Normally it has four pins. Two pins a power pins. Gnd and Vcc respectively. The third one is data_out pin. At this pin sensor outputs the temperature and humidity values. Fourth pin is void. Data_out pin requires a pull up resistor. The sensor i am using has a build in pull up resistor.
Project circuit diagram
Nodemcu esp8266-12e works on 3.3 volts and dht-11 can also work on 3 volts. So i am going to power the dht-11 with nodemcu output power pins. For data input to nodemcu i am using D3 or GPIO-0 of nodemcu. Project circuit diagram is given below.
Coming to the code portion. First i included the necessary libraries for nodemcu and dht-11 working. ESP8266WiFi header file deals with the nodemcu module and DHT header is for initializing and working with DHT sensor. After libraries i defined the macros for dht sensor and the pin to which it will be connected with nodemcu. After it enter the SSID and Password of WiFi network to which you want to connect your nodemcu.
const char* ssid = “Your SSID”;
const char* password = “Your Wifi Password”;
In the setup loop nodemcu requests the router for an IP. After IP allotment it starts its server. In the loop function nodemcu is checking for any client request. If a request arrives nodemcu fetches data from dht-11 and send back a reply in the form of an HTML page to client.
Nodemcu is working as a server. It is serving a web page. Web page contains the temperature and humidity values of room or a place. Your client desktop, mobile, laptop or notebook must be on the same WiFi network to which nodemcu is connected. If one of them the client/mobile or server/nodemcu is connected to other network then you will be unable to load and see the web page on which temperature and humidity data is served.
Just build the circuit and upload the above code in your nodemcu. After uploading enter the serial monitor from arduino ide. You will see nodemcu starting its WiFi and server status. After server startup a link will be displayed containing an IP. This IP or HTTP address is link on which nodemcu is displaying temperature and humidity values. Enter this address in your browser for page load.
If you are unable to see any thing on the serial monitor or raw numbers and figures. It might be due the wrong bps settings. Change the communication rate to 9600 bps. If still you cant see any thing check the nodemcu and PC connection. Check for all possible errors. |
Final page displayed in the browser will be some thing like below. It contains the temperature and humidity values. Temperature will be displayed in both scales Celsius and Fahrenheit. A button with text “Update Temperature & Humidity” is present on the page. When ever user needs an updated value he has to press this button. This button press notifies the nodemcu that client needs an updated temperature value.
Download the project code. Folder contains arduino ide .ino file. Please provide us your feed back on the project. For comments and queries us the below comments section.
Filed Under: Electronic Projects, ESP8266, Microcontroller Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.