Sie sind auf Seite 1von 8

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
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

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");
}

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
Example Project

The purpose of this experiment is to find out if the temperature is affected by the presence of
plants. To accomplish this, a plant was placed inside a sealed box for an hour with the DHT22
sensor inside obtaining readings every two seconds. I decided to utilize the golden pothos plant
since these plants need to be kept at a temperature of 15-29 C. Additionally, these plants can be
overwatered without causing any harms to their roots. The DHT22 sensor is also able to take
temperature readings, I decided to water the plant right before placing it inside the sealed box.

Since this sensor is only capable of taking readings every two seconds, it was hard to plot a good
graph. Recording a reading every two seconds. I decided to take the average of the recordings to
create a neater chart. Here in temperature graph, we can observe how the temperature started to
decrease as the sensor continued to take readings. For this chart the highest temperature reached
was 20.3 C, and the lowest reading was at 19.9 C. On the other hand, the humidity readings
were in percentage. The humidity inside the box, for the most part, seems to be increasing as the
readings are taken. The percentage of humidity started at 56.2%
Temperature (Sealed Box)
20.35
20.3
Temperature (Celsius)

20.25
20.2
20.15
20.1
20.05 Temperature
20
19.95
19.9
19.85
0 20 40 60 80 100 120 140
DHT22 Readings

Humidity (Sealed Box)


70
60
50
Humidity %

40
30
Humidity
20
10
0
0 20 40 60 80 100 120 140
DHT22 Readings

In the open plant box, the humidity percentage only went up to fifty-five percent and the lowest
reading was at 51.5 percent. The plant was also watered right before the readings were taken.
The humidity does not seem to increase regularly as the closed box did. Here in this chart, the
humidity only bounces back and forth within the ranges of 54.5 and 52. Moreover, the
temperature of the open box did not increase at all. In the open box, the temperature remained
between 19.5 C. and 19.4 C.
Humidity (Open Box)
55.5
55
54.5
54
53.5
53
52.5
52
51.5
51
50.5
0 20 40 60 80 100 120 140

Temperature (Open Box)


19.52

19.5
Temperature (Celsius)

19.48

19.46

19.44
Temperature
19.42

19.4

19.38
0 20 40 60 80 100 120 140
DHT22 Readings

Conclusion

I did expect the temperature to go down inside the sealed box. However, I believe to have a more
precise idea more than one plant should be used. In this case, I only utilized one golden pothos.
For the next experiment, I would like to use at least up to 3 plants to see how the temperature
drops on each box. Additionally, I am not sure if the sunlight had an effect on the temperature
change. The days, I decided to take the readings there was not enough sunlight.
Trouble Shooting
I tried to create an extension from the breadboard to the DHT22 sensor, but the sensor was not
capable of retaining the pins. Although electrical tape was used to hold the pins, the sensor fails
to read the temperature and humidity. In order for the sensor to function adequately, it needs to
be attached to the breadboard. Having the sensor connected to the breadboard is quite hard since
the sensor must be placed near the soil for precise readings to be recorded.

Das könnte Ihnen auch gefallen