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.
Step 1: Required Hardware
Arduino Board - https://goo.gl/Rqc5w2
DHT11 - https://goo.gl/n9qv8K
DHT22 - https://goo.gl/n9qv8K
LCD Display - https://goo.gl/n9qv8K
Potentiometer - https://goo.gl/n9qv8K
Breadboard - https://goo.gl/n9qv8K
Recommended Site - https://goo.gl/HDkZBt
Step 2: About DHT Sensor
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.
Step 3: Connection DHT
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.
Step 4: Connection LCD Display
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.
Step 5: Library and Source Code
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