Back to Projects
IntermediateArduino Uno R3
30 minutes build
LCD thermometer
Temperature and humidity on a 16×2 display.
Interactive Simulation
LCD thermometerarduino-uno
Required Components Checklist
Assembly Steps
1
Wire the sensor
DHT VCC to 5V, GND to GND, DATA to pin 4.
2
Wire the display
LCD VCC to 5V, GND to GND, SDA to A4, SCL to A5.
3
Show the values
Read every 2 seconds, handle NaN, and pad numbers with spaces.
Arduino Sketch
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
DHT dht(4, DHT11);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600);
dht.begin();
lcd.init();
lcd.backlight();
}
void loop() {
float t = dht.readTemperature();
float h = dht.readHumidity();
if (isnan(t) || isnan(h)) {
lcd.setCursor(0, 0);
lcd.print("Sensor error ");
Serial.println("Check the DHT wiring");
} else {
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(t);
lcd.print(" C ");
lcd.setCursor(0, 1);
lcd.print("Hum: ");
lcd.print(h);
lcd.print(" % ");
Serial.print(t);
Serial.print(" C, ");
Serial.print(h);
Serial.println(" %");
}
delay(2000); // the DHT11 can only be read about once per second
}
Challenges & Extensions
Ready to take this project further? Try these challenges:
- •Show °F on the second line.
- •Track the minimum and maximum temperature.
- •Blink the backlight above 35 °C.