Arduino with DHT22 sensor and LCD

Arduino uno board with DHT22 sensor and LCD

After the interfacing of the Arduino with DHT11 (RHT01) sensor, let’s see how to connect the Arduino with DHT22 (AM2302 – RHT03) digital humidity and temperature sensor.
Arduino interfacing with DHT11 sensor and LCD

As what was done in the previous topic, the measured temperature and humidity values are displayed on 1602 LCD screen.

DHT22 Sensor technical specifications:

  • Humidity Range: 0 ~ 100% RH
  • Humidity Accuracy: ±2% RH (max ±5% RH)
  • Temperature Range: -40 ~ 80 °C
  • Temperature Accuracy: ±0.5 °C
  • Operating Voltage: 3.3V ~ 5.5V
  • Resolution = 0.1

Hardware Required:

  • Arduino board
  • DHT22 (or AM2302 – RHT03) sensor
  • 1602 LCD screen
  • 4.7K ohm resistor
  • 10K ohm variable resistor (or potentiometer)
  • 330 ohm resistor
  • Breadboard
  • Jumper wires

Arduino + DHT22 + LCD connection circuit:
Interfacing circuit diagram is shown below.

Arduino DHT22 LCD interfacing circuit

The DHT22 has 4 pins: VCC (+5V), Data pin, NC(not connected pin) and GND (from left to right). A pull-up resistor should be added to the data pin with a value between 4.7K and 10K.

The 10K variable resistor is used to control the contrast of the LCD screen and the 330 ohm resistor supplies the LCD backlight LED.

Arduino Code:
In this interfacing I used DHT sensors library (DHT11, DHT21 and DHT22) from Adafruit. This library initiates the DHT22 sensor and reads the values of the humidity and temperature.
The Adafruit DHT library returns a float number of the humidity as well as the temperature and since the resolution of the DHT22 sensor is 0.1 we need only 1 number after the point. For that I used two variables with type int (signed 16-bit) which are RH and Temp. multiplying the float numbers by 10 gives us what we need as an integer numbers without any point.
The integer values of the humidity and temperature needs to be displayed on the LCD after the reading, and for that I used two character arrays named: temperature (char temperature[] = “Temp = 00.0 C “;) and humidity (char humidity[] = “RH = 00.0 % “;). Humidity and temperature values are copied to the previous arrays before displaying it. For example the temperature value is copied to the array temperature as follows:
temperature[7] = (Temp / 100) % 10 + 48;
This line means the 7th character of the array is equal to the hundreds Temp

temperature[8] = (Temp / 10) % 10 + 48;
this line means the 8th character of the array is equal to the tens of Temp

temperature[10] = Temp % 10 + 48;  (Temp%10 equals to the remainder of Temp/10)
and this line means the 10th character of the array is equal to the ones of Temp

For example if the temperature = 37.2 °C and this is the value which the Adafruit library returns using the function dht.readTemperature(), by multiplying this value by 10 we get 372.
yields: (372 / 100) % 10 = 3
(372 / 10) % 10  = 7
372 % 10  = 2
The number 48 is used to convert decimal numbers to AscII because the LCD works with AscII format.
The line temperature[11] = 223; is for the degree symbol ( °).
The full Arduino code is below.

Arduino + DHT22 simulation video:
The video below shows simulation of the example using Proteus.

Downloads:
Adafruit library for DHT series (after extracting put the folder named DHT in the library folder of Arduino):
Download

To be able to simulate this example, Proteus needs the Arduino library which can be downloaded from the link below. After extracting the files (ARDUINO.IDX and ARDUINO.LIB) put it in the Library folder (ex: C:\Program Files\Labcenter Electronics\Proteus 8 Professional\LIBRARY):
Download

Arduino + DHT22 + LCD Proteus simulation file download:
Download

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.