Introduction
ESP32 & DTH11(Humidity and Temperature Sensor)
Currently, with the continuous development of science and technology, all daily activities are automated, robots gradually take over many positions in our daily lives. In order to have the correct and efficient operation of automation devices, sensors are one of the key components. Motion sensors are one of them, which can help detect the movement of people or objects, thereby helping mechanical devices have the correct control signals.
In this article, we will show you how to connect and operate DTH11 with ESP32 and ESP8266 using Visual Studio IDE This Article has 2 Separate Circuit Diagrams and Source Code . However the Sensors and LCD unit are same. you will be able to apply Interfacing LCD display and DTH11 Sensor to your projects, making your products smarter.
SENSOR-MODULE/EXPANSION BOARD PINOUT DIAGRAM
Hardware Introduction
Module ESP32
In this project, they will need to use the esp32 module, specifically I chose esp32 wroom devkit v1. Picture below
ESP32-WROOM-32 is a powerful, generic Wi-Fi+BT+BLE MCU module that targets a wide variety of applications, ranging from low-power sensor networks to the most demanding tasks, such as voice encoding, music streaming and MP3 decoding.
At the core of this module is the ESP32-D0WDQ6 chip*. The chip embedded is designed to be scalable and adaptive. There are two CPU cores that can be individually controlled, and the CPU clock frequency is adjustable from 80 MHz to 240 MHz. The chip also has a low-power co-processor that can be used instead of the CPU to save power while performing tasks that do not require much computing power, such as monitoring of peripherals. ESP32 integrates a rich set of peripherals, ranging from capacitive touch sensors, Hall sensors, SD card interface, Ethernet, high-speed SPI, UART, I²S and I²C.
ESP32 Specifications
ESP8266
Espressif’s ESP8266EX delivers highly integrated Wi-Fi SoC solution to meet users’ continuous demands for efficient power usage, compact design and reliable performance in the Internet of Things industry.
With the complete and self-contained Wi-Fi networking capabilities, ESP8266EX can perform either as a standalone application or as the slave to a host MCU. When ESP8266EX hosts the application, it promptly boots up from the flash. The integrated highspeed cache helps to increase the system performance and optimize the system memory. Also, ESP8266EX can be applied to any microcontroller design as a Wi-Fi adaptor through SPI/SDIO or UART interfaces.
ESP8266EX integrates antenna switches, RF balun, power amplifier, low noise receive amplifier, filters and power management modules. The compact design minimizes the PCB size and requires minimal external circuitries.
Besides the Wi-Fi functionalities, ESP8266EX also integrates an enhanced version of Tensilica’s L106 Diamond series 32-bit processor and on-chip SRAM. It can be interfaced with external sensors and other devices through the GPIOs. Software Development Kit (SDK) provides sample codes for various applications.
Espressif Systems’ Smart Connectivity Platform (ESCP) enables sophisticated features including:
- • Fast switch between sleep and wakeup mode for energy-efficient purpose;
- • Adaptive radio biasing for low-power operation
- • Advance signal processing
- • Spur cancellation and RF co-existence mechanisms for common cellular, Bluetooth, DDR, LVDS, LCD interference mitigation

