Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Based Temperature and Humidity Display with DHT11 and LCD

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Temperature and Humidity Display with DHT11 and LCD

Circuit Documentation

Summary

This circuit is designed to interface a DHT11 temperature and humidity sensor with an Arduino UNO microcontroller, display the sensor readings on an LCD display, and adjust the display contrast using a rotary potentiometer. The Arduino UNO reads the sensor data and controls the LCD to update the temperature and humidity values periodically.

Component List

DHT11

LCD Display (16 pin)

Rotary Potentiometer

Arduino UNO

Comment

Wiring Details

DHT11

LCD Display (16 pin)

Rotary Potentiometer

Documented Code

#include <LiquidCrystal.h>
#include <DHT.h>

// Initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Define the DHT11 sensor pin and type
#define DHTPIN 6
#define DHTTYPE DHT11

// Initialize the DHT sensor
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  // Set up the LCD's number of columns and rows
  lcd.begin(16, 2);
  
  // Initialize the DHT sensor
  dht.begin();
  
  // Print a message to the LCD
  lcd.print("Temp: ");
  lcd.setCursor(0, 1);
  lcd.print("Humidity: ");
}

void loop() {
  // Read temperature and humidity from the DHT11 sensor
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  // Check if any reads failed and exit early (to try again)
  if (isnan(h) || isnan(t)) {
    lcd.setCursor(6, 0);
    lcd.print("Error");
    lcd.setCursor(10, 1);
    lcd.print("Error");
    return;
  }
  
  // Print the temperature to the LCD
  lcd.setCursor(6, 0);
  lcd.print(t);
  lcd.print(" C");
  
  // Print the humidity to the LCD
  lcd.setCursor(10, 1);
  lcd.print(h);
  lcd.print(" %");
  
  // Wait a few seconds between measurements
  delay(2000);
}

This code is responsible for initializing the LCD and DHT11 sensor, reading temperature and humidity data from the DHT11, and displaying the values on the LCD. If the sensor fails to provide valid readings, an error message is displayed. The LCD contrast can be adjusted using the rotary potentiometer.