在本文中,我们将查看用于测量温度和湿度的DHTXX系列传感器,两个功能都集成到一个模块中。
我们将看到它们的规范,以便您可以为您的项目选择最佳传感器,最后我们将与Arduino接口,并在Arduino IDE软件的串行监视器中读取值。
DHTxx consist of just two series DHT11 and DHT22. The major difference between them is their specification and cost. DHT11 is low end sensor and DHT22 is high end one. DHT22 is more expensive than DHT11, but low end is decent enough for hobby project unless you do some serious measurement with you project.
DHTxx 4-pin设备之一them is NC or no connection so, we are going to use just 3-pins. Two of them are supply pins and remaining one is output pin. The sensor may look simple, but it requires a library for handling it.
该传感器由热敏电阻,湿度传感设备和嵌入模块中的微控制器组成。它们的规格如下:
DHT11:
•工作电压范围为3至5V。
•其最大电流消耗为2.5mA。
•它可以测量20%至80% - /+ 5%精度的湿度。
• It can measure temperature ranging from 0 to 50 degree Celsius +/- 2% accuracy.
• It refreshes it value every one second.
•它的尺寸为15.5mm x 12mm x 5.5mm
DHT22:
•工作电压为3至5V
•其最大电流消耗为2.5mA。
• It can measure humidity ranging from 0% to 100% 2-5 % accuracy.
• It can measure temperature ranging from -40 to +125 degree Celsius +/- 0.5% accuracy.
•它刷新它每一秒钟的价值两倍。
•它的尺寸为15.1mm x 25mm x 7.7mm
From the above raw specifications you can choose which one is optimum for your project.
数据引脚应始终与4.7K至10K的上拉电阻连接。上面的插图传感器带有PCB,带有消除的NC引脚和上拉电阻。但是有些传感器没有这些功能,没有上拉电阻,读数发送给Arduino将是致命的错误值。
现在,我们将与Arduino接口DHT传感器。在进行项目之前,下载库文件以下链接:
https://arduino-info.wikispaces.com/file/detail/DHT-lib.zip
You just need these four components: DHTxx sensor, arduino Uno, USB cable, and a PC.
Just insert the sensor on analog pins of the arduino as illustrated in prototype and dump the code to arduino, open the serial monitor and you can see the readings.
Author’s prototype:
// ------------------------------R.Girish开发的程序------------------- // #include DHT DHT;#define dhtxxpin a1 int p = a0;int n = a2;int ack;int f;void setup(){serial.begin(9600);pinmode(p,输出);pinmode(n,输出);} void loop(){digitalwrite(p,1);DigitalWrite(n,0); ack=0; int chk = DHT.read11(DHTxxPIN); switch (chk) { case DHTLIB_ERROR_CONNECT: ack=1; break; } if(ack==0) { f=DHT.temperature*1.8+32; Serial.print("Temperature(°C) = "); Serial.println(DHT.temperature); Serial.print("Temperature(°F) = "); Serial.print(f); Serial.print("\n"); Serial.print("Humidity(%) = "); Serial.println(DHT.humidity); Serial.print("\n"); delay(500); } if(ack==1) { Serial.print("NO DATA"); Serial.print("\n\n"); delay(500); } } //----------------------Program developed by R.Girish-------------//
Serial monitor output:

Sir can we use LM35 or thermistor sensors instead of DHTxx?
Ananth, it will depend on the specifications of the two sensors, if they match reasonably well then perhaps it could work with the proposed Arduino design.
嗨,Ananth
you can't use LM35 in the place of DHT sensor, they both work in very different way.
如果我们可以控制温度和湿度,如何
先生将尽快回复您…
嗨,尼丁,
To control temperature and humidity you need a cooling or heating device or both. To control humidity you need water vaporizer (humidifier) or dehumidifier or both. The sensor and Arduino must be programmed in a way that it triggers the mentioned climate control devices on/off to meet your set temp & humidity.
以上概念在封闭的外壳中最佳地工作。
One example of this is a incubator://m.addme-blog.com/incubator-using-arduino-with-automatic-temperature-and-humidity-control/
问候
你好先生 !
我使用正确的DHT库
Above mention link.but I face error in compilation.
void循环:
错误:dhtlib_error_connect
在这方面没有申明。
但是我从代码中删除了这一行
(case DHTLIB_ERROR_CONNECT:)
Compilation successful.
hi, I am also getting error : DHTLIB_ERROR_CONNECT
在这方面没有申明。
可能是什么问题呢?
Hi, you must find and import the dht.h library correctly, it appears to be be slightly difficult since most files do not seem to work, but you have to do it, you can refer to the following link for some info:
https://community.blynk.cc/t/correct-dht-library/30774/5
THANKS,BRO. IN EGG INCUBATOR PROJECT
DHTLIB_ERROR_CONNECT’ was not declared in this scope. HOW CAN I SOLVE THIS ERROR.
Sorry Shaik, I tried a lot to find the solution, but I could not understand the reason….. actually I am an Arduino expert, and this code was generated by an external author.