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 -
LCD Display -
Potentiometer -
Breadboard -

Recommended Site -


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() {
  lcd.begin(16,2);                      //initializes the LCD and specifies the dimensions
void loop() {
  float temp = dht.getTemperature();
  float humi = dht.getHumidity();
  lcd.print("Temp: ");
  lcd.print(" C");
  lcd.print("Humi: ");
  lcd.print(" %");