Intro
You can read temperature and humidity on a laptop screen, but a real project needs a display of its own. A small LCD on the wall of a room, a greenhouse or a shop tells everyone the climate at a glance, with no computer attached.
In this tutorial you will build a temperature and humidity monitor with the DHT11 sensor and Arduino Uno, with the readings shown on a 16×2 LCD display. You will wire the sensor and the LCD, install two libraries, and write code that updates the display every two seconds and flashes a HOT warning when the room passes 30 °C. You will also learn how the DHT11 differs from the DHT22, so you can choose the right sensor for your next project.
What You Need
| Part | Quantity | Purpose |
|---|---|---|
| DHT11 temperature & humidity sensor | 1 | Measures temperature and humidity |
| Arduino UNO R3 DIP ATmega328P with USB cable | 1 | Runs the code and reads the sensor |
| LCD1602 16×2 display with I2C module | 1 | Shows temperature and humidity |
| MB102 breadboard, 830 points | 1 | Holds the sensor without soldering |
| 40-pin Dupont jumper wires, male-to-male | 7 | Connects the sensor and LCD to the Uno |
A ready-made version of this project is also available on order, and all the components above are available in our store.
How the DHT11 Measures Temperature and Humidity
The DHT11 is a small blue sensor with a capacitive humidity element, an NTC thermistor and a tiny chip inside. The chip turns both measurements into digital numbers, so the Arduino reads them over a single digital wire. There is no analog signal to calibrate and no extra circuit to build.
A reading starts when the Arduino pulls the DATA line LOW for at least 18 milliseconds. The sensor wakes up and sends back 40 bits: humidity, temperature, and a checksum byte. The library checks the checksum. If it does not match, the reading is discarded and the code gets a NaN value instead of a number.
The sensor is slow and coarse, and it is better to know that now than to discover it later. It gives at most one reading per second, so this project reads every two seconds. Its resolution is 1 °C and 1 % RH, so the decimal part is always zero. A reading of 27 °C and 54 % is all the detail you will get. That is enough for a room display, a weather station or a greenhouse alarm. It is not enough for a laboratory. The full numbers are in the DHT11/DHT22 datasheet.
DHT11 vs DHT22
The DHT22 (also sold as the AM2302) looks nearly identical and uses the same wiring and the same library. The difference is the sensing element inside.
| Feature | DHT11 | DHT22 (AM2302) |
|---|---|---|
| Temperature range | 0 to 50 °C | −40 to 80 °C |
| Temperature accuracy | ±2 °C | ±0.5 °C |
| Humidity range | 20 to 90 % RH | 0 to 100 % RH |
| Humidity accuracy | ±5 % RH | ±2 to 5 % RH |
| Resolution | 1 °C, 1 % RH | 0.1 °C, 0.1 % RH |
| Fastest reading | once per second | once every 2 seconds |
| Power | 3 to 5 V, 2.5 mA max | 3 to 5 V, 2.5 mA max |
Pick the DHT11 for room displays, weather stations and most student projects. Pick the DHT22 when you need decimal readings, freezing temperatures, or accuracy better than ±2 °C. The code in this tutorial works for both. Change one word, DHT11 to DHT22, and nothing else.
Key specifications of the DHT11:
| Specification | Value |
|---|---|
| Operating voltage | 3 to 5 V DC |
| Working current | 2.5 mA max during conversion |
| Temperature range | 0 to 50 °C, ±2 °C accuracy |
| Humidity range | 20 to 90 % RH, ±5 % RH accuracy |
| Resolution | 1 °C, 1 % RH |
| Sampling rate | 1 Hz max (once per second) |
| Interface | Single-wire digital |
| Size | 15.5 x 12 x 5.5 mm |
DHT11 and LCD Wiring with Arduino Uno
The DHT11 module has three pins. The LCD1602 with I2C module has four pins and needs only two data wires, because the small I2C backpack on its back handles the rest. Connect everything while the Uno is unplugged from USB.
| DHT11 module pin | Arduino Uno pin |
|---|---|
| VCC | 5V |
| DATA | D2 |
| GND | GND |
| LCD1602 I2C pin | Arduino Uno pin |
|---|---|
| VCC | 5V |
| GND | GND |
| SDA | A4 |
| SCL | A5 |
On the Uno, pins A4 and A5 are the I2C bus. That is why the LCD connects there and nowhere else. The DHT11 DATA pin can go to any digital pin; D2 is used here because it is free and easy to remember.
Two things to check before powering on. First, the bare 4-pin DHT11 sensor (not the module) has a different pinout: pin 1 VCC, pin 2 DATA, pin 3 not connected, pin 4 GND. The bare sensor also needs a 10k ohm pull-up resistor between DATA and VCC. The ready-made module already has that resistor on board. Second, the LCD has a small blue potentiometer on its I2C backpack. That sets the screen contrast. If the display lights up but shows only solid blocks or nothing at all, turn that screw slowly with a small screwdriver until the text appears.

