Contents

Interfacing DHT11 Temperature/Humidity Sensor with Arduino

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.

Note
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.

Note

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.
Note

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
  
Home
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 DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); dht.begin(); Serial.println("Initializing... Please wait."); delay(2000); } 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!")); return; } Serial.print(F("Humidity: ")); Serial.print(h); Serial.print(F("% Temperature: ")); Serial.print(t); Serial.print(F("°C ")); Serial.println(f); delay(2000); }

The code output is like this:

Liked What You See?​
Get Updates And Learn From The Best​

Comment (1)

  • naim Reply

    thx a lot you are good Mohammadreza Akbari (are you engineer ?)
    nice to contact and read to you
    i’m naim tunisian computer science engineer and robotic teacher

    March 30, 2023 at 12:20 am

Leave a Reply

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