Interfacing DHT11 with NodeMCU Example

In this tutorial we are interfacing DHT11 or DHT22 Humidity temperature sensor with NodeMCU.

The DHT11 (or DHT22 and similar) are cheap temperature and humidity sensors. The communicate with a ESP8266 is over a single wire, but unfortunately it is not compatible with the 1-Wire protocol defined by Dallas Semiconductors.

The electric connection to the NodeMCU is very simple, as the DHT series can be powered direct with 3.3V. Only 3 wires are needed: VCC, GND and the data line.

DHT11 Connections with NodeMCU

ESP8266 DHT11 Interfacing

DHT11 Sensor Specifications

The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin (no analog input pins needed). Its fairly simple to use, but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds, so when using our library, sensor readings can be up to 2 seconds old. Compared to the DHT22, this sensor is less precise, less accurate and works in a smaller range of temperature/humidity, but its smaller and less expensive.

If you are using module it comes with a 4.7K or 10K resistor. You need external 10K or 4.7K pull up on data pin to VCC.

DHT11 Pinout for ESP8266

DHT11 Specifications:

  • Low cost
  • 3 to 5V power and I/O
  • 2.5mA max current use during conversion (while requesting data)
  • Good for 20-80% humidity readings with 5% accuracy
  • Good for 0-50°C temperature readings ±2°C accuracy
  • No more than 1 Hz sampling rate (once every second)
  • Body size 15.5mm x 12mm x 5.5mm
  • 4 pins with 0.1″ spacing

NodeMCU ESP8266 Program for DHT11 Sensor

Before moving directly on coding install required libraries.

Go to menu Sketch >> Include Library >> Manage Library

Install DHT sensor library for ESPx by beegee library. or DownloadNodeMCU DHT11 LibraryAfter installing library write below code.

Results

After uploading program in NodeMCU open serial monitor with 115200 baud rate.

DHT11 NodeMCU Readigns

References:

Leave a Reply