মূল বিষয়বস্তুতে যান
Back to Projects
IntermediateArduino Uno R3
30 minutes build

LCD thermometer

Temperature and humidity on a 16×2 display.

Interactive Simulation

LCD thermometerarduino-uno
Open in Lab
UNOATmega328P: The 8-bit AVR microcontroller that runs your sketch (16 MHz, 32 KB flash, 2 KB RAM).ATmega328PUSB-B: USB connection for uploading sketches and for the Serial Monitor. Also powers the board (5 V).DC jack: Barrel jack for 7–12 V from a battery pack or adapter (centre positive).ATmega16U2: Converts USB to serial for uploads and Serial.print().RESET: Restarts your sketch from the beginning (setup() runs again).L (D13): Built-in LED connected to pin 13 (LED_BUILTIN).ON: Power indicator.5 V regulator: Turns 7–12 V from VIN/jack into a steady 5 V.16 MHz: Clock source: the microcontroller runs 16 million cycles per second.ICSP: In-circuit programming header (SPI). Used to burn a bootloader; not needed for normal uploads.27°C · 60%GNDVCCSDASCL

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.