Arduino Example: Detecting Environmental Temperature and Humidity with DHT11

DHT11 is a low-cost temperature and humidity sensor that uses a moisture-sensitive resistor to measure humidity, employs a digital temperature sensor for temperature testing, and processes the data using a microcontroller with serial output. The DHT11 costs about 4 yuan, though it is not aesthetically pleasing. The DHT22 is priced around 15 yuan, and while it has a white color, it still lacks visual appeal. Both have the same pin definitions, but their operating sequences differ.

Arduino Example: Detecting Environmental Temperature and Humidity with DHT11

DHT22 Pin Definitions

The hardware connection between DHT11 and DHT22 is very simple, as shown in the schematic below:

Arduino Example: Detecting Environmental Temperature and Humidity with DHT11

The circuit connection for driving the DHT11 with an Arduino UNO R3 is shown in the following diagram, where the DATA pin of the DHT11 connects to the D2 pin of the Arduino.

Arduino Example: Detecting Environmental Temperature and Humidity with DHT11

Setting Up the Development Environment

1. Launch Arduino IDE

Project -> Load Library -> Manage Libraries, search for DHT, and install the DHT sensor library.

2. Open the example

File -> Examples -> DHT sensor library -> DHTtester

3. Modify the example to support DHT11

#define DHTTYPE DHT11 // DHT 11

//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

4. Upload the program, open the serial monitor, set baud rate to 9600, and observe temperature and humidity.

Note: This is just a demonstration routine; students can try to drive an LCD or OLED screen to display the environmental temperature and humidity. If using DHT22, simply modify the example.

//#define DHTTYPE DHT11 // DHT 11

#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

The review period before the exam is the most beautiful and shy time“, students who finished the circuit theory exam say this.

Arduino Example: Detecting Environmental Temperature and Humidity with DHT11

Dear passengers, the train number 2016 you are on will arrive in 8 days. Please organize your memories. Before getting off, give a hug to someone you know on the train and say thank you; no matter what, they have accompanied you through 2016. May all passengers cherish and enjoy the remaining 8 days! Finally, I wish everyone health and happiness on the next train!

Arduino Example: Detecting Environmental Temperature and Humidity with DHT11

Leave a Comment

×