How to Interface DHT11 and DHT22 Sensors With Arduino Uno

by Rachana Jain in Circuits > Arduino

32 Views, 0 Favorites, 0 Comments

How to Interface DHT11 and DHT22 Sensors With Arduino Uno

How to Interface DHT11 and DHT22 Sensors with Arduino Uno.jpg

Want to create a smart home climate control system or measure real-time temperature and humidity data in a weather station? DHT11 and DHT22 Temperature and Humidity Sensors are excellent choices. Their ease of use, affordability, and relatively accurate readings make them ideal for DIY electronics projects requiring climate data.

This tutorial will walk you through interfacing these sensors with an Arduino Uno to measure humidity and temperature. With a simple setup and Arduino code, you can quickly begin capturing real-time environmental data.


Supplies

  1. Arduino Uno
  2. DHT11
  3. DHT22 sensor
  4. Breadboard
  5. Jumper wires
  6. 10kΩ pull-up resistor

Overview of DHT11 and DHT22 Sensors

The DHT11 and DHT22 sensors are part of the DHTxx series and are widely used for temperature and humidity measurement. They are similar in appearance and pin configuration but differ in terms of specifications, accuracy, and applications.

DHT11 Sensor

The DHT11 is cost-effective and suitable for basic applications. It has the following features:

  1. Temperature Range: 0 to 50°C with an accuracy of ±2°C
  2. Humidity Range: 20-90% RH with an accuracy of ±5%
  3. Operating Voltage: 3.3 to 5.5V DC
  4. Sampling Rate: 2 seconds
  5. Resolution: 1% RH for humidity, 1°C for temperature

DHT22 Sensor

The DHT22 offers higher precision and a broader range of measurements:

  1. Temperature Range: -40 to 80°C with an accuracy of <±0.5°C
  2. Humidity Range: 0-100% RH with an accuracy of ±2 to ±5%
  3. Operating Voltage: 3.3 to 6V DC
  4. Sampling Rate: Greater than 2 seconds
  5. Resolution: 0.1% RH for humidity, 0.1°C for temperature

Both sensors are interchangeable, requiring minimal modifications to the code for swapping.

Working Principle of DHT11 and DHT22

The sensors measure temperature and humidity using:

  1. Humidity Sensing Component: A substrate holds moisture between two electrodes. The conductivity changes with humidity levels, altering the resistance sensed by the sensor's internal MCU. The processed data is sent as relative humidity.
  2. NTC Thermistor: Measures temperature by changing resistance based on ambient temperature. A negative temperature coefficient (NTC) means resistance decreases as temperature increases.
  3. Integrated Circuit (IC): Processes the signals from the sensing components, converting analog readings into digital data for the Arduino.

How DHT Sensors Communicate with Arduino

DHT sensors use the Aosong One-Wire Protocol to communicate with the Arduino. This protocol requires a single data pin for communication, simplifying wiring while maintaining efficient data transfer.

DHT11 and DHT22 Pinout

DHT11 Temperature and humidity sensor pinout.JPG
DHT22 Temperature and humidity sensor pinout.JPG
  1. Pin 1: VCC (Power Supply, 3.3-5.5V for DHT11, 3.3-6V for DHT22)
  2. Pin 2: This pin is used for communication between the sensor and the microcontroller.
  3. Pin 3: NC (Not connected)
  4. Pin 4: GND (Ground)

Wiring Diagram for Interfacing DHT11 and DHT22 Sensor to an Arduino

Interfacing DHT22 Temperature and humidity Sensor with Arduino Uno.JPG
Interfacing DHT22 Temperature and humidity Sensor with Arduino Uno.JPG
  1. Connect VCC of the sensor to the Arduino's 5V pin.
  2. Connect GND of the sensor to the Arduino's GND pin.
  3. Connect Data pin to a digital pin D2 on the Arduino with a 10kΩ pull-up resistor between the data pin and VCC.

Arduino Example Code

In the below code, we will be interfacing a DHT11/DHT22 temperature and humidity sensor with Arduino UNO.

/*
this code is brought to you by www.playwithcircuit.com
*/
#include <DHT.h>
#define DHTPIN 2 // Define the digital pin where the DHT sensor is connected
#define DHTTYPE DHT11 // DHT11 or DHT22, change this according to your sensor type
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600); // initialize serial port
dht.begin(); // Initialize the DHT sensor
}
void loop() {
// Read temperature and humidity from the DHT sensor
// In the parameter pass true if temperature is required in fahrenheit, pass false if temperature is required in celsius
float temperature = dht.readTemperature(false);
float humidity = dht.readHumidity();
// Check if the sensor reading is valid (non-NaN)
if (!isnan(temperature) && !isnan(humidity)) {
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C, Humidity: ");
Serial.print(humidity);
Serial.println("%");
}
else
{
Serial.println("Failed to read from DHT sensor!");
}
delay(2000); // Delay for 2 seconds before the next reading
}

Conclusion

By following this guide, you can seamlessly interface DHT11 or DHT22 sensors with an Arduino Uno to measure temperature and humidity. The DHT11 offers affordability for basic projects, while the DHT22 provides higher precision for more critical applications. Choose the sensor that best fits your project requirements and start building amazing projects!

To learn more checkout this guide: Interfacing DHT11 and DHT22 Sensors with Arduino Uno