Project tutorial
Arduino DTH22 Humidity Temperature With LCD I2C 16x2 Display

Arduino DTH22 Humidity Temperature With LCD I2C 16x2 Display © MIT

Check the humidity & temperature of your terrarium with a DTH22 humidity and temperature sensor and display this on an LCD I2C 16x2 display.

  • 48 respects

Components and supplies

About this project

For two years my son (7) had the desire to have a pet snake. Finally he bought a couple of snakes with a terrarium. To keep the snakes at a comfortable environment for them we need to monitor the temperature and the humidity.

So we bought an analogue humidity/temperature sensor and discovered that it wasn't all that easy to keep both at a good level. As I was dying to start a project with my newly bought Arduino Uno it seemed a good idea to use a humidity / temperature sensor and let the Arduino do the automation of temperature and humidity in the terrarium. Therefor I bought a DTH22 humidity / temperature sensor and a LCD I2C 16x2 display and had a go.

This tutorial is the basis of this project. There is no automation whatsoever in this tutorial. Just the use of the DTH22 and a LCD I2C display.

I have seen an other tutorial for this purpose, but this was using an LCD without the I2C. If you don't have the I2C connected to your LCD please have a look at this tutorial by ThothLoki

Hardware Required

  • Any 5V Arduino (in this case Arduino Uno R3)
  • DTH22 Humidity / temperature sensor
  • LCD 16x2 display with I2C mounted to it
  • Breadboard
  • 6 male/male jumper wires
  • 4 male/female jumper wires

Needed Libraries

Before we start

I like the LCD 16x2 with an I2C mounted because it saves you the trouble of all the pins that might or might not need to be connected to the Arduino. You only need 4 jumper wires and thats it.

The display has an I2C address to accept commands or send messages. The downside is that you need to figure out which address it uses before you can continue. I won't me going into the details here, but at the Arduino forum you can read everything about it.

In my case our device uses the 0x3F address, if your device also uses this address you're lucky, you can just copy our code.

Hook-up the breadboard to the Arduino

The DHT22 sensor as well as the LCD 1602 I2C use a 5V power supply. Therefore I connected the 5V pin on my Arduino to the red + row on the breadboard and the ground of my Arduino to the blue - on the breadboard. As I want to keep colors in sync, on my schema I will use red cables for 5V and blue cables for ground. In real life I didn't use blue for ground, but white... have been playing too much with car electronics I guess.

I will use a yellow cable for Data, an orange cable for SDA and a gray cable for SCL. The letter two will be on the I2C.

Adding the DHT22 sensor

Lets have a look at the pinout. The DHT22 sensor (like the DHT11) has four pins. I place the DHT22 sensor on the breadboard with the front facing outwards. This way the first pin (5V power) is on the right (see the schematics).

I use a small red jumper cable to connect the 5V VCC to the 5V (+) row on the breadboard. And a small blue jumper cable to connect the ground to the ground (-) row on the breadboard. I took a long yellow cable to connect the second pin, the data pin, to the Arduino. As it is digital data, I connected this to data port 4 on the Arduino. In other examples you will probably see people using port 7, both will work. I used port 4 because I anticpated that I will use more data ports and wanted to save port 7 just in case. You will also see this in the schema's.

Adding the LCD 16x2 I2C

The LCD 16x2 I2C also has 4 pins. Looking at the picture below, from left to right:

  • Ground
  • VCC (5V)
  • SDA
  • SCL

Connect the first (left) pin to the ground (-) row on the breadboard. Connect the second pin to red the 5V (+) row of the breadboard. I use an Arduino Uno so which has the I2C connections on A4 (SDA) and A5 (SCL). So I connected the third pin to the A4 and the fourth pin to A5 connector on the Arduino.

The code

Remember for the screen you can have different address' to connect to. My I2C uses address 0x3F (see part 'Before we start') so beware that my code is setup for this address.

Remember the libraries needed (Adafruit_Sensor, DHT, NewliquidCrystal). Download these libraries, unzip them and place these in the libraries directroy of your project.

Then upload the code to your Arduino and check the humidity and temperature of your terrarium (or server cabinet, or refrigerator or just your living room).


/* How to use the DHT-22 sensor with Arduino uno
   Temperature and humidity sensor
   More info:
   Dev: Michalis Vasilakis // Date: 1/7/2015 // 

#include <DHT.h>
#include <Wire.h> 
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define DHTPIN 4     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino

#define I2C_ADDR 0x3F
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value

void setup()

void loop()
  //Read data and store it to variables hum and temp
  hum = dht.readHumidity();
  temp = dht.readTemperature();
  //Print temp and humidity values to serial monitor
  Serial.print("Humidity: ");
  Serial.print(" %, Temp: ");
  Serial.println(" Celsius");

  lcd.print("Temp: ");
  lcd.print(" ");
  lcd.print("Hum:  ");
  lcd.print(" %");

  delay(2000); //Delay 2 sec.



Fritzing Schema
Schema Fritzing
Screen shot 2017 02 26 at 20 grlbif7dqy


Similar projects you might like

DHT11 Humidity + Temperature Sensor with 16x2 LCD display

Project showcase by onatto22

  • 1 comment
  • 17 respects

Temperature + Humidity on LCD

Project showcase by interpeo

  • 49 respects

Date, Time, Temperature and Humidity Display

Project tutorial by Chamath Vithanawasam

  • 29 respects

Sound Sensor Activated LEDs with LCD for Sound Level Data!

Project tutorial by Heathen_Hacks-v2

  • 8 respects

Temperature and Humidity Data Logger

Project tutorial by Wimpie van den Berg

  • 22 respects
Add projectSign up / Login