How to use DHT11 and DHT22 sensors



In this tutorial we will learn how to use the DHT11 or the DHT22 sensor for measuring temperature and humidity.
And we will see the value output of the DHT sensors on both the serial monitor and the LCD screen.
The LCD screen component is optional. With this tutorial you can also print on a serial monitor.
Code and circuit diagram are compatible within both sensors.

---

Hardware Required:

Arduino Board - https://goo.gl/Rqc5w2
LCD Display - https://goo.gl/SxH8Jx
Potentiometer - https://goo.gl/MPwcEM
Breadboard - https://goo.gl/GjpqVW

Recommended Site - https://goo.gl/HDkZBt

---

The DHT sensors have four pins, VCC, GND, data pin and a not connected pin which has no usage.

From left to right

1 - VCC (5V)
2 - Signal
3 - NC Not connected
4 - GND

---

DHT Sensors Library:


---

Get the Source Code:
#include "DHT.h"                        //include the DHT library
#include <LiquidCrystal.h>              //include the LiquidCrystal library
#define DHTPin 2                        //define DHT pin
LiquidCrystal lcd(1, 3, 4, 5, 6, 7);    //define LCD pins (RS, E, D4, D5, D6, D7)
DHT dht;

void setup() {
  dht.setup(DHTPin);  
  lcd.begin(16,2);                      //initializes the LCD and specifies the dimensions
}
void loop() {
  float temp = dht.getTemperature();
  float humi = dht.getHumidity();
  lcd.setCursor(0,0);
  lcd.print("Temp: ");
  lcd.print(temp);
  lcd.print(" C");
  lcd.setCursor(0,1);
  lcd.print("Humi: ");
  lcd.print(humi);
  lcd.print(" %");
  delay(2000);
}