Measure Temperature and Humidity Using Arduino and DHT11/DHT22

In this Arduino Tutorial we will learn how to use the DHT11 or the DHT22 sensor for measuring temperature and humidity with the Arduino board.

Introduction :

These sensors are very popular for electronics hobbyists because there are very cheap but still providing great performance. Here are the main specifications and differences between these two sensors:

The DHT22 is the more expensive version which obviously has better specifications. Its temperature measuring range is from -40 to +125 degrees Celsius with +-0.5 degrees accuracy, while the DHT11 temperature range is from 0 to 50 degrees Celsius with +-2 degrees accuracy. Also the DHT22 sensor has better humidity measuring range, from 0 to 100% with 2-5% accuracy, while the DHT11 humidity range is from 20 to 80% with 5% accuracy.

Difference between DHT11 and DHT22

There are two specification where the DHT11 is better than the DHT22. That’s the sampling rate which for the DHT11 is 1Hz or one reading every second, while the DHT22 sampling rate is 0,5Hz or one reading every two seconds and also the DHT11 has smaller body size. The operating voltage of both sensors is from 3 to 5 volts, while the max current used when measuring is 2.5mA.

Components Required :

  • Arduino UNO
  • DHT11 or DHT22
  • 16 x 2 LCD Display
  • Potentiometer
  • Breadboard
  • Jumper Cables
  • Arduino Cable

Schematics :

Schematics
ArduinoLCD DHT11 / DHT22Potentiometer
    
D2RS
D3E
D4D4
D5D5
D6D6
D7D7
D12Data Pin
V0Center Pin
GNDVss, RW, KGND Right / Left Pin
5VVcc, AVccLeft / Right Pin

Source Code :

Note :

  • Remove Tx / Rx Pins of Arduino while Uploading the Code.
  • Install the Required Library.
/*

      © Techtronic Harsh
 
*/

#include "DHT.h"                        //include the DHT library
#include <LiquidCrystal.h>              //include the LiquidCrystal library
#define DHTPIN 12                       //define DHT pin
#define DHTTYPE DHT11                   //define DHTTYPE DHT11/DHT22

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);    //define LCD pins (RS, E, D4, D5, D6, D7)

DHT dht(DHTPIN, DHTTYPE);

void setup() 
{
  dht.begin();  
  lcd.begin(16,2);                      //initializes the LCD and specifies the dimensions
}
void loop() 
{
  float temp = dht.readTemperature();
  float humi = dht.readHumidity();
  
  lcd.setCursor(0,0);
  lcd.print("Temp: ");
  lcd.print(temp);
  lcd.print(" C");
  
  lcd.setCursor(0,1);
  lcd.print("Humi: ");
  lcd.print(humi);
  lcd.print(" %");
  
  delay(2000);
}

/*

      © Techtronic Harsh
 
*/
Close Bitnami banner
Bitnami