April 21, 2024

What is the DHT11 humidity sensor on an Arduino?


The DHT11 humidity sensor is a cost effective device that enables you to effortlessly measure temperature and humidity. Whether you’re constructing a weather station monitoring the climate inside a greenhouse or developing a home automation system the DHT11 sensor proves to be an asset. Within this all-encompassing guide we will delve into all the details, about the sensor and provide instructions, on how to seamlessly connect it with an Arduino.

What is the DHT11 Humidity Sensor?

The DHT11 humidity sensor is a device that can detect and record both temperature and humidity. It uses a sensor to measure humidity levels and a thermistor to measure temperature accurately. The DHT11 is capable of measuring temperatures from 0°C, to 50°C with an accuracy of ±2.0°C. It can also determine humidity levels ranging from 20% to 80% with an accuracy of 5%. Due to its size and affordability the DHT11 sensor has gained popularity among both hobbyists and professionals, in fields.

DHT11 Module Hardware Overview

The DHT11 module revolves around the DHT11 sensor itself which is manufactured by AOSONG. This sensor comes pre calibrated from the factory. Doesn’t require any components to operate. It has a design. Includes all the necessary circuitry making it convenient to use right out of the package.

Within the DHT11 sensor there is an NTC thermistor that measures temperature and a component that senses humidity. The humidity sensing component consists of two electrodes separated by a substrate that can hold moisture. When the humidity increases the substrate absorbs water vapor causing a decrease, in resistance between the electrodes. This change, in resistance is directly related to the humidity level enabling measurements of humidity.

DHT11 Module Pinout and Wiring

The DHT11 module consists of three pins; VCC, OUT and GND. The VCC pin is responsible, for supplying power to the sensor. It is recommended to use a 5V power source for performance. The OUT pin facilitates communication between the sensor and the microcontroller while the GND pin is connected to ground.

To connect the DHT11 module with an Arduino board you will need to establish a connection by linking the VCC pin with the Arduino’s output. Next connect the OUT pin to an input pin on the Arduino (such as pin 8). Finally attach the GND pin to ground. It’s worth noting that the DHT11 module already includes a built in pull up resistor so there’s no need, for an one.

Installing the DHT Library

To begin reading data from the DHT11 sensor we’ll first need to install the DHT library in the Arduino IDE. This library simplifies the process of communicating with the DHT11 sensor. Offers functions, for obtaining temperature and humidity values.

To install the DHT library open the Arduino IDE. Navigate to Sketch > Include Library > Manage Libraries… In the search bar look for “DHT”. You should find Adafruits DHT sensor library. Select it. Click on the “Install” button to incorporate it into your Arduino IDE.

Arduino Example 1 - Displaying Readings on Serial Monitor

Let’s begin by installing the DHT library. After that we can create an Arduino sketch to retrieve and show temperature and humidity data, from the DHT11 sensor. For this demonstration we will utilize the monitor to visualize the readings, from the sensor.


#include <DHT.h>  // Include the DHT library

#define DHTPIN 8   // Defines the pin number to which the sensor is connected


DHT dht(DHTPIN, DHT11);  // Create a DHT object


void setup() {

  Serial.begin(9600);  // Initialize serial communication



void loop() {

  delay(2000);  // Wait for 2 seconds between readings


  float temperature = dht.readTemperature();  // Read temperature in Celsius

  float humidity = dht.readHumidity();        // Read humidity


  Serial.print(“Temperature: “);


  Serial.print(” °C\t”);


  Serial.print(“Humidity: “);


  Serial.println(” %”);


In this example we start by including the DHT library and specifying the pin number where the DHT11 sensor is connected. Afterwards we create a DHT object. Set up the communication, in the setup function.

Within the loop function we utilize the readTemperature() and readHumidity() functions to obtain temperature and humidity values from the sensor respectively. We then use the object to display these values on the monitor.

To observe real time temperature and humidity readings upload this sketch, to your Arduino board. Open the monitor.

Arduino Example 2 - Displaying Readings on an LCD

Apart, from showing the readings from the sensor on the monitor you can also present them on an LCD display to create an user friendly interface. In this scenario we will link an LCD display to the Arduino. Adjust the code to exhibit the sensor readings, on the LCD.


To wire the LCD display to the Arduino, you’ll need to connect the following pins:

  • LCD VCC to Arduino 5V
  • LCD GND to Arduino GND
  • LCD SDA to Arduino A4
  • LCD SCL to Arduino A5

Arduino Code

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

#include <DHT.h>


#define DHTPIN 8




LiquidCrystal_I2C lcd(0x27, 16, 2);  // I2C address may vary, check the documentation


void setup() {

  lcd.begin(16, 2);  // Initialize the LCD display

  lcd.backlight();  // Turn on the backlight


  dht.begin();  // Initialize the DHT sensor



void loop() {

  float temperature = dht.readTemperature();

  float humidity = dht.readHumidity();


  lcd.setCursor(0, 0);

  lcd.print(“Temp: “);


  lcd.print(” C”);


  lcd.setCursor(0, 1);

  lcd.print(“Humidity: “);


  lcd.print(” %”);




In this example we make sure to include the libraries, for the LCD display such as Wire.h and LiquidCrystal_I2C.h well as the DHT sensor library called DHT.h. We specify the pin number to which the DHT11 sensor is connected and create an object for it.

Inside the setup function we take care of initializing both the LCD display and turning on its backlight. Additionally we ensure that the DHT sensor is properly initialized.

Moving on to the loop function we retrieve temperature and humidity values from the sensor. Showcase them on the LCD display using functions, like print and setCursor. To avoid overwhelming or crowding up the display a delay of 2 seconds is added between each reading.

Once you’ve uploaded this sketch to your Arduino board you’ll be able to observe temperature and humidity readings being conveniently displayed on your LCD screen.


The DHT11 humidity sensor is a device, for measuring temperature and humidity in projects. It has become popular among both hobbyists and professionals due, to its affordability and ease of use. By following the instructions provided in this guide you can effortlessly connect the DHT11 sensor to an Arduino board. Begin gathering temperature and humidity data for your projects. Whether you’re keeping track of the climate in a greenhouse or constructing a weather station the DHT11 sensor is an option that won’t put a strain on your budget. So go ahead, get creative, and explore the possibilities with the DHT11 humidity sensor!

Leave a Reply

Your email address will not be published. Required fields are marked *