Project tutorial
Displaying Temperature and Humidity on an LCD

Displaying Temperature and Humidity on an LCD © GPL3+

Integrate this easy-to-use DHT11 temperature and humidity sensor into your weather station, drone, weather balloon, or greenhouse.

  • 2 views
  • 0 comments
  • 0 respects

Components and supplies

Necessary tools and machines

Apps and online services

About this project

Introduction

In this project, we are going to interface a DHT11 temperature and humidity sensor, and display the data on a 16x2 LCD. If you haven't read Project 9 for the Arduino Uno Rev3, please read that first because this covers how to interface a 16x2 character LCD in 4-bit mode. We will then swap out the 16x2 LCD for a 20x4 LCD to display the humidity and the temperature in Celsius, Fahrenheit, and Kelvin. The DHT11 sensor can be used for a weather station, weather balloon, drone, or greenhouse.

16x2 Character LCD

In our previous project, we showed you how to interface a 16x2 LCD to the Uno. You should have pins 4, 6, and 11 - 14 of the LCD connected to Uno pins 2, 3, and 4 - 7, respectively. You can either connect the LCD using a solderless breadboard or the Modulus Canister. An image is shown below with it connected to Modulus.

20x4 Character LCD

The 20x4 LCD adds two extra rows and four extra columns per row compared to the 16x2 LCD. Similar to the 16x2, the 20x4 LCD uses the Hitachi controller so the commands and interfaces are the same. It also has the same 16-pin header, allowing you to unplug the 16x2 LCD and plug in the 20x4 without changing any wiring. The only thing we have to change is one line of code, lcd.begin(20, 4), which specifies the columns (first argument) and rows (second argument) of the LCD. An image of the 20x4 LCD is shown below.

DHT11 Temperature and Humidity Sensor

There are different types of DHT sensors such as the DHT11, DHT21, DHT22, DHT33, and DHT44. They all measure both temperature and humidity, but the difference lies mostly in their accuracy and sampling rate. For example, we show a side-by-side comparison in the table below of the two most popular DHT sensors, DHT11 and DHT22. The DHT22 has a better accuracy and range, but it has a slower sampling rate, it's bigger in size, and double the cost of the DHT11.

To measure the temperature and humidity, a thermistor and a capacitive humidity sensor are used, respectively. The resistance of a thermistor changes with a change in temperature - as the temperature increases, the resistance decreases. For the humidity sensor, the resistance between the two electrodes changes with a change in humidity. Both of these changes in resistance are measured by the IC on the sensor and sent to the host via a 1-wire interface. Each sample consists of a 40-bit data packet.

We are using a 3-pin DHT11 sensor as shown in the image below. The pins are "+", "OUT", and "-." The sensor can be supplied with both +5Vdc or +3.3Vdc - we'll be supplying +5Vdc to it.

DHT11 Wiring

We are mounting the DHT11 sensor to the 2.54mm pitch section of Modulus with a right-angle (R/A) female header, as shown in the image below. Solder the 4-pin R/A female header to the edge of the board. Next, solder a 4-pin male header adjacent to the female header. Once you have the headers soldered on, flip the board over and make a solder bridge between the adjacent pins of the headers.

Wire-wrap the "+" pin to +5Vdc which is any of the pins in column 20 on the 4x26-pin breakout. Then wire-wrap the "-" pin to the GND vector just below the 4x26-pin breakout. Use a 12" F/M jumper to connect the "OUT" pin to pin 8 of the Uno. If you are using a breadboard, a wiring schematic is shown below.

FuelCan Wiring

If you haven't mounted the Uno onto the prototyping area of the FuelCan, go ahead and do that. If you are using a breadboard instead of Modulus, place the breadboard in the bottom storage compartment to limit the length of the jumper wires. You'll need to supply +5V and GND to the power and ground rails on the breadboard by using the provided banana jack to test-lead clip cables. You will need two male header pins to mount the test-lead clips on the breadboard side. Plug the Type A side of the USB cable into USB1 receptacle and the Type B side into the Uno's receptacle. Power up the FuelCan with the AC-DC power adapter.

