Skip to main content

Command Palette

Search for a command to run...

Using the DHT11 Sensor with Arduino

Updated
3 min read

Introduction

The DHT11 is a low-cost digital sensor used to measure temperature and humidity. It is widely used in electronics, IoT, weather monitoring systems, smart homes, and automation projects because of its simple interface and easy integration with microcontrollers like Arduino.

The sensor provides calibrated digital output, making it easier to use compared to analog temperature sensors.


Features of DHT11

  • Measures temperature and humidity

  • Digital signal output

  • Low power consumption

  • Easy to interface with Arduino

  • Suitable for beginner electronics projects

Specifications

Parameter Value
Operating Voltage 3.3V – 5V
Temperature Range 0°C to 50°C
Humidity Range 20% – 90% RH
Accuracy ±2°C and ±5% RH
Sampling Rate 1 Hz

Components Required

  • Arduino Uno/Nano

  • DHT11 Sensor Module

  • Breadboard

  • Jumper Wires

  • USB Cable


Pin Configuration of DHT11

DHT11 Pin Arduino Connection
VCC 5V
DATA Digital Pin 2
GND GND

If you are using the bare DHT11 sensor instead of the module version, use a 10kΩ pull-up resistor between VCC and DATA.


Circuit Diagram


Installing the DHT Library

Before uploading the code, install the DHT sensor library.

Steps:

  1. Open Arduino IDE

  2. Go to Sketch → Include Library → Manage Libraries

  3. Search for DHT sensor library

  4. Install:

    • Arduino IDE compatible DHT sensor library by Adafruit

    • Adafruit Unified Sensor library


Arduino Code

#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

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

void loop() {
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();

  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.print("%  ");

  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println("°C");

  delay(2000);
}

How the Code Works

  • The DHT library communicates with the sensor.

  • readHumidity() reads humidity percentage.

  • readTemperature() reads temperature in Celsius.

  • Data is displayed on the Serial Monitor every 2 seconds.


Output

After uploading the code:

  1. Open the Serial Monitor

  2. Set baud rate to 9600

  3. Temperature and humidity values will appear continuously

Example:

Humidity: 55.00%  Temperature: 29.00°C

Applications of DHT11

  • Weather stations

  • Smart home systems

  • Greenhouse monitoring

  • IoT environmental monitoring

  • Room climate measurement


Advantages

  • Cheap and easily available

  • Beginner-friendly

  • Simple digital communication

  • Works directly with Arduino libraries


Limitations

  • Lower accuracy compared to advanced sensors

  • Slow sampling rate

  • Limited temperature and humidity range

For better accuracy, sensors like the DHT22 can be used.


Conclusion

The DHT11 sensor is an excellent choice for beginners learning Arduino and IoT projects. With just a few connections and simple code, users can measure environmental temperature and humidity easily. It is widely used in educational, hobby, and basic automation applications.