You are on page 1of 4

Overview

The DHT22 sensor is a low-cost temperature and humidity sensor. This sensor utilizes a
thermistor to measure the surrounding air, and sends out a digital signal on a data pin, which
means that no analog input pins are needed. It is a very simple sensor to utilize, however; it does
require a set timing to obtain data. This sensor is only capable of obtaining data once every two
seconds.

3 to 5V power
2.5mA mas current use during conversion
Good for 0-100% humidity readings with 2%-5% accuracy
-40 to 80 C temperature
0.5 Hz sampling accuracy
27mm X 59mm x 13.5mm (1.05 X 2.32 X0.53)
4 pins, 0.1 spacing

Connecting to Arduino

1. Connect 5Vto VCC on DHT22 (red)


2. Connect GND to GND on DHT22 (black)
3. Connect 2 Digital to DATA pin on DHT22 (purple)
4. Connect VCC to a blank rail (red)
5. Connect DATA to a blank rail (purple)
6. Place a 100k resistor in the blank rails created between VCC and DATA
Example Programs
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");

dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();

float t = dht.readTemperature();

float f = dht.readTemperature(true);

if (isnan(h) || isnan(t) || isnan(f)) {


Serial.println("Failed to read from DHT sensor!");
return;
}
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);

Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
}

Libraries
This sensor will require a DHT library to work. The library can be obtained at this link
https://github.com/adafruit/DHT-sensor-library

1- Once the GitHub pages has opened click on clone or download and download as ZIP
2- After downloading the library, click on the ZIP file.

3- Once you have clicked on the ZIP file a new folder for this library will be created.

4- Erase the ZIP file and rename the library folder to DHT sensor.

5- Next, open the Arduino software and include the libraries.

Click on sketch
Include library
Name of downloaded library
Program Overview

This part of the code is defining the sensor, so it can be initialized

Here a wait is being created for the sensor to take measurements. As mentioned before the
DHT22 sensor takes about 250 milliseconds and the readings may only last up to 2 seconds.

Read the temperature as Celsius

Read temperature as Fahrenheit


Isfahrenheit=true

You might also like