ESP8266 Specifications
DHT11 Sensor
DHT11 output calibrated digital signal. It applies exclusive digital-signal-collecting-technique and humidity sensing technology, assuring its reliability and stability. Its sensing elements is connected with 8-bit single-chip computer.
Every sensor of this model is temperature compensated and calibrated in accurate calibration chamber and the calibration-coefficient is saved in type of programmer in OTP memory, when the sensor is detecting, it will cite coefficient from memory.
Small size & low consumption & long transmission distance(100m) enable DHT11 to be suited in all kinds of harsh application occasions. Single-row packaged with four pins, making the connection very convenient.
Operating specifications:
Communication and signal: 1-wire bus is used for communication between MCU and DHT11.
Power and Pins : Power’s voltage should be 3.3-5.5V DC. When power is supplied to sensor, don’t send any instruction to the sensor within one second to pass unstable status. One capacitor valued 100nF can be added between VDD and GND for wave filtering.
Display LCD 16×2 – I2C
The term LCD stands for Liquid Crystal Display. It is one kind of electronic display module used in an extensive range of applications like various circuits & devices like mobile phones, calculators, computers, TV sets, etc. These displays are mainly preferred for multi-segment light-emitting diodes and seven segments. The main benefits of using this module are inexpensive; simply programmable, animations, and there are no limitations for displaying custom characters, special and even animations, etc.
LCD Specification
Features of LCD16x2:
- + The operating voltage of this LCD is 4.7V-5.3V
- + It includes two rows where each row can produce 16-characters.
- + The utilization of current is 1mA with no backlight
- + Every character can be built with a 5×8 pixel box
- + The alphanumeric LCDs alphabets & numbers
- + Is display can work on two modes like 4-bit & 8-bit
- + These are obtainable in Blue & Green Backlight
- + It displays a few custom generated characters
I2C Serial Interface Adapter
This is also known as I2C Module. It has total of 20 male pins. 16 pins are faced to rear side and 4 pins faced towards front side. The 16 pins for connect to 16×2 LCD and the 2 pins out of 4 pins are SDA and SCL. SDA is the serial data pin and SCL is the clock pin. The rest 2 pins for power supply (Vcc and ground).There is a POT on the I2C Module. We can control the contrast of the LCD display by rotating this POT. And there is a jumber fixed on the module. When we remove the jumber, the backlight of the LCD display will go OFF.
ESP32 Connectivity Diagram

ESP32 DTH Sensor Pin Connectivity Table
Actual ESP32 DTH11 and LCD Connectivity Image
Source Code
Create new project ESP32 with visual studio code
#include <Arduino.h>
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int DHTPIN = 15;
const int DHTTYPE = DHT11;
DHT dht(DHTPIN, DHTTYPE);
byte degree[8] = {
0B01110,
0B01010,
0B01110,
0B00000,
0B00000,
0B00000,
0B00000,
0B00000
};
void setup() {
lcd.init();
lcd.backlight();
lcd.print("Temper: ");
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.createChar(1, degree);
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)) {
}
else {
lcd.setCursor(10,0);
lcd.print(round(t));
lcd.print(" ");
lcd.write(1);
lcd.print("C");
lcd.setCursor(10,1);
lcd.print(round(h));
lcd.print(" %");
}
}
Git Repo for ESP32
You can download the entire project source code at: https://github.com/hongthiet1994/esp32_dht11
Module ESP8266
ESP8266 Connectivity Diagram
ESP8266 DTH11 Pin Connectivity Table
Actual Image ESP8266DTH11 and LCD Display

Source code:
#include <Arduino.h>
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int DHTPIN = D4;
const int DHTTYPE = DHT11;
DHT dht(DHTPIN, DHTTYPE);
byte degree[8] = {
0B01110,
0B01010,
0B01110,
0B00000,
0B00000,
0B00000,
0B00000,
0B00000
};
void setup() {
lcd.init();
lcd.backlight();
lcd.print("Temper: ");
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.createChar(1, degree);
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)) {
}
else
{
lcd.setCursor(10,0);
lcd.print(round(t));
lcd.print(" ");
lcd.write(1);
lcd.print("C");
lcd.setCursor(10,1);
lcd.print(round(h));
lcd.print(" %");
}
}
Git Repo for ESP8266
https://github.com/hongthiet1994/esp8266_dht11
5g (2) adafruit (10) airtel (2) arduino (7) cloud (4) Connected Home (3) cybersecurity (2) Dpdk (3) DTH11 (2) easymesh (2) esp32 (6) esp8266 (5) gaming (2) gps (7) home assistant (4) home hub (2) IoT Security (2) LCD (2) lora (6) mesh (3) mesh-wifi (4) mesh network (5) mesh wifi (6) micropython (10) motion-sensor (3) mqtt (2) mycroft (3) nrf24 (3) openmesh (2) programming (2) rapberry pi zero w (3) raspberry pi (26) raspberry pi pico (15) RFM69HCW (5) rpi-pico (18) sam-mq8 (2) Secure Smart Home (7) security (6) Smart-Home (12) Smart-Home Security (5) smart home (3) sparkfun (2) voice assistant (4) vpn (6) wireless (5)