DHT11 is a commonly used temperature and humidity sensor, but it is not easy to read on the Raspberry Pi. In the examples, most of them are analyzed by libraries or read signal pins directly. Although these methods are effective, they are not simple and convenient. The official Raspberry Pi system comes with a simple method that can easily read data from DHT11.
Open/boot/overlays/README and you will find the following lines:
Name: dht11 Info: Overlay for the DHT11/DHT21/DHT22 humidity/temperature sensors Also sometimes found with the part number(s) AM230x. Load: dtoverlay=dht11,<param>=<val> Params: gpiopin GPIO connected to the sensor's DATA output. (default 4)
This means that by adding dtoverlay=dht11 to config.txt, you can find the dht11 file under /dev/. The content is the humidity and temperature of DHT11.
First make sure you are using the latest version of Raspbian.
Connect the DHT11 (or DHT21/DHT22) signal pin to gpio4.
sudo nano /boot/config.txt
Add a new line at the end:
Save and exit.
reboot Raspberry Pi.
use the command blelow to see the data.
How to assign another pin?
in the config.txt you just added, and change 4 to the pin you want. Note that the pin numbers are BCM coded.