Library Installation
- In the Arduino IDE, open Sketch > Include Library > Manage Libraries.
- Search for “DHT sensor library” and install the one by Adafruit.
- Search for “Adafruit Unified Sensor” and install it as well. The DHT library needs it.
- Search for “LiquidCrystal I2C” and install the one by Frank de Brabander. That is the library for the LCD backpack.
- Restart the IDE if the examples do not appear.
Complete Arduino Code
/*
DHT11 Temperature and Humidity Monitor with LCD - Arduino Uno
Reads the DHT11 every 2 seconds and shows temperature and
humidity on a 16x2 LCD with an I2C backpack. A HOT warning
appears on the display when the room passes 30 degrees C.
Needs the Adafruit "DHT sensor library", "Adafruit Unified
Sensor" and "LiquidCrystal I2C" libraries.
To use a DHT22 instead, change DHT11 to DHT22 below.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#define DHT_PIN 2 // DHT11 DATA pin
#define DHT_TYPE DHT11 // Change to DHT22 for a DHT22 sensor
const float HOT_ALERT_C = 30.0; // HOT warning above this
const unsigned long READ_INTERVAL_MS = 2000; // DHT11: max 1 reading/sec
// Most I2C LCD backpacks use address 0x27, 16 columns, 2 rows.
LiquidCrystal_I2C lcd(0x27, 16, 2);
DHT dht(DHT_PIN, DHT_TYPE);
unsigned long lastReadTime = 0;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
dht.begin();
lcd.setCursor(0, 0);
lcd.print("DHT11 Monitor");
lcd.setCursor(0, 1);
lcd.print("Starting...");
delay(1500);
lcd.clear();
}
// Read the sensor once and update the LCD.
// A failed reading leaves the last good values on screen.
void updateDisplay() {
float humidity = dht.readHumidity();
float tempC = dht.readTemperature(); // Celsius by default
if (isnan(humidity) || isnan(tempC)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(tempC, 1);
lcd.print((char)223); // degree symbol
lcd.print("C ");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(humidity, 0);
lcd.print("% ");
if (tempC > HOT_ALERT_C) {
lcd.setCursor(13, 0);
lcd.print("HOT");
}
Serial.print(tempC, 1);
Serial.print(" C | ");
Serial.print(humidity, 0);
Serial.println(" %");
}
void loop() {
unsigned long now = millis();
// millis() timing: read on a schedule, never with delay().
if (now - lastReadTime >= READ_INTERVAL_MS) {
lastReadTime = now;
updateDisplay();
}
}Note: the delay(1500) in setup() only shows the welcome message for a moment at startup. The main loop has no delay() at all.
Code Explanation
Includes at the top. Wire.h is the built-in I2C library the LCD needs. LiquidCrystal_I2C.h drives the LCD backpack. Adafruit_Sensor.h and DHT.h are the sensor libraries. All four must be installed, or the code will not compile.
Constants. DHT_PIN is 2, matching the wiring table. DHT_TYPE is DHT11. Change that one word to DHT22 for a DHT22 sensor. HOT_ALERT_C is 30.0. READ_INTERVAL_MS is 2000, safely above the DHT11’s one-reading-per-second limit and slow enough for a DHT22 as well.
LiquidCrystal_I2C lcd(0x27, 16, 2) creates the display object. 0x27 is the I2C address most backpacks use, and 16, 2 is the size of the screen. If your LCD stays blank, try 0x3F instead of 0x27. lcd.init() and lcd.backlight() in setup() start the display and switch its backlight on.
updateDisplay() does one reading and one screen update. It reads humidity and temperature, then checks both with isnan(). A failed reading returns early, so the LCD keeps showing the last good values instead of nonsense. The temperature line prints “Temp: 27.0 °C” using character 223 for the degree symbol. The trailing spaces after each value wipe out leftover characters when a shorter number replaces a longer one. If the temperature is above 30 °C, the word HOT appears at the top right of the screen.
loop() has no delay(). It checks the clock with millis() and calls updateDisplay() every two seconds. The display is only rewritten when a new reading exists, which keeps it flicker-free.
Demonstration: Expected LCD and Serial Monitor Output
Upload the code. The LCD first shows “DHT11 Monitor” and “Starting…”, then after two seconds it shows the readings:
Temp: 27.0 °C
Humidity: 54%
Open the Serial Monitor at 9600 baud and you will see the same values:
DHT11 Monitor ready
27.0 C | 54 %
27.0 C | 54 %
28.0 C | 52 %
Breathe gently on the sensor and the humidity number climbs. Hold a warm cup near it (not touching) and the temperature rises. When it passes 30 °C, the word HOT appears at the top right of the LCD. The numbers move slowly, one step every two seconds, because the sensor itself is slow. That is normal.
Need Help with the Build?
Troubleshooting
- The LCD lights up but shows nothing, or only solid blocks. The contrast is wrong. Turn the small blue potentiometer on the I2C backpack slowly with a screwdriver until the text appears. If the screen stays blank, the I2C address may be different. Change 0x27 to 0x3F in the code and upload again.
- The LCD shows “Starting…” and never changes. The sensor is not answering. Check that DATA is on D2 and matches DHT_PIN, VCC is on 5V, and GND is on GND. If you use the bare 4-pin sensor instead of the module, add the 10k pull-up resistor between DATA and VCC. Also check that DHT_TYPE matches the sensor you bought.
- The monitor shows “Failed to read from DHT sensor!”. The reading failed the checksum test. A loose DATA wire is the usual cause. Check the jumper wires, then check that the reading interval is at least two seconds. A single failed reading now and then is normal; a failure every time means wiring.
- The temperature is 2 °C higher than another thermometer. That is within the DHT11’s ±2 °C accuracy, so it is not a fault. Keep the sensor away from the Uno’s voltage regulator and out of direct sunlight. Both warm the little blue case and push the reading up.
- The code does not compile: “LiquidCrystal_I2C.h: No such file or directory”. The LCD library is not installed. Install “LiquidCrystal I2C” by Frank de Brabander from the Library Manager. The error message names the missing file, so install the library that provides it.
- The code compiles, but the LCD shows old values that never change. The loop may be stuck. Check that READ_INTERVAL_MS is 2000 and that there is no delay() inside loop(). Also check the Serial Monitor: if it prints new values but the LCD does not, the I2C wires SDA and SCL may be loose. They must be on A4 and A5.
Project Ideas and FYP Ideas Using the DHT11
- Classroom climate board. Mount the LCD on a classroom wall with the DHT11 beside it. Add a second line that shows the time from a DS3231 real-time clock module. Teachers can see the room climate at a glance, and the build is cheap enough for every classroom.
- Greenhouse display and fan control. Put the sensor and LCD in a small greenhouse. Add a relay module and a DC fan. When the temperature passes 32 °C the fan starts, and the LCD shows both the temperature and the fan state. It is a strong FYP because it senses, displays and acts.
- Medicine fridge monitor. A DHT22 (not the DHT11, because it must read below zero) inside a medicine fridge, with the LCD outside the door. If the temperature rises above 8 °C, the display flashes a warning. Pharmacies use exactly this idea.
- Home weather station. Combine the DHT11 with an LCD and a real-time clock. Record the highest and lowest temperature of the day on the second line of the display. Reset the values at midnight. It is a complete daily weather record with no computer.
- Egg incubator monitor. A DHT11 or DHT22 inside a small incubator box, with the LCD showing temperature and humidity and a relay switching a small bulb heater. The display lets the user check the conditions without opening the box and losing heat.
Frequently Asked Questions
Which is better, DHT11 or DHT22?
For most student projects, the DHT11 is enough. It is cheaper and reads once a second. The DHT22 is better when you need decimal readings, temperatures below 0 °C, or accuracy better than ±2 °C. Both use the same wiring and the same library, so you can swap them by changing one word in the code.
Why is my LCD blank after wiring it?
Three causes cover almost every case: the contrast screw on the I2C backpack needs adjusting, the I2C address is 0x3F instead of 0x27, or the SDA and SCL wires are swapped. Fix them in that order. The contrast screw is the most common one.
Why does my DHT11 show NaN?
NaN means the sensor did not answer in time. The usual causes are a loose DATA wire, the wrong pin in the code, a missing 10k pull-up resistor on a bare sensor, or reading the sensor too often. Check the wiring first, then check that DHT_PIN and DHT_TYPE match your build.
Can the DHT11 work with an ESP32?
Yes. The DHT library supports the ESP32, and the wiring is the same: DATA to any GPIO pin, VCC to 3.3 V or 5 V, GND to GND. The LCD also works on the ESP32, but its SDA and SCL pins are GPIO 21 and GPIO 22, not A4 and A5. The reading interval rule is the same.
What is the DHT11 sensor price in Pakistan?
The DHT11 temperature and humidity sensor costs Rs 210 at Smart Circuit Hub. A complete setup with an Arduino Uno, breadboard, jumper wires and LCD1602 display costs roughly Rs 2,460.
Conclusion
You have built a standalone climate monitor: a DHT11 sensor, an Arduino Uno and a 16×2 LCD that shows the room’s temperature and humidity with no computer attached. You have also learned the sensor’s honest limits: one reading per second, ±2 °C accuracy, and a 20 to 90 % humidity range. The LCD skills carry further than this one project. The same I2C display can show distance, voltage, speed or any number your next sensor produces. Try the greenhouse idea next. It adds a relay and a fan to this exact build, and the display already shows everything you need to see.
Components for this project are available at Smart Circuit Hub with nationwide Cash on Delivery across Pakistan.
If you missed it, our HC-SR04 ultrasonic sensor tutorial builds a distance meter the same way.
