ejshea
Published © GPL3+

Displaying Temperature and Humidity on an LCD

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

BeginnerFull instructions provided31,553
Displaying Temperature and Humidity on an LCD

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Wiring LCD and DHT11 to Arduino Uno

Code

Display data on 16x2 LCD

Arduino
//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 LCD

Arduino
//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); 

}

Credits

ejshea

ejshea

16 projects • 29 followers

Comments