Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES Buy from JP

Content

  1. Introduction
  2. Preparations
  3. About the DHT11
  4. Examples

Introduction

The digital temperature and humidity sensor DHT11 inside contains a chip that does analog to digital conversion and spits out a digital signal with the temperature and humidity, compatible with any MCUs, ideal for those who want some basic data logging stuffs. It’s very popular for electronics hobbyists because it is very cheap but still providing great performance.

In this lesson, we will first go into a little background about humidity, then we will explain how the DHT11 measures humidity. After that, we will show you how to connect the DHT11 to an Arduino and give you some example code so you can use the DHT11 in your own projects.

Preparations

Hardware

Software

About DHT11 module

WHAT IS RELATIVE HUMIDITY?

The DHT11 measures relative humidity. Relative humidity is the amount of water vapor in air vs. the saturation point of water vapor in air. At the saturation point, water vapor starts to condense and accumulate on surfaces forming dew.

The saturation point changes with air temperature. Cold air can hold less water vapor before it becomes saturated, and hot air can hold more water vapor before it becomes saturated.

The formula to calculate relative humidity is:

RH = (\frac{\rho_{w}}{\rho_{s}}) \ x \ 100 \% \\ \\ RH: \ Relative \ Humidity \\ \rho_{w}: \ Density \ of \ water \ vapor\\ \rho_{s}: \ Density \ of \ water \ vapor \ at \ saturation

Relative humidity is expressed as a percentage. At 100% RH, condensation occurs, and at 0% RH, the air is completely dry.

HOW THE DHT11 MEASURES HUMIDITY AND TEMPERATURE

The DHT11 detects water vapor by measuring the electrical resistance between two electrodes. The humidity sensing component is a moisture holding substrate with electrodes applied to the surface. When water vapor is absorbed by the substrate, ions are released by the substrate which increases the conductivity between the electrodes. The change in resistance between the two electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes, while lower relative humidity increases the resistance between the electrodes.

The DHT11 measures temperature with a surface mounted NTC temperature sensor (thermistor) built into the unit.

With the plastic housing removed, you can see the electrodes applied to the substrate, an IC mounted on the back of the unit converts the resistance measurement to relative humidity. It also stores the calibration coefficients, and controls the data signal transmission between the DHT11 and the Arduino:

Diffrences Between DHT11 and DHT22

Examples

Before you can use the DHT11 on the Arduino, you’ll need to install the DHT library. It has all the functions needed to get the humidity and temperature readings from the sensor. It’s easy to install, just download the DHT.zip file and open up the Arduino IDE. Then go to Sketch>Include Library>Add .ZIP Library and select the DHT.zip file.

Display Humidity and Temperature on the Serial Monitor

Connection

First, please plug OSOYOO Magic I/O shield into UNO board:

Then connect the OSOYOO Temp & Humi Module to the port D3 of the Magic I/O shield with 3-pin PNP cables as below:

This diagram shows how we will connect for the testing sketch. Connect data to pin 3, you can change it later to any pin.

Code Program

After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on. Load up the following sketch onto your Arduino.

#include<dht.h> dht DHT; // if you require to change the pin number, Edit the pin with your Arduino pin. #define DHT11_PIN 3 void setup() { Serial.begin(9600); Serial.println("The real time Temperature and Humidity is :"); } void loop() { // READ DATA int chk = DHT.read11(DHT11_PIN); Serial.print(" Humidity: " ); Serial.print(DHT.humidity, 1); Serial.println('%'); Serial.print(" Temparature "); Serial.print(DHT.temperature, 1); Serial.println('C'); delay(2000); }

Running Result

A few seconds after the upload finishes, open the Serial Monitor, you should now see the humidity and temperature readings displayed at one second intervals.

Note: Please make sure you have choosed the correct port and the correct baudrate for you project.

Display Humidity and Temperature on the I2C 1602LCD

A nice way to display the humidity and temperature readings is on a 1I2C 1602LCD. To do this, first follow our tutorial on How to Set Up an LCD Display on an Arduino, then follow below operations and complete this project.

Connection

Connect the OSOYOO Temp & Humi Module to the port D3 of the Magic I/O shield with 3-pin PNP cables and connect the OSOYOO 1602 I2C LCD Screen to the port I2C of the Magic I/O shield with 4-pin PNP cables as below:

Code Program

After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. Then load up the following sketch onto your Arduino.

#include <Wire.h> #include <LiquidCrystal_I2C.h> #include<dht.h> dht DHT; LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display #define DHT11_PIN 3 void setup() { lcd.begin(16,2); lcd.init(); // initialize the lcd  // Print a message to the LCD. lcd.backlight(); lcd.clear(); lcd.print("Humidity & temp"); delay(3000); lcd.clear(); lcd.print("Starting....."); delay(3000); } void loop() { // READ DATA int chk = DHT.read11(DHT11_PIN); lcd.clear(); delay(500); lcd.setCursor(0, 0); // print from 0 to 9: lcd.print("Temp    : "); lcd.print(DHT.temperature, 1); lcd.print(" C"); // set the cursor to (16,1): lcd.setCursor(0,1); lcd.print("Humidity: "); lcd.print(DHT.humidity, 1); lcd.print(" %"); delay(2000); }

Running Result

A few seconds after the upload finishes, you should now see the value of current humidity and temperature displayed on the LCD.