Arduino - How to Use DHT11 and DHT22 Humidity and Temperature Sensor

by MertArduino in Circuits > Arduino

9560 Views, 42 Favorites, 0 Comments

Arduino - How to Use DHT11 and DHT22 Humidity and Temperature Sensor

Arduino Tutorial 34: How to use DHT11 and DHT22 sensors

In this tutorial we will learn how to use the DHT11 or the DHT22 sensor for measuring temperature and humidity.

And we will see the value output of the DHT sensors on both the serial monitor and the LCD screen. The LCD screen component is optional. With this tutorial you can also print on a serial monitor. Code and circuit diagram are compatible within both sensors.

Required Hardware

vlcsnap-2017-05-31-03h30m29s170.png

About DHT Sensor

vlcsnap-2017-05-31-03h30m43s567.png
vlcsnap-2017-05-31-03h30m52s249.png

DHT (temperature & humidity) sensors are very basic and slow, but are great for hobbyists who want to do some basic data logging. The DHT sensors are made of two parts, a capacitive humidity sensor and a thermistor.

Connection DHT

vlcsnap-2017-05-31-03h31m02s258.png
vlcsnap-2017-05-31-03h31m29s997.png
vlcsnap-2017-05-31-03h31m49s993.png

The DHT sensors have four pins, VCC, GND, data pin and a not connected pin which has no usage.

From left to right

1 - VCC (5V)

2 - Signal

3 - NC Not connected

4 - GND

A pull-up resistor from 5K to 10K Ohms is required to keep the data line high and in order to enable the communication between the sensor and the Arduino Board.

Connection LCD Display

vlcsnap-2017-05-31-03h33m01s402.png
vlcsnap-2017-05-31-03h33m20s516.png

LCD 16x02 Connection

The LCD has 16 pins and the first one from left to right is the Ground (GND) pin

The second pin is the VCC which we connect the +5V pin on the breadboard.

Next is the Vo pin on which we can attach a potentiometer for the contrast of the display

The RS pin will be connected to the digital 1 pin of the Arduino.

The RW pin will be connected to the GND pin of the breadboard.

The E pin will be connected to the digital 3 pin of the Arduino.

The D4 pin - Digital 4 of the Arduino.

The D5 pin will be connected to the digital 5 pin of the Arduino.

The D6 pin will be connected to the digital 6 pin of the Arduino.

The D7 pin will be connected to the digital 7 pin of the Arduino.

The A (anode) pin will be connected to the +5V pin of the breadboard.

The K (cathode) pin will be connected to the GND pin of the breadboard.

The potentiometer's other pins will be connected to the +5V and GND pin of the breadboard.

Library and Source Code

vlcsnap-2017-05-31-03h32m08s801.png
vlcsnap-2017-05-31-03h32m21s217.png
vlcsnap-2017-05-31-03h32m36s816.png
vlcsnap-2017-05-31-03h33m39s195.png

First we need to included the DHT library which can be found from the Arduino official website.

DHT Sensors Library - http://playground.arduino.cc/Main/DHTLib

After that we open DHT_test example code (To see the values on the serial monitor. Also to make DHT settings.)

Then define the pin number to which our sensor is connected and create a DHT object.

In the setup section we need to initiate the serial communication because we will use the serial monitor to print the results.

Using the read22() function we will read the data from the sensor and put the values of the temperature and the humidity into the T and H variables.

If you use the DHT11 sensor you will need to you the read11() function.

At the end we will print the temperature and the humidity values 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 - https://goo.gl/f2pJPp

You Can Subscribe to My YouTube Channel

mert arduino.png

You can subscribe to the my YouTube channel for more tutorials and projects. Subscribe for support. Thank you.

Go to my YouTube Channel - https://goo.gl/f0RHmR