ESP32DHT11 Tutorial | DHT11 Humidity Temperature Sensor with ESP32

In this tutorial, we will learn how to interface DHT11 with ESP32 DevKit Development Board. If you want to build a Web based Temperature and Humidity Monitoring System using ESP32, then DHT11 and DHT22 are the best choice as the Sensor. Learn how ESP32 DHT11 Humidity and Temperature Sensor interface works, setup Arduino IDE, display the humidity and temperature on an LCD. Additionally, you can design a simple ESP32 Web Server which continuously displays the humidity and temperature from DHT11 Sensor.

ESP32-DHT11-IMAGE-1

DHT11湿度和温度传感器的简短说明

我们已经在涉及Arduino,Raspberry Pi,ESP8266和STM32F103C8T6的几个早期项目中使用了DHT11温度和湿度传感器。DHT11是一种数字湿度和温度传感器,由电阻型湿度传感器,NTC型温度传感器和8位微控制器组成。ESP32初学者的项目]

DHT11 Sensor

It can measure Humidity in the range of 20% to 80% Relative Humidity and temperatures in the range of 00C to 500C. The microcontroller in the DHT11 Sensor performs all the ADC related stuff and provides the Digital data through a single wire.

Additionally, the DHT11 Temperature and Humidity Sensor can have a cable length up to 20 meters. This means you can easily implement a wired Sensor system which can go into lengthy places.

DHT11的PIN图和PIN描述

下图显示了DHT11和表的下表显示DHT11的引脚描述。

DHT11 PINOUT

DTH11的销 Description
VCC 力量Supply (3V to 5.5V)
数据 输入 /输出数据。必须高高拉。
NC Not Connected
GND Ground

Decoding Data from DHT11

In the Arduino DHT11 Tutorial, I explained in detail how the data from DHT11 Sensor looks like and how to extract this data without using any library. This is very useful if you are writing your drivers for DHT11 Sensor for any other microcontroller.

I won’t go into the details but the output of DHT11 is a 40-bit data divided as 8-bit Relative Humidity Integer Data + 8-bit Relative Humidity Decimal Data + 8-bit Temperature Integer Data + 8-bit Temperature Decimal Data + 8-bit Checksum.

DHT11 Sensor Data

ESP32 DHT11接口

现在,我们已经看到了一些有关DHT11湿度和温度传感器的信息,现在让我们继续了解如何与ESP32接口DHT11。您要记住的第一件事是DHT是一个数字传感器(内部微控制器执行数据采集和ADC转换)。

要记住的下一个重要的事情是,它需要一根电线进行通信。这意味着我们可以使用ESP32的任何数字GPIO PIN发送和从DHT11接收数据,我们只需要一根电线即可进行正确的通信。

Components Required

  • ESP32 Devkit开发委员会
  • DHT11湿度和温度传感器(传感器或模块)
  • 1 KΩ Pullup Resistor
  • 16×2 LCD
  • PCF8574 I2C LCD模块
  • 面包板
  • 连接电线
  • Micro USB Cable

笔记:I got a DHT11 Module with a 1 KΩ Pullup resistor on the Data Line already installed. If you are using just the sensor, then this pull-up resistor is important. A 5 KΩ Pullup is recommended by the manufacturer.

Circuit Diagram

The following image shows the connections between ESP32 and DHT11. First of all, the VCC of DHT11 is connected to VIN of ESP32 Board.

笔记:The range of power supply for DHT11 is from 3 V to 5.5 V. So, you can power DHT11 with a 3.3V Supply from ESP32 Board as well.

Next, the DATA pin. This pin should be pulled HIGH. As I have a module with a 1 KΩ Pullup already connected, I don’t need to make any additional connections. In case you are using only the DHT11 Sensor, then connect a 4.7 KΩ Resistor between Data Pin and VIN (or 3.3V) of ESP32.

笔记:The pullup voltage of Data Pin can be anywhere between 3 V to 5.5 V.

现在,数据引脚已连接到ESP32的GPIO 16,该GPIO 16在ESP32 Devkit板上标记为RX2。

第三引脚没有连接到任何东西。最后,GND引脚连接到ESP32的任何GND引脚。

ESP32-DHT11-Circuit

Preparing Arduino IDE

您需要下载几个库,以便ESP32可以与DHT11传感器正确通信。首先是主DHT11传感器库。转到工具 - >在Arduino IDE中管理库…。

ESP32-DHT11-Arduino-1

In the search bar, enter ‘dht’. Scroll through the options and install ‘DHT sensor library’ by Adafruit.

ESP32-DHT11-Arduino-2

下一个库与Adafruit本身关联。搜索“ Adafruit Unified”,向下滚动并安装“ Adafruit Unified Sensor”库。

ESP32-DHT11-Arduino-3

在串行显示器上显示湿度和温度

After making the proper connections and installing the necessary libraries as mentioned above, we will now see how to read the humidity and temperature data from DHT11 Sensor using ESP32 and display the result on the Serial Monitor.

Code

I wrote a simple code which will assign a pin to DHT11 Sensor, initialize the DHT11 Sensor and reads the humidity and temperature data from the sensor.

To view the result, I simply used the serial monitor to print the temperature values in % for Humidity and degree Celsius for temperature.

ESP32-DHT11-Image-4

The following image shows the screenshot of the Serial Monitor, which is continuously printing the humidity and temperature reading every 3 seconds.

ESP32-DHT11-Arduino-4

ESP32 DHT11与我2C LCD

Displaying humidity and temperature values from DHT11 Sensor on Serial Monitor is useful just for testing the connections and the code itself. To build a practical “Embedded System” application, you have to use a display module of some kind (OLED, 16×2 Character LCD, Nokia 5110 LCD, graphical LCD etc.) to view the humidity and temperature readings.

I used a regular 16×2 Character LCD Display Module in combination with PCF8574 I2C LCD Module to display the temperature readings from ESP32 DHT11 Interface.

I made a dedicated tutorial on how to use an I2C LCD与ESP32。查看该教程以获取深入的信息。我还讨论了您已下载的必要库,以成功将I2C LCD与该教程中的ESP32连接起来。

笔记:我还解释了如何获得我的奴隶地址2该教程中的C LCD模块。此步骤非常重要。

Circuit Diagram

The additional components you require are a 16×2 LCD Display and an I2C LCD Module (based on PCF8574). Plug-in the I2C LCD Module at the back of the 16×2 LCD Display. The I2C LCD Module needs only four connections (two of them are for power and two are for data).

以下电路图显示了ESP32和I2C LCD模块以及ESP32和DHT11湿度和温度传感器之间的所有必要连接。

ESP32-DHT11-I2C-LCD电路

Code

ESP32 DHT11与I2C LCD接口的代码非常简单。传感器的初始化部分与先前的代码相似。另外仅添加了与LCD相关的代码。

ESP32-DHT11-IMAGE-2

结论

这里实现了有关将DJT11湿度和温度传感器接口的初学者教程。您了解了一些有关DHT11传感器,ESP32 DHT11接口的工作,与DHT11通信的必要库,如何在串行输出上显示湿度和温度数据以及如何将I2C LCD与ESP32连接并显示湿度和温度读数。

就使用ESP32和DHT11传感器的基于Web的湿度和温度监视系统而言,我将在短期内使用Web服务器代码更新此页面。

一个回应

发表评论

Your email address will not be published.

电子产品hub Favicon
<\/i>","library":""}}" data-widget_type="nav-menu.default">
Baidu