/

The DHT11 Temperature and Humidity Sensor: A Beginner's Guide

The DHT11 Temperature and Humidity Sensor: A Beginner’s Guide

The DHT11 temperature and humidity sensor is an essential electronic component often used for building indoor or outdoor thermometers. It is one of the first sensors that beginners learn to use due to its simplicity and practicality.

DHT11 Temperature and Humidity Sensor
DHT11 Temperature and Humidity Sensor
DHT11 Temperature and Humidity Sensor

The DHT11 sensor has four output pins, although some breakout boards may only have three. The pins are as follows:

  • Vdd (positive input)
  • Vss (negative input)
  • Output signal

The output signal is a 40-bit serialized data that lasts for 4ms. To read the temperature and humidity information, the serialized data needs to be deserialized.

To simplify the process of reading the temperature, there is a library available called the DHT Sensor Library maintained by Adafruit. The library can be found here. It provides convenient functions for interacting with the DHT11 sensor.

In an Arduino program, the library is included using #include <DHT.h>. Following this, an object of the DHT class is initialized by specifying the sensor signal pin and the sensor type, which is DHT11 in this case.

The library provides functions such as readHumidity() and readTemperature() to retrieve the values as floating-point variables. By default, the temperature value is returned in Celsius, but the library also includes a convertCtoF() function to obtain the Fahrenheit value.

Additionally, the library offers other useful methods like computeHeatIndex(). For more details, you can explore the DHT.h header file source code on GitHub.

To demonstrate the usage of the DHT11 sensor, here’s a simple Arduino program that reads the data from a DHT11 sensor connected to digital pin #2 and prints the values to the serial monitor:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <DHT.h>

DHT dht(2, DHT11);

void setup() {
Serial.begin(9600);
dht.begin();
}

void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();

if (isnan(h) || isnan(t)) {
Serial.println("Cannot read values");
return;
}

Serial.println((String)"Humidity: " + h + "%, Temperature: " + t + "C");
}

The program periodically reads the humidity and temperature values and prints them to the serial monitor.

Serial Monitor Output

The DHT11 sensor is a great component for beginners to start experimenting with temperature and humidity measurements. Its simplicity and availability make it a popular choice in various applications.

Tags: electronic components, DHT11, temperature sensor, humidity sensor, Arduino, sensor library