How to Use DHT11 Temperature and Humidity Sensor with Arduino

Follow,Star Public Account so you don’t miss out on wonderful content

How to Use DHT11 Temperature and Humidity Sensor with Arduino

The DHT11 digital temperature and humidity sensor is a comprehensive sensor that includes a calibrated digital signal output, commonly used in HVAC, automobiles, dehumidifiers, automatic control, and other fields. This article introduces the DHT11 driver and prints the collected ambient temperature and humidity data via serial.

1. Introduction to DHT11

The DHT11 is a digital sensor that integrates temperature and humidity measurement. It includes a resistive humidity sensing element and an NTC temperature sensing element, connected to a high-performance 8-bit microcontroller. With simple external circuit connections, it can collect local temperature and humidity in real-time. The DHT11 communicates with microcontrollers and other controllers using a simple single-bus protocol, requiring only one I/O port. The sensor transmits 40-bit temperature and humidity data to the microcontroller at once, with checksum verification to ensure the accuracy of the data transmission.

The technical parameters of DHT11 are as follows:

  • Operating Voltage: 3.3V-5.5V

  • Operating Current: Average 0.5mA

  • Output: Single-bus digital signal

  • Measurement Range: Humidity 20-95%RH, Temperature 0-50℃

  • Accuracy: Humidity ±5%, Temperature ±2℃

  • Resolution: Humidity 1%, Temperature 1℃

The pin arrangement of DHT11, with the window hole facing up, from left to right is VCC, Dout, NC, GND.

How to Use DHT11 Temperature and Humidity Sensor with Arduino
DHT11 Pinout

In circuit connections, a pull-up resistor is usually added to the data pin, as shown in the DHT11 module:

How to Use DHT11 Temperature and Humidity Sensor with Arduino
DHT11 Module

2. Install the Driver Library

In the Arduino IDE, click on ‘Project’—’Load Library’—’Manage Libraries’, enter “dht11”, and you will see many libraries. You can choose to install one based on your needs. This article selects the second one, ‘DHT sensor library’, for installation.

How to Use DHT11 Temperature and Humidity Sensor with Arduino
Install Library

To use the ‘DHT sensor library’, we also need to download and install ‘Adafruit_Sensor’. Note that this library cannot be found in the library manager, so we download it directly from Github (https://github.com/adafruit/Adafruit_Sensor).

How to Use DHT11 Temperature and Humidity Sensor with Arduino
Download Library

After downloading the compressed package, click ‘Project’—’Load Library’—’Add .ZIP Library’ in the IDE, and locate the downloaded compressed package for installation.

How to Use DHT11 Temperature and Humidity Sensor with Arduino
Add Library

3. Experiment Materials

  • Uno R3 Development Board

  • USB Data Cable

  • Breadboard and Jumper Wires

  • DHT11 Sensor Module

4. Experiment Steps

1. Build the circuit according to the schematic diagram.

The single-bus connection of DHT11 is very simple. Connect the module’s VCC and GND to the development board’s 3.3V and GND, and connect the DATA pin of the module to any digital pin on the development board; this article connects to digital pin 2.

The experimental schematic diagram is shown below:

How to Use DHT11 Temperature and Humidity Sensor with Arduino
Circuit Connection Diagram

The actual connection diagram is shown below:

How to Use DHT11 Temperature and Humidity Sensor with Arduino
Actual Connection Diagram

2. Create a sketch, copy the code below to replace the auto-generated code and save it.

#include "DHT.h"

#define DHTPIN  2
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHT11 test");
  dht.begin();
}

void loop() {
  float h = dht.readHumidity(); // Read humidity
  float t = dht.readTemperature(); // Read temperature (Celsius)

  Serial.print("Humidity:");
  Serial.print(h);
  Serial.print("% Temperature:");
  Serial.print(t);
  Serial.println("℃");
  delay(2000);
}

3. Connect the development board, set the corresponding port number and board type, and download the program.

How to Use DHT11 Temperature and Humidity Sensor with Arduino
Program Download

5. Experimental Phenomena

Open the Serial Monitor, set the baud rate to match the program, and you can see the temperature and humidity data printed at intervals.

How to Use DHT11 Temperature and Humidity Sensor with Arduino
Experimental Phenomena
Recommended Reading:

Arduino Improvement Series 02—OLED Screen Chinese Character Display

Arduino Improvement Series 03—OLED Screen Image Display

Arduino Improvement Series 04—U8g2 Library Driver for OLED

If you find this article helpful, please click ‘Like’, share, or leave a message as support.

Follow the public account ‘TonyCode’, reply ‘Improvement’ in the background to get the code in this article.

How to Use DHT11 Temperature and Humidity Sensor with Arduino

Long press to recognize the QR code in the image to follow

Leave a Comment

×