Measure temperature/humidity using DHT11 + LCD i2c + Arduino
Hello here,
Before proceeding, if you need to buy DHT11 sensor, check Seeedstudio by clicking here !
In this tutorial we gonna see how to simply use the DHT11 module, It’s a module that can measure ambient temperature 0-50°C and humidity up to 95% RH (Relative humidity), it’s very good for Home Automation projects or DIY projects for daily use.
Also there are a lot of modules that have the same function as this one, you can check them here:
- Measure temperature/humidity using DHT22 + LCD i2c + Arduino
- Measure Temperature / Humidity and Heat Index using DHT 21 (AM 2301) + Arduino + LCD
- Measuring temperature and humidity using AM2320 (DHT12 ??) i2c sensor
- SHT 21/HTU 21 – Measure Temperature and Himidity with Arduino + OLED/LCD [DigitSpace.com]
For this we gonna need:
- DHT 11 (obvious 😃 ) note here that I’m using 3 pins version there are 4 pins one.

- Arduino board here I’ll use Uno
- LCD i2c screen
- Breadboard and jump wires
The LCD i2c is totally optional but usually used with this module as a classic learning project, in case you don’t know how to use one check here:LCD i2c tutorial.
The LCD I used is a I2C version, there are the standard versions but they require a lot of pins, and also in this case you’ll need another library and code functions.
Wiring:

