DIY ELECTRONICSTR

← All projects

LCD Thermometer

Beginner30 min

A small device that shows temperature and humidity on a 16x2 LCD instead of the Serial Monitor, so it can sit on a desk without a computer. The DHT11 is read every two seconds; the top line of the screen shows the temperature and the bottom line the humidity. It teaches driving a screen over I2C with just two data wires, using two libraries together, and updating a line on the screen without clearing it. Install the "LiquidCrystal I2C" and "DHTlib" libraries from the Library Manager.

Build it step by step in the app

What you need

Wiring steps

  1. 1

    Connect the power rails (5V and GND)

    Connect the power rails (5V and GND)

    Plug a red jumper wire into the 5V pin on the Arduino's power header and connect its other end to the breadboard's bottom red (+) rail. Plug a black wire into one of the GND pins on the same header and connect its other end to the bottom blue (−) rail. The Uno has a single 5V pin; these two rails share 5V and GND between the sensor and the screen.

    • Arduino 5V → the bottom red (+) rail (red wire)
    • Arduino GND → the bottom blue (−) rail (black wire)
  2. 2

    Add and wire the DHT11

    Add and wire the DHT11

    Plug the DHT11 module into the bottom half of the breadboard: its + pin in column 6, DATA in column 7 and − in column 8. Connect column 6 to the bottom (+) rail with a short red wire and column 8 to the bottom (−) rail with a short black wire. Then connect the Arduino's pin 2 to column 7 with a blue wire (DHT_PIN 2). The module already carries the resistor it needs, so no extra resistor is required.

    • DHT11 + pin → column 6, bottom half
    • DHT11 DATA pin → column 7, bottom half
    • DHT11 − pin → column 8, bottom half
    • column 6, bottom half → the bottom red (+) rail (red wire)
    • column 8, bottom half → the bottom blue (−) rail (black wire)
    • Arduino pin 2 → column 7, bottom half (blue wire)
  3. 3

    Connect the LCD

    Connect the LCD

    Do not plug the screen into the breadboard; push the female ends of male-female jumper wires onto the four pins of the I2C board on its back. Connect VCC to the bottom (+) rail and GND to the bottom (−) rail. Connect SDA to the Arduino's A4 pin with a yellow wire and SCL to A5 with a green wire. Thanks to I2C these two data wires do the work of the screen's 16 pins; on the Uno the same SDA and SCL lines are also on the two pins next to AREF.

    • LCD GND → the bottom blue (−) rail (black wire)
    • LCD VCC → the bottom red (+) rail (red wire)
    • Arduino A4 → LCD SDA (yellow wire)
    • Arduino A5 → LCD SCL (green wire)

Arduino sketch

// Install from the Library Manager:
// "LiquidCrystal I2C" and "DHTlib"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <dht.h>

// The DHT11's data (DATA) pin
const int DHT_PIN = 2;
// Between readings (ms): DHT11 is slow
const unsigned long READ_EVERY = 2000;

// I2C address: 0x27 on most, 0x3F on some
LiquidCrystal_I2C lcd(0x27, 16, 2);
dht DHT;

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.print("Measuring...");
  Serial.begin(9600);
}

void loop() {
  delay(READ_EVERY);
  int chk = DHT.read11(DHT_PIN);

  if (chk != DHTLIB_OK) {
    // No reading: say so on the screen
    lcd.setCursor(0, 0);
    lcd.print("Sensor error    ");
    lcd.setCursor(0, 1);
    lcd.print("Check the wires ");
    Serial.println("Sensor could not be read");
    return;
  }

  // 16 characters fit on a line
  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.print(DHT.temperature, 0);
  // 223: the LCD's degree sign
  lcd.print((char)223);
  // Trailing spaces wipe the old text
  lcd.print("C  ");

  lcd.setCursor(0, 1);
  lcd.print("Humidity: ");
  lcd.print(DHT.humidity, 0);
  lcd.print(" %   ");

  Serial.print("Temperature: ");
  Serial.print(DHT.temperature, 0);
  Serial.print(" °C  Humidity: ");
  Serial.print(DHT.humidity, 0);
  Serial.println(" %");
}

What the Serial Monitor shows

SERIAL MONITOR · 9600 BAUD
Temperature: 24 °C  Humidity: 45 %
Temperature: 24 °C  Humidity: 46 %
Temperature: 25 °C  Humidity: 46 %

If a wire is loose

SERIAL MONITOR · 9600 BAUD
Sensor could not be read

What you will see

At start-up the screen shows "Measuring..."; two seconds later the top line shows the temperature (for example Temp: 24°C) and the bottom line the humidity (Humidity: 45 %), updated every two seconds. Hold the sensor in your hand and both slowly rise. If the screen is lit but shows no text, turn the small screw (contrast) on the I2C board with a screwdriver until the text appears. If there is still nothing, the screen's address may be 0x3F: change 0x27 in the code to 0x3F. If the screen says "Sensor error", check that the blue wire runs from pin 2 to column 7 (DATA) and that columns 6 and 8 go to the right rails.

In the app, tick off every wire, match the parts to your inventory and pick up where you left off.

Build it step by step in the app