Interface DHT11 (Humidity Sensor) Using NodeMCU
by CodeChamp in Circuits > Sensors
183603 Views, 59 Favorites, 0 Comments
Interface DHT11 (Humidity Sensor) Using NodeMCU
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.
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
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.
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.
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.
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.
CODE :
#include <dht.h> dht DHT; #define DHT11_PIN 2
void setup(){ Serial.begin(9600); }
void loop(){ int chk = DHT.read11(DHT11_PIN); Serial.print("Temperature = "); Serial.println(DHT.temperature); Serial.print("Humidity = "); Serial.println(DHT.humidity); delay(1000); }
Downloads
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.