DHT11/DHT22 (ВЛАЖНОСТЬ И ТЕМПЕРАТУРА)
ОПИСАНИЕ
These DHTXX sensors are very popular among the Arduino Tinkerers. The DHT sensors are relative cheap sensors for measuring temperature and humidity.
These sensors inside contain a chip that does analog to digital conversion and spits out a digital signal with the temperature and humidity.
With any microcontroller(MCU) these signals are easy to ready.
SPECIFICATIONS DHT11 VS DHT22
You have to two versions of the DHT sensor.
DHT11
- Диапазон: 20-90%
- Абсолютная точность: ±5%
- Стабильность: ±1%
- Долговременная стабильность: ±1% за год
DHT22
- Диапазон: 0-100%
- Absolute accuracy: ±2%
- Стабильность: ±1%
- Долговременная стабильность: ±0.5% за год
As you can see from the specs above, the DHT22 is a little more accurate.
ARDUINO WITH DHT11 TEMPERATURE AND HUMIDITY SENSOR
Для схемы требуются следующие компоненты:
- Arduino
- DHT11
- Макетная плата
- 10K резистор
Here’s how to connect the DHT11 to an Arduino:
Контакты:
- VCC (от 3 В до 5 В)
- Вывод данных
- не подсоединен
- GND
ИСХОДНЫЙ КОД
Here’s the code you need for this project:
- Загрузите DHT11 library here
- Unzip the DHT library
- Rename the extracted folder and remove the “-“. Otherwise your Arduino IDE won’t recognize your library
- Install the DHT11 in your Arduino IDE
- Перезапустите Arduino IDE
- Go to Files / Examples / DHT_SENSOR_LIB / DHT Tester
- Выгрузите код
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<pre class="decode:1 " >// Example testing sketch for various DHT humidity/temperature sensors // Written by ladyada, public domain #include "DHT.h" #define DHTPIN 2 // what pin we're connected to // Раскомментируйте нужный тип сенсора! //#define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) // Initialize DHT sensor for normal 16mhz Arduino DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); Serial.println("DHTxx test!"); dht.begin(); } void loop() { // Подождать несколько секунд между измерениями. delay(2000); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); // Read temperature as Celsius float t = dht.readTemperature(); // Read temperature as Fahrenheit float f = dht.readTemperature(true); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t) || isnan(f)) { Serial.println("Ошибка чтения данных DHT сенсора!"); return; } // Compute heat index // Must send in temp in Fahrenheit! float hi = dht.computeHeatIndex(f, h); Serial.print("Влажность: "); <span role="presentation"> Serial.print(h); </span> Serial.print(" %\t"); Serial.print("Температура: "); Serial.print(t); Serial.print(" *C "); Serial.print(f); Serial.print(" *F\t"); Serial.print("Heat index: "); Serial.print(hi); Serial.println(" *F"); } |
Результаты
In this project the Arduino is measuring the temperature and humidity. Those two measures are being displayed in the serial monitor. Here’s what you should see in your Arduino IDE serial monitor.
I hope you found this guide useful.