Skip to the content.

Temperature Sensor & LCD

Photo of circuit

This tutorial will help you put together a temperature and humidity sensor (DHT11) and be able to view the data on the Liquid Crystal Display (LCD).

Components Needed

Arduino Library

This circuit requires the DHT11 library and the Unified Sensor library from Adafruit. To install the libraries, go to the Sketch menu, then Include Library, then Manage Libraries.

Manage Libraries

Search for “dht11” and install the library created by Adafruit.

Adafruit DHT11 library

Then, search for “adafruit unified sensor” and scroll to the bottom of the results and install the “Adafruit Unified Sensor” library.

Adafruit Unified Sensor library

Documentation

Wiring Diagrams

DHT11 Sensor

DHT11 wiring diagram

DHT11 & LCD

DHT11 & LCD wiring diagram

The resistor connecting pin 15 on the LCD to VCC (positive) is optional. The higher the resistance the dimmer the background light on the LCD.

Code

#include <DHT.h>
#define DHTTYPE DHT11

const int DHTPIN 7;

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);

  dht.begin();
}

void loop() {
  delay(2000);

  float h = dht.readHumidity();
  float c = dht.readTemperature();
  float f = dht.readTemperature();

  Serial.print("Temperature: ");
  Serial.print(c);
  Serial.println("°C");

  Serial.print("Temperature: ");
  Serial.print(f);
  Serial.println("°F");
  
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.println("%");

  Serial.println();
}
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.print("Hello World!");
}

void loop() {
  lcd.setCursor(0,1);
  lcd.print("My scrolling text...");
 
  lcd.scrollDisplayLeft();

  delay(1000);
  
}
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#include <DHT.h>
#define DHTTYPE DHT11
const int DHT11_PIN = 7;
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  lcd.begin(16, 2);
  dht.begin();
}

void loop() {
  delay(2000);

  lcd.setCursor(0,0);
  lcd.print("Temp: ");
  lcd.print(dht.readTemperature());
  lcd.print( (char)223); //Create the degree symbol
  lcd.print("C");

  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(dht.readHumidity());
  lcd.print("%");
}

Resources

Components

Other Tutorials