Software

Once the wiring is complete and the FuelCan is powered up, we can now load the sketch onto the Uno. The first sketch is used with the 16x2 LCD. The second sketch is used with the 20x4 LCD. The DHT11 sensor is sampled every two seconds since sampling faster causes errors.

You'll need the DHT Library to use the DHT functions within the sketch which is available on Arduino's website.

Code

Display data on 16x2 LCDArduino
//Interface the DHT11 Temp & Humidity sensor and display humidity and temperature
//in Celsius on a 16x2 character LCD

#include <dht.h>
#include <LiquidCrystal.h>

dht DHT;
const int RS = 2, EN = 3, D4 = 4, D5 = 5, D6 = 6, D7 = 7;
LiquidCrystal lcd(RS,EN,D4,D5,D6,D7);   //set Uno pins that are connected to LCD, 4-bit mode

void setup() {
  lcd.begin(16,2);    //set 16 columns and 2 rows of 16x2 LCD

}

void loop() {
  int readDHT = DHT.read11(8);    //grab 40-bit data packet from DHT sensor
  lcd.setCursor(0,0); 
  lcd.print("Temp: ");
  lcd.print(DHT.temperature);
  //lcd.print((char)223);         //used to display degree symbol on display
  //lcd.write(0xdf);              //another way to display degree symbol
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(DHT.humidity);
  lcd.print("%");
  delay(3000);

}
Display data on 20x4 LCDArduino
//Interface the DHT11 Temp & Humidity sensor and display humidity and temperature
//in Celsius, Fahrenheit, and Kelvin on a 20x4 character LCD

#include <dht.h>
#include <LiquidCrystal.h>

//variable declarations
dht DHT;
double tempF = 0;
double tempK = 0;
const int RS = 2, EN = 3, D4 = 4, D5 = 5, D6 = 6, D7 = 7;

LiquidCrystal lcd(RS,EN,D4,D5,D6,D7);   //set Uno pins that are connected to LCD, 4-bit mode

void setup() {
  lcd.begin(20,4);    //set 20 columns and 4 rows of 16x2 LCD

}

void loop() {
  int readDHT = DHT.read11(8);      //grab the 40-bit data packet from DHT sensor

  tempF = DHT.temperature*9/5 + 32;   //convert temp to Fahrenheit
  tempK = DHT.temperature + 273.15;   //convert temp to Kelvin
  lcd.print("Temp: ");
  lcd.print(DHT.temperature);     //display temp in C on LCD
  lcd.print("C");

  lcd.setCursor(0,1);
  lcd.print("Temp: ");
  lcd.print(tempF);     //display temp in F on LCD
  lcd.print("F");

  lcd.setCursor(0,2);
  lcd.print("Temp: ");
  lcd.print(tempK);     //display temp in Kelvin on LCD
  lcd.print("K");
    
  lcd.setCursor(0,3);
  lcd.print("Humidity: ");
  lcd.print(DHT.humidity);
  lcd.print("%");
  lcd.setCursor(0,0);
  delay(2000); 

}

Schematics

Wiring LCD and DHT11 to Arduino Uno
Circuit schematic 50uewknw4d

Comments

Similar projects you might like

Temperature + Humidity on LCD

Project showcase by interpeo

  • 24,221 views
  • 14 comments
  • 58 respects

Temperature Monitor with DHT22 and I2C 16x2 LCD

Project tutorial by adrakhmat

  • 3,296 views
  • 3 comments
  • 18 respects

Temperature and Humidity Logger Per Hour

Project tutorial by lefteris1993

  • 2,228 views
  • 0 comments
  • 13 respects

Displaying Sensor Values on LCD

by Wimpie van den Berg

  • 58,404 views
  • 5 comments
  • 43 respects

Health Kit: Humidity and Temperature Control

Project tutorial by Diana Khalipina

  • 6,889 views
  • 2 comments
  • 45 respects
Add projectSign up / Login