Showing posts with label temperature and humidity. Show all posts
Showing posts with label temperature and humidity. Show all posts

Tuesday, September 30, 2025

How to Make a Temperature and Humidity Monitor with DHT11 and LCD

How to Make a Temperature and Humidity Monitor with DHT11 and LCD

Hello, friends! I'm Gaurav, and welcome to the Gaurav Arduino blog.

Have you ever wanted to know the current temperature and humidity of your room, greenhouse, or any other space? In today's DIY (Do It Yourself) project, we will use an Arduino Uno to build a very simple yet useful "Temperature and Humidity Monitor." We will display the output of this project on a 16x2 LCD screen.

This project is perfect for beginners and will give you a basic understanding of interfacing sensors and displays with an Arduino. So, let's get started!

Required Components

You will need the following components to build this project:

  1. Arduino Uno: This is the microcontroller and the brain of our project, which will read data from the sensor and send it to the LCD.

  2. DHT11 Sensor: This is a digital sensor that can measure both temperature and humidity. It's inexpensive and easily available.

  3. 16x2 I2C LCD Display: This is a display with 16 columns and 2 rows. We have chosen an LCD with an I2C module because it greatly simplifies the wiring, requiring us to connect only 4 wires.

  4. Breadboard: To easily build and test the circuit without soldering.

  5. Jumper Wires: To connect the components to each other.

Circuit Diagram and Connections

After gathering all the components, the next step is to connect them. The connections are very straightforward. Follow the instructions below:

1. Connect the DHT11 Sensor to the Arduino:

  • DHT11's VCC pin -> Arduino's 5V pin

  • DHT11's GND pin -> Arduino's GND pin

  • DHT11's DATA pin -> Arduino's Digital Pin 2

2. Connect the I2C LCD to the Arduino:

  • LCD's GND pin -> Arduino's GND pin

  • LCD's VCC pin -> Arduino's 5V pin

  • LCD's SDA pin -> Arduino's A4 pin

  • LCD's SCL pin -> Arduino's A5 pin

Note: On the Arduino Uno, pins A4 (SDA) and A5 (SCL) are the dedicated pins for I2C communication.

Library Installation

Before uploading the code, we need to install two important libraries in the Arduino IDE. These libraries help us communicate with the sensor and the LCD.

  1. DHT sensor library: Open the Arduino IDE, go to Sketch -> Include Library -> Manage Libraries.... In the search bar, type "DHT sensor library by Adafruit" and install it.

  2. LiquidCrystal_I2C library: In the same Library Manager, search for "LiquidCrystal_I2C" and install the library by Frank de Brabander.

The Arduino Code

After the libraries are installed, copy the code below and paste it into your Arduino IDE.

C++
// Include necessary libraries
#include <Wire.h> 
#include <LiquidCrystal_I2C.h> // Library for the I2C LCD
#include "DHT.h" // Library for the DHT sensor

// Define the pin and type of the DHT sensor
#define DHTPIN 2     // The data pin is connected to Digital Pin 2
#define DHTTYPE DHT11   // We are using the DHT11 sensor

// Initialize the DHT sensor and LCD objects
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address can be 0x27 or 0x3F, 16 columns, 2 rows

void setup() {
  // Serial Monitor (optional, for debugging)
  Serial.begin(9600);
  Serial.println("DHT11 Test!");

  // Initialize the LCD and DHT sensor
  lcd.begin();
  lcd.backlight();
  dht.begin();

  lcd.setCursor(0,0);
  lcd.print("Gaurav Arduino");
  lcd.setCursor(0,1);
  lcd.print("Project Start!");
  delay(2000);
}

void loop() {
  // Take a reading every 2 seconds
  delay(2000);

  // Read Humidity from the sensor
  float h = dht.readHumidity();
  // Read Temperature in Celsius from the sensor
  float t = dht.readTemperature();

  // Check if any reading failed
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Sensor Error!");
    return;
  }

  // Clear the LCD screen
  lcd.clear();

  // Set the cursor to the first line (row 0)
  lcd.setCursor(0, 0); 

  // Print the temperature
  lcd.print("Temp: ");
  lcd.print(t);
  lcd.print((char)223); // Degree symbol (°)
  lcd.print("C");

  // Set the cursor to the second line (row 1)
  lcd.setCursor(0, 1);

  // Print the humidity
  lcd.print("Humidity: ");
  lcd.print(h);
  lcd.print(" %");
}

How the Code Works

  • Libraries: At the beginning of the code, we include the Wire, LiquidCrystal_I2C, and DHT libraries.

  • Definitions: We define that our DHT sensor is on pin 2 and is of type DHT11. We also create the LCD and DHT objects.

  • void setup(): This function runs once. In it, we initialize the LCD, its backlight, and the DHT sensor with the begin() command.

  • void loop(): This function runs continuously. Every 2 seconds, it reads the values from the sensor using dht.readHumidity() and dht.readTemperature(). It then clears the screen with lcd.clear() and prints the new values to the display using lcd.setCursor() and lcd.print().

Troubleshooting

  • LCD is blank or showing strange characters:

    • Double-check your SDA and SCL connections.

    • Your LCD's I2C address might be 0x3F instead of 0x27. Try changing it in the code.

    • Ensure that VCC and GND are connected correctly.

  • "Sensor Error!" is displayed on the LCD:

    • Check the connections of the DHT11 sensor. The data pin must be correctly connected to the Arduino pin.

    • Make sure you have installed the DHT library correctly.

Conclusion

Congratulations! You have successfully built your own temperature and humidity monitor. This project is not only practical but also teaches you a lot about Arduino programming and sensor interfacing.

If you liked this project and article, please give it a like and share it with your friends. To see more fun and Arduino-related projects, subscribe to our channel, Gaurav Arduino. If you have any questions, be sure to ask them in the comments below.

Happy Making!

By: Gaurav, Gaurav Arduino

How to Make a Temperature and Humidity Monitor with DHT11 and LCD

How to Make a Temperature and Humidity Monitor with DHT11 and LCD Hello, friends! I'm Gaurav, and welcome to the Gaurav Arduino blog. H...