Libraries:
DHT library: Download library here
LCD i2c New_Liquid_Crystal library: Download LCD i2c library here
Codes
You can download the codes: Download codes here or check below:
Code 1:
The code 1 works with the Serial monitor, it shows the ambient temperature in °C and humidity in %RH, and refresh every 1s.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <dht.h> //DHT library dht DHT; //Declaring dht entity named DHT #define DHT11_PIN 7 //DHT data pin void setup(){ Serial.begin(9600); } void loop() { int chk = DHT.read11(DHT11_PIN); //Read data temperature from DHT11 pin Serial.print("Temperature = "); //Show ambient temperature and humidity every 1s Serial.println(DHT.temperature); Serial.print("Humidity = "); Serial.println(DHT.humidity); delay(1000); } |
Code2:
The second code works with LCD i²c screen, it shows both temperature and humidity over there.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
//This code is to use with DHT11 Temperature/humidity sensor with LCD i2c screen //We measure the values of the temperature and humidity then print them on the screen every second //Refer to Surtrtech channel on youtube or blogger for more information or how to use the LCD i2c #include <dht.h> //DHT and LCD libraries #include <LiquidCrystal_I2C.h> #define I2C_ADDR 0x27 #define BACKLIGHT_PIN 3 #define En_pin 2 #define Rw_pin 1 #define Rs_pin 0 #define D4_pin 4 #define D5_pin 5 #define D6_pin 6 #define D7_pin 7 LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); dht DHT; //Declaring the DHT as a dht type to use it later #define DHT11_PIN 7 //Declaring where the DHT signal pin is wired void setup(){ lcd.begin (16,2); lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); lcd.setBacklight(HIGH); lcd.home (); } void loop() { lcd.clear(); lcd.setCursor(0,0); int chk = DHT.read11(DHT11_PIN); //Reading data from the module lcd.print("Temp: "); lcd.print(DHT.temperature); //Showing temperature value (before that you can do some math to get the temperature in Farnheit) lcd.print(" C"); lcd.setCursor(0,1); lcd.print("Humidity: "); lcd.println(DHT.humidity); //Showing humidity percentage lcd.print(" %"); delay(1000); //Refreshing every 1s } |
Categories
Yassine View All
Automation and Electrical Engineer, Electronics amateur trying to share my little projects.
Thank you
Very good video but poor audio?.
Sorry it’s a bit a old, sometimes I don’t have the right setups
How am I supposed to open the rar file and paste to arduino?
Hi, if you’re talking about the libraries they’re in .ZIP format just go to Arduino IDE -> Sketch -> Include library -> Add .ZIP library and look for the library file and it will install.
For the codes just extract the .RAR file and you’ll find codes .INO there.
help, how to add it into library i dont get it
Arduino: 1.8.3 (Windows 10), Board: “Arduino/Genuino Uno”
DHT11_LCD:24: error: expected ‘)’ before numeric constant
LiquidCrystal_I2C lcd ( I2C_ADDR 0x27 ,En_pin 2 ,Rw_pin 1 ,Rs_pin 0 ,D4_pin 4 ,D5_pin 5 ,D6_pin 6 ,D7_pin7 ) ;
^
DHT11_LCD:24: error: expected ‘)’ before numeric constant
LiquidCrystal_I2C lcd ( I2C_ADDR 0x27 ,En_pin 2 ,Rw_pin 1 ,Rs_pin 0 ,D4_pin 4 ,D5_pin 5 ,D6_pin 6 ,D7_pin7 ) ;
^
DHT11_LCD:24: error: expected ‘)’ before numeric constant
LiquidCrystal_I2C lcd ( I2C_ADDR 0x27 ,En_pin 2 ,Rw_pin 1 ,Rs_pin 0 ,D4_pin 4 ,D5_pin 5 ,D6_pin 6 ,D7_pin7 ) ;
^
DHT11_LCD:24: error: expected ‘)’ before numeric constant
LiquidCrystal_I2C lcd ( I2C_ADDR 0x27 ,En_pin 2 ,Rw_pin 1 ,Rs_pin 0 ,D4_pin 4 ,D5_pin 5 ,D6_pin 6 ,D7_pin7 ) ;
^
DHT11_LCD:24: error: expected ‘)’ before numeric constant
LiquidCrystal_I2C lcd ( I2C_ADDR 0x27 ,En_pin 2 ,Rw_pin 1 ,Rs_pin 0 ,D4_pin 4 ,D5_pin 5 ,D6_pin 6 ,D7_pin7 ) ;
^
DHT11_LCD:24: error: expected ‘)’ before numeric constant
LiquidCrystal_I2C lcd ( I2C_ADDR 0x27 ,En_pin 2 ,Rw_pin 1 ,Rs_pin 0 ,D4_pin 4 ,D5_pin 5 ,D6_pin 6 ,D7_pin7 ) ;
^
DHT11_LCD:24: error: expected ‘)’ before numeric constant
LiquidCrystal_I2C lcd ( I2C_ADDR 0x27 ,En_pin 2 ,Rw_pin 1 ,Rs_pin 0 ,D4_pin 4 ,D5_pin 5 ,D6_pin 6 ,D7_pin7 ) ;
^
DHT11_LCD:24: error: ‘D7_pin7’ was not declared in this scope
LiquidCrystal_I2C lcd ( I2C_ADDR 0x27 ,En_pin 2 ,Rw_pin 1 ,Rs_pin 0 ,D4_pin 4 ,D5_pin 5 ,D6_pin 6 ,D7_pin7 ) ;
^
D:\DHT11_LCD\DHT11_LCD.ino: In function ‘void setup()’:
DHT11_LCD:33: error: ‘class LiquidCrystal_I2C’ has no member named ‘setBacklightPin’
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
^
DHT11_LCD:33: error: ‘POSITIVE’ was not declared in this scope
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
^
Multiple libraries were found for “dht.h”
Used: C:\Users\User\Documents\Arduino\libraries\DHT
Not used: C:\Users\User\Documents\Arduino\libraries\DHTLib
exit status 1
expected ‘)’ before numeric constant
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
So this happened. PLEASE HELP
Hello, first please read that you have multiple DHT libraries !!! So use only one and delete the other
Multiple libraries were found for “dht.h”
Used: C:\Users\User\Documents\Arduino\libraries\DHT
Not used: C:\Users\User\Documents\Arduino\libraries\DHTLib
what the fuck is this why i have to use this web side just post the code no need to download the code
i don’t trust you . sorry bud but it can be a virus
Arduino:1.8.19 (Windows 10), Board:”Arduino Uno”
sketch_jul02c:25:3: error: ‘lcd’ was not declared in this scope
lcd.begin (16,2);
^~~
sketch_jul02c:26:37: error: ‘POSITIVE’ was not declared in this scope
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
^~~~~~~~
sketch_jul02c:33:3: error: ‘lcd’ was not declared in this scope
lcd.clear();
^~~
exit status 1
‘lcd’ was not declared in this scope
i followed all the steps but these errors occured any idea what the problem might be?