ESP8266 with DHT11 and DHT22 sensors

In this blog there are many topics talk about the DHT11 and DHT22 sensors and how to use them with different types of microcontrollers including the Arduino. This topic shows how use the DHT11 and the DHT22 relative humidity and temperature sensors with ESP8266 ESP-01 Wi-Fi module where the measured values of the relative humidity and the temperature are displayed on 16×2 LCD screen.

The DHT11 (RHT01) as well as the DHT22 (RHT03, AM2302) sensors work with voltage range from 3V to 5.5V. The ESP-01 module works with 3.3V and the LCD screen works with 5V.
Since the ESP-01 module has only four I/O pins, I’m going to use an I2C LCD. This LCD consists of PCF8574 I/O expander.

If you want to see how to use the ESP-01 module for the first time, how to use it with Arduino IDE and how to program (upload sketches) it with Arduino, visit the following topic:
ESP8266 WiFi module programming with Arduino UNO board

Also, the page below shows how interface the ESP-01 module with I2C LCD:
Interfacing ESP8266 ESP-01 module with I2C LCD

Hardware Required:
The components required for this project are listed below, if you’re using the DHT11, choose it, otherwise choose the DHT22.

  • ESP8266 ESP-01 module
  • DHTT11 or DHT22 sensor
  • 16×2 LCD screen
  • PCF8574 I/O expander (or PCF8574A)   —   PCF8574 datasheet
  • AMS1117 3V3 voltage regulator
  • 10uF capacitor
  • 0.1uF (100nF) ceramic capacitor
  • 5 x 10k ohm resistor
  • 4.7k ohm resistor
  • 330 ohm resistor
  • 10k ohm variable resistor or potentiometer
  • 5V source
  • Breadboard
  • Jumper wires

ESP8266 ESP-01 with DHT22 sensor and LCD

The Circuit:
The circuit connections of the DHT11 and the DHT22 are the same.

ESP8266 ESP-01 DHT11 DHT22 sensor circuit

(All grounded terminals are connected together)

The DHT11/DHT22 sensor has 4 pins (from left to right): VCC (+3V), data, NC (not connected) and GND (ground). The data pin is connected to the RX pin of the ESP-01 module, this pin is also GPIO1.

The Codes:
The circuit diagrams of the DHT11 and the DHT22 are the same, but the codes are not. The two code are below, the first one is for the DHT11 sensor and the second is for the DHT22 sensor.

To be able to compile the 2 codes, we need 2 libraries: one for the I2C LCD and the other for the DHT (DHT11 and DHT22) sensors, download links are below:
LiquidCrystal_I2C Library   —   direct link
Adafruit DHT library         —   direct link

DHT11 code:

DHT22 code:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.