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.
DHT library: Download library here
LCD i2c New_Liquid_Crystal library: Download LCD i2c library here
You can download the codes: Download codes here or check below:
The code 1 works with the Serial monitor, it shows the ambient temperature in °C and humidity in %RH, and refresh every 1s.
#include <dht.h> //DHT library
dht DHT; //Declaring dht entity named DHT
#define DHT11_PIN 7 //DHT data pin
int chk = DHT.read11(DHT11_PIN); //Read data temperature from DHT11 pin
Serial.print("Temperature = "); //Show ambient temperature and humidity every 1s
Serial.print("Humidity = ");
The second code works with LCD i²c screen, it shows both temperature and humidity over there.
//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
#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
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
int chk = DHT.read11(DHT11_PIN); //Reading data from the module
lcd.print(DHT.temperature); //Showing temperature value (before that you can do some math to get the temperature in Farnheit)
lcd.println(DHT.humidity); //Showing humidity percentage
delay(1000); //Refreshing every 1s
Automation and Electrical Engineer, Electronics amateur trying to share my little projects.