Fusion!! Integrating I2C LCD 16x4 with DHT11 Sensor (Should be)

Garin Ichsan Nugraha
Garin ESP32 DEVKIT
Published in
2 min readFeb 24, 2020

Hi Everyone! How’s live? Here I want to share my experience using I2C LCD 16x4 to Visualize the value of Temperature and Humidity that detected by DHT11 Sensor.

First of all, know the schematic! Here the schematic for you!

After you’ve done implementing the schematic, you can code it. Use the library that we’ve install before, both for LCD and for DHT11. Here’s the code for you to try!

/*********
Garin Ichsan
Embeded System Project
Adaptation from https://randomnerdtutorials.com
*********/
// Example to integrate DHT11 with LCD#include <LiquidCrystal_I2C.h>
#include "DHT.h"
LiquidCrystal_I2C lcd(0x3f, 16, 2);
DHT dht(4, DHT11);
void setup() {
// initialize LCD and turn on LCD backlight
lcd.init();
lcd.backlight();
// start the DHT
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
//lcd.clear();
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();

// set cursor to first column, first row
lcd.setCursor(0, 0);
// print message
lcd.print("Humidity: ");
lcd.print(h);
lcd.print("%");
// set cursor to first column, second row
lcd.setCursor(0,1);
lcd.print("Heat index: ");
lcd.print(t);
lcd.print("°C");
}

Try to compile and run it, your LCD will look like this with some letter on it. But unfortunately our experiment this time face some error that made our LCD didn’t show anything.

Isn’t it interesting ?! We’ll try to fix this really soon so you’ll know how the LCD works with the DHT11. Thanks!

See ya in our next project!!

--

--