Illustration: on a bookshelf an LCD shows temperature and humidity, with a DHT11 sensor and the board beside it.Home and IoT
Illustration (made with AI): roughly what the finished project looks like.

A Room Thermometer on an LCD

A DHT11 sensor measures the temperature and humidity, and a 16×2 display shows both, updating every two seconds.

Difficulty
Beginner
Time
40 min
Age
10+
Parts
5, 5 on the site

Written by the RoboHub team. A question? Write to us.

Variations

Choose a variation and the parts list updates.

Instructions

  1. Install the libraries

    In the Library Manager, install “DHT sensor library” (Adafruit) and “LiquidCrystal I2C” (Frank de Brabander). When the IDE offers extra libraries, choose “Install all”.

  2. Connect the display

    The I2C display has four pins: GND to ground, VCC to 5V, and SDA and SCL to the board's SDA and SCL pins. On the Uno they sit next to AREF (A4 and A5 are the same), on the Mega they are pins 20 and 21.

    On the Uno, SDA and SCL sit next to AREF (the same as A4 and A5); on the Mega they are pins 20 and 21. D2 is the board's digital pin 2, GND is ground. Red wires are power, black ground, the other colours signals (on a real servo the ground wire is often brown). In the steps, what a step adds is in colour and what is already connected in grey.

    • LCD 16×2 (I2C) GND → Arduino GND
    • LCD 16×2 (I2C) VCC → Arduino 5V
    • LCD 16×2 (I2C) SDA → Arduino SDA
    • LCD 16×2 (I2C) SCL → Arduino SCL
  3. Connect the sensor

    Connect the DHT11 module's “+” to 5V, “−” to ground and OUT (or DATA) to pin 2. The board has one 5V pin, so feed the display and the sensor from one breadboard rail. If your sensor has four legs and no little board, put a 10 kΩ resistor between DATA and 5V.

    On the Uno, SDA and SCL sit next to AREF (the same as A4 and A5); on the Mega they are pins 20 and 21. D2 is the board's digital pin 2, GND is ground. Red wires are power, black ground, the other colours signals (on a real servo the ground wire is often brown). In the steps, what a step adds is in colour and what is already connected in grey.

    • DHT11 module + → Arduino 5V
    • DHT11 module − → Arduino GND
    • DHT11 module OUT → Arduino D2
  4. Upload the code

    If you have a DHT22, change DHT11 to DHT22 in the code. If the screen lights up but shows no text, turn the blue knob on the back (contrast). If nothing shows at all, try address 0x3F instead of 0x27. On the Uno R4 the IDE warns that LiquidCrystal I2C was written for AVR: the warning does no harm.

    Illustration: an LCD showing temperature and humidity, with a DHT11 sensor beside it.

    Illustration, made with AI

    Arduino C++
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    #include <DHT.h>
    
    DHT dht(2, DHT11);                     // a DHT22? write DHT22 here
    LiquidCrystal_I2C lcd(0x27, 16, 2);    // some displays use 0x3F
    
    void setup() {
      dht.begin();
      lcd.init();
      lcd.backlight();
    }
    
    void loop() {
      float t = dht.readTemperature();     // °C
      float h = dht.readHumidity();        // %
      lcd.clear();
      if (isnan(t) || isnan(h)) {
        lcd.print("Sensor error");
      } else {
        lcd.setCursor(0, 0);
        lcd.print("Temp: ");
        lcd.print(t, 1);
        lcd.print((char)223);              // the degree sign on these displays
        lcd.print("C");
        lcd.setCursor(0, 1);
        lcd.print("Humidity: ");
        lcd.print(h, 0);
        lcd.print("%");
      }
      delay(2000);                         // a DHT11 can be read at most once a second
    }
  • Home and IoT
    Intermediate1 h12+

    A Code Lock with a Keypad

    Type the secret code and press #: with the right code the green light comes on and a servo slides the bolt open, with the wrong one the buzzer beeps three times.

    7/7 parts on the site
  • Sensors
    Beginner1 h10+

    Parking Sensor with Sound and Lights

    An ultrasonic sensor measures the distance. Three LEDs show how close the obstacle is, and the buzzer beeps faster the closer you get.

    6/6 parts on the site
  • Games
    Beginner45 min10+

    A Two-Player Reaction Game

    An LED lights at a random moment. Whoever presses their button first wins. Built from Student Kit parts in 45 minutes.

    6/6 parts on the site