Humidity and Temperature Measurement using Arduino

Published  July 17, 2015   17
S Saddam
Author
Arduino Uno Humidity Sensor Project

Humidity and temperature are common parameters to measure environmental conditions. In this Arduino based project we are going to measure ambient temperature and humidity and display it on a 16x2 LCD screen. A combined temperature and himidity sensor DHT11 is used with Arduino uno to develop this Celsius scale thermometer and percentage scale humidity measurement project. In one of my previous project, I have also developed a digital thermometer using temperature sensor LM35.

 

This project consists of three sections - one senses the humidity and temperature by using humidity and temperature sensor DHT11. The second section reads the DHTsensor module’s output and extracts temperature and humidity values into a suitable number in percentage and Celsius scale. And the third part of the system displays humidity and temperature on LCD.

Arduino Humidity and Temperature Sensor Block Diagram

Working of this project is based on single wire serial communication. First arduino send a start signal to DHT module and then DHT gives a response signal containing temperature and humidity data. Arduino collect and extract in two parts one is humidity and second is temperature and then send them to 16x2 LCD.

 

Here in this project we have used a sensor module namely DHT11. This module features a humidity and temperature complex with a calibrated digital signal output means DHT11 sensor module is a combined module for sensing humidity and temperature which gives a calibrated digital output signal. DHT11 gives us very precise value of humidity and temperature and ensures high reliability and long term stability. This sensor has a resistive type humidity measurement component and NTC type temperature measurement component with an 8-bit microcontroller inbuilt which has a fast response and cost effective and available in 4-pin single row package.

DHT11 sensor

DHT11 module works on serial communication i.e. single wire communication. This module sends data in form of pulse train of specific time period. Before sending data to arduino it needs some initialize command with a time delay. And the whole process time is about 4ms. A complete data transmission is of 40-bit and data format of this process is given below:

8-bit integral RH data + 8-bit decimal RH data + 8-bit integral T data + 8-bit decimal T data + 8-bit check sum.

 

Complete Process

First of all arduino sends a high to low start signal to DHT11 with 18µs delay to ensure DHT’s detection. And then arduino pull-up the data line and wait for 20-40µs for DHT’s response. Once DHT detects starts signal, it will send a low voltage level response signal to arduino of time delay about 80µs. And then DHT controller pull up the data line and keeps it for 80µs for DHT’s arranging of sending data.

 

When data bus is at low voltage level it means that DHT11 is sending response signal. Once it is done, DHT again makes data line pull-up for 80µs for preparing data transmission.

Data format that is sending by DHT to arduino for every bit begins with 50µs low voltage level and length of high voltage level signal determines whether data bit is “0” or “1”.

Arduino Uno DHT11

One important thing is to make sure pull up resistor value because if we are placing DHT sensor at <20 meter distance, 5k pull up resistor is recommended. If placing DHT at longer the 20 meter then use appropriate value pull up resistor.

 

Circuit Diagram and Explanation

Arduino Humidity Sensor Circuit Diagram

A liquid crystal display is used for displaying temperature and humidity which is directly connected to arduino in 4-bit mode. Pins of LCD namely RS, EN, D4, D5, D6 and D7 are connected to arduino digital pin number 2, 3, 4, 5, 6 and 7. And a DHT11 sensor module is also connected to digital pin 12 of arduino with a 5k pull-up resistor.

 

Programming Description

In programming, we are going to use pre-built libraries for DHT11 sensor and LCD display module. 

Header file

Then we haved defined pins for LCD and DHT sensor and initialized all the things in setup. Then in a loop by using dht function reads DHT sensor and then using some dht functions we extract humidity and temperature and display them on LCD.

Humidity and Temperature value program

Here degree symbol is created by using custom character method.

degree symbol

Code

#include<dht.h>      // Including library for dht
#include<LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

#define dht_dpin 12 

dht DHT;

byte degree[8] = 
              {
                0b00011,
                0b00011,
                0b00000,
                0b00000,
                0b00000,
                0b00000,
                0b00000,
                0b00000
              };

