Control DHT11/22

日本語のページ

You can control the temperature/humidity sensor DHT11/22.

Wiring

The DHT11/22 has three pins: + (or V), - (or G), and S.
+ connects to the power supply, - connects to GND, and S connects to any GPIO pin that can accept input.
The power supply voltage can be either 3.3V or 5V.

For example, when connecting the DHT11 to an unbranded ESP32, the wires to be used when connecting the S of the DHT11 to pin 5 are as shown in the figure below.

Example of Wiring plain ESP32 and DHT11

Initialization

First, use the initialization block to initialize DHT11/22.
Specify which DHT11/22 to use and the connection destination of the S pin.

Initialize DHT11/22

Getting temperature/humidity

After initialization, you can get the temperature/humidity values ​​using the block that gets them.
The temperature unit is degrees Celsius, and the humidity unit is percent.

Temperature of DHT11/22

Humidity of DHT11/22

Example

This is an example of obtaining temperature and humidity from a DHT22 connected to pin 5 and outputting it to the console every second.
This sample can be downloaded from here.

Example of DHT11/22