ESP8266 - Humidity Sensor - LCD
This tutorial instructs you how to use ESP8266 to read temperature and humidity from DHT22 sensor and display them on LCD I2C.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of DHT22 and LCD
If you are unfamiliar with the DHT22 temperature humidity sensor and LCD (including pinout, how it works, and how to program), the following tutorials can help:
Wiring Diagram
ESP8266 - DHT22 and LCD Wiring Diagram
This image is created using Fritzing. Click to enlarge image
See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.
ESP8266 Code - DHT22 Sensor - LCD I2C
※ NOTE THAT:
The I2C address of LCD may differ depending on the manufacturer. In our code, we have used 0x27 as specified by DIYables manufacturer.
Detailed Instructions
To get started with ESP8266 on Arduino IDE, follow these steps:
- Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
- Wire the components as shown in the diagram.
- Connect the ESP8266 board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
- Connect an USB cable from the ESP8266 to the PC.
- Open the Arduino IDE and select the correct board and port.
- Click to the Libraries icon on the left bar of the Arduino IDE.
- Search for “DHT” and locate the Adafruit DHT sensor library.
- Press the Install button to complete the installation.
- You will be prompted to install additional library dependencies.
- Click the Install All button to install all necessary libraries.
- Search for “LiquidCrystal I2C”, then locate the LiquidCrystal_I2C library created by Frank de Brabander.
- Click the Install button to install the LiquidCrystal_I2C library.
- Copy the code above and open it with the Arduino IDE.
- Click the Upload button in the Arduino IDE to compile and upload the code to the ESP8266.
- Change the temperature of the environment around the sensor.
- Check out the results on the LCD.
If the LCD does not show anything, check out Troubleshooting on LCD I2C for help.