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

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • DHT11 Sensor x 1
  • I2C LCD1602 x 1
  • 10k ohm Resistor x 1
  • Breadboard x 1
  • Jumpers
  • USB Cable x 1
  • PC x 1

Software

About DHT11

The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin (no analog input pins needed). Its fairly simple to use, but requires careful timing to grab data.

Only three pins are available for use: VCC, GND, and DATA. The communication process begins with the DATA line sending start signals to DHT11, and DHT11 receives the signals and returns an answer signal. Then the host receives the answer signal and begins to receive 40-bit humiture data (8-bit humidity integer + 8-bit humidity decimal + 8-bit temperature integer + 8-bit temperature decimal + 8-bit checksum).

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

Dimension of DHT11

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

Build the circuit as below:

Simply ignore pin 3 of DHT11, its not used. You will want to place a 10K resistor between VCC and the data pin, to act as a medium-strength pull up on the data line. The Arduino has built in pullups you can turn on but they’re very weak, about 20-50K

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

Build the circuit 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.

Leave a Reply

WordPress spam blocked by CleanTalk.
Bombax Theme designed by itx