Introduction

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.

method

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.

Steps

First make sure you are using the latest version of Raspbian.
Connect the DHT11 (or DHT21/DHT22) signal pin to gpio4.

Edit config.txt

sudo nano /boot/config.txt

Add a new line at the end:
dtoverlay=dht11,gpiopin=4
Save and exit.

reboot Raspberry Pi.

sudo reboot

You're done!
use the command blelow to see the data.

sudo cat/dev/dht11

How to assign another pin?

Find dtoverlay=dht11, gpiopin=4 in the config.txt you just added, and change 4 to the pin you want. Note that the pin numbers are BCM coded.

Last modified: February 15, 2020

Author

Comments

Write a Reply or Comment

Your email address will not be published.