Arduino DHT22 Temperature Humidity sensor

In this tutorial, we will learn how to connect Arduino with DHT22 sensor.

1). What you will need

  •  DHT Arduino library
  •  Adafruit_sensor.h library
  •  Jumper wires
  • 16×2 LCD compatible with Hitachi HD44780 driver
  • Arduino board
  •  Breadboard
  •  10K ohm potentiometer
  •  220 ohm resistor
  •  Arduino USB cable
  •  Temperature humidity sensor (DHTxx series or AMxxxx series)
Components

 2).  Connect it up

  •        VSS pin of the LCD to ground
  •        VCC pin of the LCD to 5V
  •        RS pin of the LCD to digital pin 7 of the Arduino
  •        R/W pin of the LCD to ground
  •        E pin of the LCD to  digital pin 6 of the Arduino
  •        D4 pin of the LCD to  digital pin 5 of the Arduino
  •        D5 pin of the LCD to  digital pin 4 of the Arduino
  •        D6 pin of the LCD to  digital pin 3 of the Arduino
  •        D7 pin of the LCD to  digital pin 2 of the Arduino

For  220 ohm resistor

  •         one end to A pin of the LCD and the other end to 5V

    For  10k ohm potentiometer

  •         Slider pin of the potentiometer to LCD VO pin of the LCD 
  •         A and B pins of the potentiometer to +5V and ground respectively

    Arduino with DHT22

  •        GND pin of the sensor to  ground
  •        Data pin of the sensor to  digital pin 8 of the Arduino
  •        VCC pin of the sensor to  5V
  •       Note: NC (Not Connected) pin should not be connected to anything
Circuit diagram

3).  Type in the code

Open up your Arduino IDE and type in the code below.  The sketch uses the dht sensor to measure the environmental temperature and relative humidity . The results are displayed on the LCD screen. 

#include<Adafruit_Sensor.h> 
#include<LiquidCrystal.h> 
#include<DHT.h> 
#define DHTPIN 9    
#define DHTTYPE DHT22
LiquidCrystal lcd(7,6,5,4,3,2); 
DHT dht(DHTPIN, DHTTYPE);
byte degree[8]={
  0b00110,0b01001,0b01001,
  0b00110,0b00000,0b00000,
  0b00000,0b00000};
  

void setup() {
  lcd.begin(16,2);
  dht.begin();
  lcd.createChar(0, degree);
}

void loop() {
  int t = dht.readTemperature();
  int h = dht.readHumidity();
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("H:");
  lcd.print(h);
  lcd.print("%");
  lcd.setCursor(0,1);
  lcd.print("T:");
  lcd.print(t);
  lcd.write(byte(0));
  lcd.print("C");
  delay(1000);
  
}

4).  Power up and upload the sketch (code)

Power up the Arduino from your pc using usb cable. Lastly, upload the sketch onto your board.  For reference, see the video below.