Toggle Nav

Interfacing DHT11 Temperature/Humidity Sensor with Arduino

Table of Contents

DHT11 Sensor Features

The DHT11 is a digital temperature and humidity sensor. This sensor is able to measure the humidity in the range of 20% to 80% with an accuracy of 5%. It can also measure the temperature in the range of 0 to 50 degrees Celsius with an accuracy of 2 degrees.

The sampling frequency of this sensor is 1Hz. As a result, there must be at least one second between every readings of the sensor, otherwise the reading values will be incorrect.

You can download the DHT11 sensor datasheet here.

DHT11 Sensor Module Pinout

This module has 4 pins, which only 3 pins are used.

   • VCC: Module power supply – 5V
   • GND: Ground
   • Data: Sensor output

You can see pinout of this module in the image below.

Required Material

Hardware component

Arduino UNO R3 × 1
DHT11 Temperature Humidity Sensor Module × 1
Male to Female jumper wire × 1

Software Apps

Arduino IDE

Interfacing DHT11 Sensor with Arduino

Step 1: Circuit

Connect the module to Arduino according to the following image.


The output pin of the DHT11 sensor is pulled up on the module with a resistor. therefore, you do not need to connect an external resistor.

Step 2: Installing Library

Go to Library manager and install DHT11 temperature sensor library.

If you need more help with installing a library on Arduino, read this tutorial: How to Install an Arduino Library

Step 3: Code

Upload the following code on your Arduino. This code displays the temperature and humidity read in the serial monitor.
  DHT11 - Tempertature & Hummidity Sensor
  modified on 08 Sep 2020
  by Mohammad Reza Akbari @ Electropeak

  Based on Adafruit Example

#include "DHT.h"

#define DHTPIN 8     // Digital pin connected to DHT11

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11


void setup() {
  Serial.println("Initializing... Please wait.");

void loop() {
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(F("%  Temperature: "));
  Serial.print(F("°C "));


The code output is like this:

Liked What you see?

Get updates and learn from the best

More To Explore

Leave a Reply

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