Arduino Nano - DHT11 - LCD

This tutorial instructs you how to use Arduino Nano to read the temperature and humidity from DHT11 sensor and display it on LCD I2C.

Hardware Preparation

1×Arduino Nano
1×USB A to Mini-B USB cable
1×LCD I2C
1×DHT11 Temperature and Humidity Sensor
1×DHT11 Temperature Humidity Sensor Module (short)
1×Jumper Wires
1×Breadboard
1×(Recommended) Screw Terminal Expansion Board for Arduino Nano
1×(Recommended) Breakout Expansion Board for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of DHT11 and LCD

If you are unfamiliar with the DHT11 temperature humidity sensor and LCD (pinout, how it works, how to program ...), then the following tutorials can help:

Wiring Diagram

Arduino Nano - DHT11 and LCD Wiring Diagram

The wiring diagram between Arduino Nano and DHT11 temperature and humidity LCD

This image is created using Fritzing. Click to enlarge image

Please note that the power from the 5V pin of the Arduino Nano may not be enough for both the DHT11 and the LCD. If you see the LCD display nothing, please add extra power to the LCD and DHT11 as shown in the wiring diagram below.

The wiring diagram between Arduino Nano and DHT11 temperature humidity LCD external power

This image is created using Fritzing. Click to enlarge image

Arduino Nano Code - DHT11 Sensor - LCD I2C

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-dht11-lcd */ #include <LiquidCrystal_I2C.h> #include "DHT.h" #define DHT_PIN 2 // The Arduino Nano pin connected to DHT11 sensor #define DHT_TYPE DHT11 LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27 (from DIYables LCD), 16 column and 2 rows DHT dht11(DHT_PIN, DHT_TYPE); void setup() { dht11.begin(); // initialize the sensor lcd.init(); // Initialize the LCD I2C display lcd.backlight(); // open the backlight } void loop() { delay(2000); // wait a few seconds between measurements float humi = dht11.readHumidity(); // read humidity float temperature_C = dht11.readTemperature(); // read temperature lcd.clear(); // check if any reads failed if (isnan(humi) || isnan(temperature_C)) { lcd.setCursor(0, 0); lcd.print("Failed"); } else { lcd.setCursor(0, 0); // start to print at the first row lcd.print("Temp: "); lcd.print(temperature_C); // print the temperature lcd.print((char)223); // print ° character lcd.print("C"); lcd.setCursor(0, 1); // start to print at the second row lcd.print("Humi: "); lcd.print(humi); // print the humidity lcd.print("%"); } }

※ NOTE THAT:

The address of the LCD can differ depending on the manufacturer. We have used 0x27 in our code, which is specified by DIYables manufacturer.

Detailed Instructions

  • Connect an USB cable between the Arduino Nano and the PC.
  • Open the Arduino IDE, choose the correct board and port.
  • Click to the Libraries icon on the left bar of the Arduino IDE.
  • Search for “DHT” and locate the DHT sensor library by Adafruit.
  • Press the Install button to install the library.
Arduino Nano DHT sensor library
  • You will be prompted to install some other library dependencies.
  • Click the Install All button to install all necessary library dependencies.
Arduino Nano Adafruit Unified sensor library
  • Search for “LiquidCrystal I2C” and locate the LiquidCrystal_I2C library by Frank de Brabander.
  • Then, click the Install button to install the library.
Arduino Nano LiquidCrystal I2C library
  • Copy the code above and open it with the Arduino IDE.
  • Click the Upload button in the Arduino IDE to send the code to the Arduino Nano.
  • Change the temperature of the environment around the sensor.
  • Check out the result on the LCD.

A grandfather, who was learning through this tutorial to help his grandchild, tested this code with Arduino Nano and sent us the result as follows:

Arduino Nano display temperature humidity on LCD

If the LCD does not show anything, check Troubleshooting on LCD I2C for help.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!