Arduino using DHT11

DHT11 Temperature and Humidity Sensor

Introduction

This DHT11 Temperature and Humidity Sensor features a calibrated digital signal output with the temperature and humidity sensor capability. It is integrated  with a high-performance 8-bit microcontroller. Its technology ensures the high reliability and excellent long-term stability.  This sensor includes a resistive element and a sensor for wet NTC temperature measuring devices. It has excellent quality, fast response, anti-interference ability and high performance.

Each DHT11 sensors features extremely accurate calibration of humidity calibration chamber. The calibration coefficients stored in the OTP program memory, internal sensors detect signals in the process, we should call these calibration coefficients. The single-wire serial interface system is integrated to become quick and easy. Small size, low power, signal transmission distance up to 20 meters, enabling a variety of applications and even the most demanding ones. The product is 4-pin single row pin package. Convenient connection, special packages can be provided according to users need.

Specification

  • Supply Voltage: +5 V
  • Temperature range :0-50 °C error of ± 2 °C
  • Humidity :20-90% RH ± 5% RH error
  • Interface: Digital

Many low cost sensors have unusual output formats, and in this case, a “Manchester-esque” output that is not SPI, I2C or 1-Wire compatible must be polled continuously.

In this tutorial we will learn how to use a DHT (DHT11 version) Temperature and Humidity Sensor.

First I’ll  go into a little background about humidity, then I’ll explain how the DHT11 measures humidity.

DHT11 / DHT22 Working Principle

Ok now let’s see how these sensors actually work. They consist of a humidity sensing component, a NTC temperature sensor (or thermistor) and an IC on the back side of the sensor.’

Related image

For measuring humidity they use the humidity sensing component which has two electrodes with moisture holding substrate between them. So as the humidity changes, the conductivity of the substrate changes or the resistance between these electrodes changes. This change in resistance is measured and processed by the IC which makes it ready to be read by a microcontroller.

On the other hand, for measuring temperature these sensors use a NTC temperature sensor or a thermistor.

A thermistor is actually a variable resistor that changes its resistance with change of the temperature. These sensors are made by sintering of semiconductive materials such as ceramics or polymers in order to provide larger changes in the resistance with just small changes in temperature. The term “NTC” means “Negative Temperature Coefficient”, which means that the resistance decreases with increase of the temperature.

Components Required

  • Arduino UNO
  • DHT11 Temperature and Humidity Sensor
  • Breadboard (or perfboard)
  • Power supply
  • Connecting wires

Circuit Description

Image result for DHT with arduino

We will see the circuit design of DHT11 interfacing with Arduino. The DHT11 Humidity and Temperature sensor comes in two variants: just the sensor or a module.

The main difference is that the module consists of the pull – up resistor and may also include a power on LED. We have used a module in this project and if you wish to use the sensor itself, you need to connect a 5K Ω pull – up resistor additionally.

Step 1: How to Include DHT Library

  • Please download the DHT library from the below link.

          DHTLib

  • Go to Sketch–> Include Library –> Add Zip File
  • As shown in the above screen shot please browse the ZIP file and include the library after including the library.
  • Close the Arduino IDE and open it again then you will find the library included.

Step 2: Program and Results

Program

/*  DHT11/ DHT22 Sensor Temperature and Humidity Tutorial
 *  www.genbays.com 
 */
/*
 * You can find the DHT Library from Arduino official website
 * https://github.com/adafruit/DHT-sensor-library
 */
 
#include <dht.h>

#define dataPin 7 // Defines pin number to which the sensor is connected
dht DHT; // Creats a DHT object

void setup() {
  Serial.begin(9600);
}
void loop() {
  int readData = DHT.read22(dataPin); // Reads the data from the sensor
  float t = DHT.temperature; // Gets the values of the temperature
  float h = DHT.humidity; // Gets the values of the humidity
  
  // Printing the results on the serial monitor
  Serial.print("Temperature = ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print("    Humidity = ");
  Serial.print(h);
  Serial.println(" % ");
  
  delay(2000); // Delays 2 secods, as the DHT22 sampling rate is 0.5Hz
}

After we will upload this code to the Arduino board, the temperature and humidity results from the sensor can be seen on the Serial monitor.

I also made an example where I display the results on a LCD. Here’s the source code of that example:

Components Required

  • Arduino UNO
  • DHT11 Temperature and Humidity Sensor
  • Breadboard (or perfboard)
  • Power supply
  • 16 x 2 LCD Display
  • 10K Ohm Potentiometer
  • 5K Ohm Resistor (1/4 W)
  • Connecting wires

Image result for DHT with arduino lcd

/*  DHT11/ DHT22 Sensor Temperature and Humidity Tutorial
 *  www.genbays.com 
 */
/*
 * You can find the DHT Library from Arduino official website
 * https://github.com/adafruit/DHT-sensor-library
 * You can find the LCD Library from Arduino official website
 * https://github.com/arduino-libraries/LiquidCrystal
 */
 
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
#include <dht.h>
#define dataPin 2 // Defines pin number to which the sensor is connected
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)
dht DHT; // Creats a DHT object
void setup() {
  lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
}
void loop() {
  int readData = DHT.read22(dataPin);
  float t = DHT.temperature;
  float h = DHT.humidity;
  lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
  lcd.print("Temp.: "); // Prints string "Temp." on the LCD
  lcd.print(t); // Prints the temperature value from the sensor
  lcd.print(" C");
  lcd.setCursor(0,1);
  lcd.print("Humi.: ");
  lcd.print(h);
  lcd.print(" %");
  delay(2000);
}