Search

How to use a DHT 11 temperature and humidity sensor with arduino

 

 

 

In this project we will measure the temprature and humidity with the DHT 11 temperature and humidity sensor with an arduino and a 20×4 LCD display.

Some characteristics of this sensor are:

1 Can detect  the environmental humidity and temperature
2 Humidity measurement range: 20% 95% humidity
3 Humidity error +-5%
4 Temperature measurement range:0-50 °C
5 Temperature error ±2°C
6 Supply voltage 3.3-5 Volts
7 One wire digital output form
8 Fixed bolt hole for easy installation
9 3.2×1.4 cm

You can use this sensor to measure temperature and humidity in relative restricted environments because the temperature range is between 0 to 50 degrees. It is perfect for rooms, garages, storehouses etc where temperature do not go under zero.

Why we choose this sensor???? Because being calibrated and with only 2 degrees error it is perfect for cheap and pretty precise monitoring sistems.

A picture of this sensor is below:

DHT 11 sensor

For easy in installation we will use a library you can download from here. This zip library can be installed by selecting from arduino software sketch-include library-add zip library .

Now let’s see how to connect the sensor from arduino. As you can see in  the image the shield sensor has 3 pins:

“+” connect to 5V from arduino

“-” connect to GND from arduino 

“S”connect to any digital pin(we choose digital pin number 4).

Before to start the program with the LCD you can upload a example sketch that you installed with the library and you can find it in arduino software at Examples-DHTlib-dht11_test. It’s working with serial monitor.



To install the 20×4 LCD display see this tutorial.

The program with LCD is presented below or you can download from here:

#include <dht.h>

dht DHT;

#define DHT11_PIN 4 //digital pin 4 is the input pin for sensor

#include <Wire.h>  // Comes with Arduino IDE

#include <LiquidCrystal_I2C.h>

// set the LCD address to 0x27 for a 20 chars 4 line display

// Set the pins on the I2C chip used for LCD connections:

//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

void setup()

{

Serial.begin(115200);

lcd.begin(20,4);   // initialize the lcd for 20 chars 4 lines, turn on backlight

lcd.backlight();   // finish with backlight on

//first row and first column is indexed with 0

lcd.setCursor(0,0);//starting to display from character 0 line 0

lcd.print(“Temperature:”);

lcd.setCursor(6,1); //starting to display from character 6 line 1

lcd.print((char) 223); //ASCII code for degree

lcd.setCursor(7,1);  //starting to display from character 7 line 1

lcd.print(“C”);

lcd.setCursor(0,2); //starting to display from character 0 line 2

lcd.print(“Humidity:”);

lcd.setCursor(6,3); //starting to display from character 6 line 3

lcd.print(“%”);

}

void loop()

{

updateDHT(); // call function updateDHT

}

void updateDHT() // the function that read the sensor and display data

{

int chk;

chk = DHT.read11(DHT11_PIN);// READ DATA

lcd.setCursor(2,1);

lcd.print(DHT.temperature,1);

lcd.setCursor(2,3);

lcd.print(DHT.humidity,1);

delay(1000);

}

 

Please let us in the comment zone any suggestions that you think will improve the article!

If you like the article click the follow button from social media to stay in touch with us!

 

A small video with the sensor and the LCD display is:

Facebooktwitterpinterest

Related posts

Leave a Comment

Show Buttons
Hide Buttons