Arduino UNO R4 - DHT22 - LCD
We'll learn programming an Arduino UNO R4 to read temperature and humidity from a DHT22 sensor and show these on an I2C LCD display.
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
Learn about the DHT22 sensor and LCD, including their pinout, functions, and programming, in the tutorials below:
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Uno R4 and other components.
Arduino UNO R4 Code - DHT22 Sensor - LCD I2C
※ NOTE THAT:
The LCD I2C address can differ based on the manufacturer. In our code, we used the address 0x27 as provided by the manufacturer DIYables.
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
- Connect the Arduino Uno R4 to the DHT22 module and LCD I2C according to the provided diagram.
- Connect the Arduino Uno R4 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
- Click on the Libraries icon on the left side of the Arduino IDE.
- Type "DHT" in the search box and look for the DHT sensor library by Adafruit.
- Click the Install button to add the library.
- You will need to install additional library dependencies.
- Click the Install All button to install all library dependencies.
- Search for "LiquidCrystal I2C" and choose the LiquidCrystal_I2C library by Frank de Brabander. Click the Install button to install the library.
- Copy the code above and open it in Arduino IDE.
- Click the Upload button in Arduino IDE to upload the code to Arduino UNO R4.
- Change the temperature around the sensor to either hotter or colder.
- Observe the result on the LCD.
If the LCD screen shows no information, please check here: Troubleshooting on LCD I2C