void setup()
{
 lcd.begin(16, 2);
 lcd.createChar(1, degree);
 lcd.clear();
 lcd.print("   Humidity   ");
 lcd.setCursor(0,1);
 lcd.print("  Measurement ");
 delay(2000);
 lcd.clear();
 lcd.print("Circuit Digest ");
 delay(2000);
}

void loop()
{
  DHT.read11(dht_dpin);
  lcd.setCursor(0,0);
  lcd.print("Humidity: ");
  lcd.print(DHT.humidity);   // printing Humidity on LCD
  lcd.print(" %");
  lcd.setCursor(0,1);
  lcd.print("Temperature:");
  lcd.print(DHT.temperature);   // Printing temperature on LCD
  lcd.write(1);
  lcd.print("C");
  delay(500);
}

Video

Comments

Submitted by ain adinan on Tue, 09/29/2015 - 20:33

Permalink

hi. i want to know name of the parts that you use because the are not same as mine. what proteus you used? i also have a problem regarding the arduino libraries in proteus. i could'nt find the arduino's part in proteus library. i've check that my proteus 8 does'nt have the library folder after installed. please help me. thank you

You can clearly see the parts used, Arduino Uno, 16X2 LCD and DHT11 Temperature and humidity sensor. Proteus doesn't come with Arduino installed, you need to add Arduino Library in Proteus. Library folder can be found at Proteus 8 Professional\Data\LIBRARY

Submitted by DP on Thu, 02/11/2016 - 09:48

Permalink

I have both the DHT sensor library as well as the LCD library but your code won't compile. Why?

Submitted by Wambat on Fri, 04/01/2016 - 14:39

Permalink

I get a compile error
temp_humid_display:7: error: 'dht' does not name a type
dht DHT;

Submitted by Naman Chauhan on Wed, 01/11/2017 - 13:19

Permalink

its showing up errors even after adding libraries. the error message is :
Arduino: 1.8.1 (Windows 7), Board: "Arduino/Genuino Uno"

sketch_jan11a:5: error: no matching function for call to 'DHT::DHT()'

DHT dht;

^

C:\Users\user\Desktop\sketch_jan11a\sketch_jan11a\sketch_jan11a.ino:5:5: note: candidates are:

In file included from C:\Users\user\Desktop\sketch_jan11a\sketch_jan11a\sketch_jan11a.ino:1:0:

C:\Users\user\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:40:4: note: DHT::DHT(uint8_t, uint8_t, uint8_t)

DHT(uint8_t pin, uint8_t type, uint8_t count=6);

^

C:\Users\user\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:40:4: note: candidate expects 3 arguments, 0 provided

C:\Users\user\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:38:7: note: constexpr DHT::DHT(const DHT&)

class DHT {

^

C:\Users\user\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:38:7: note: candidate expects 1 argument, 0 provided

C:\Users\user\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:38:7: note: constexpr DHT::DHT(DHT&&)

C:\Users\user\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:38:7: note: candidate expects 1 argument, 0 provided

C:\Users\user\Desktop\sketch_jan11a\sketch_jan11a\sketch_jan11a.ino: In function 'void loop()':

sketch_jan11a:32: error: 'class DHT' has no member named 'read11'

dht.read11(dht_dpin);

^

sketch_jan11a:35: error: 'class DHT' has no member named 'humidity'

lcd.print(dht.humidity); // printing Humidity on LCD

^

sketch_jan11a:39: error: 'class DHT' has no member named 'temperature'

lcd.print(dht.temperature); // Printing temperature on LCD

^

exit status 1
no matching function for call to 'DHT::DHT()'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Submitted by Rahul Ramesh on Tue, 04/18/2017 - 20:38

Permalink

Problem solved Sometimes higher version of dht library file is not supported so use lower version like 1.0.0 by adafruit and try it. Happy coding.

Submitted by mohamed abdel-hamid on Fri, 04/28/2017 - 03:12

Permalink

I tried to use the lower version 1.0.0 nut still give error : 'dht' does not name a type !!