NodeMCU文档中文翻译 7 DHT温湿度传感器模块
【转载请注明出处:http://blog.csdn.net/leytton/article/details/76178661】
一、序言
DHT11 温湿度模块传感器
资料下载:http://pan.baidu.com/s/10CeBk
一 描述
1 可以检测周围环境的湿度和温度
2 传感器采用DHT11
3 湿度测量范围:20%-95%(0度-50度范围)湿度测量误差:+-5%
4 温度测量范围:0度-50度 温度测量误差:+-2度
4 工作电压3.3V-5V
5 输出形式 数字输出
6 设有固定螺栓孔,方便安装
7 小板PCB尺寸:3.2cm * 1.4cm
8 电源指示灯(红色)
9 每套重量约为8g
二 模块接口说明(3线制)
1 VCC 外接3.3V-5V
2 GND 外接GND
3 DO 小板开关数字量输出接口 接单片机IO口
二、译文
Constants | 一些函数常量 |
dht.read() | 读取所有DHT传感器,包括 DHT11, 21, 22, 33, 44 温湿度传感器. |
dht.read11() | 读取DHT11温湿度传感器. |
dht.readxx() | 读取除了DHT11以外的所有温湿度传感器. |
常量
一些函数常量.
dht.OK
, dht.ERROR_CHECKSUM
, dht.ERROR_TIMEOUT
表示DHT传感器读取状态值
dht.read()
读取所有DHT传感器,包括 DHT11, 21, 22, 33, 44 温湿度传感器.
语法
dht.read(pin)
参数
pin
DHT传感器连接的引脚编号
(不能为0), 数据类型是数字
返回结果
status
常量定义temp
温度 (详情查看下面备注)humi
湿度(详情查看下面备注)temp_dec
温度小数humi_dec
湿度小数
备注
如果使用浮点型固件,那么 temp 和 humi 是浮点数字. 如果是整形固件, 连接 temp 和temp_dec 或者 humi 和hum_dec即可得到最终值.
示例代码
pin = 5
status, temp, humi, temp_dec, humi_dec = dht.read(pin)
if status == dht.OK then
-- 整形固件使用这段代码
print(string.format("DHT Temperature:%d.%03d;Humidity:%d.%03d\r\n",
math.floor(temp),
temp_dec,
math.floor(humi),
humi_dec
))
-- 浮点型固件使用这段代码
print("DHT Temperature:"..temp..";".."Humidity:"..humi)
elseif status == dht.ERROR_CHECKSUM then
print( "DHT Checksum error." )
elseif status == dht.ERROR_TIMEOUT then
print( "DHT timed out." )
end
dht.read11()
读取DHT11温湿度传感器.
语法
dht.read11(pin)
参数
pin
DHT传感器连接的引脚编号
(不能为0), 数据类型是数字
返回结果
status
常量定义temp
温度 (详情查看下面备注)humi
湿度(详情查看下面备注)temp_dec
温度小数humi_dec
湿度小数
备注
如果使用浮点型固件,那么 temp 和 humi 是浮点数字. 如果是整形固件, 连接 temp
和temp_dec
或者 humi
和hum_dec
即可得到最终值.
另请参阅
dht.readxx()
读取除了DHT11以外的所有温湿度传感器.
语法
dht.readxx(pin)
参数
pin
DHT传感器连接的引脚编号
(不能为0), 数据类型是数字
返回结果
status
常量定义temp
温度 (详情查看下面备注)humi
湿度(详情查看下面备注)temp_dec
温度小数humi_dec
湿度小数
备注
如果使用浮点型固件,那么 temp 和 humi 是浮点数字. 如果是整形固件, 连接 temp
和temp_dec
或者 humi
和hum_dec
即可得到最终值.
另请参阅
三、原文
DHT Module
Since | Origin / Contributor | Maintainer | Source |
---|---|---|---|
2015-06-17 | RobTillaart | Vowstar | dhtlib |
Constants | Constants for various functions. |
dht.read() | Read all kinds of DHT sensors, including DHT11, 21, 22, 33, 44 humidity temperature combo sensor. |
dht.read11() | Read DHT11 humidity temperature combo sensor. |
dht.readxx() | Read all kinds of DHT sensors, except DHT11. |
Constants
Constants for various functions.
dht.OK
, dht.ERROR_CHECKSUM
, dht.ERROR_TIMEOUT
represent
the potential values for the DHT read status
dht.read()
Read all kinds of DHT sensors, including DHT11, 21, 22, 33, 44 humidity temperature combo sensor.
Syntax
dht.read(pin)
Parameters
pin
pin
number of DHT sensor (can't be 0), type is number
Returns
status
as defined in Constantstemp
temperature (see note below)humi
humidity (see note below)temp_dec
temperature decimalhumi_dec
humidity decimal
Note
If using float firmware then temp
and humi
are
floating point numbers. On an integer firmware, the final values have to be concatenated from temp
and temp_dec
/ humi
and hum_dec
.
Example
pin = 5
status, temp, humi, temp_dec, humi_dec = dht.read(pin)
if status == dht.OK then
-- Integer firmware using this example
print(string.format("DHT Temperature:%d.%03d;Humidity:%d.%03d\r\n",
math.floor(temp),
temp_dec,
math.floor(humi),
humi_dec
))
-- Float firmware using this example
print("DHT Temperature:"..temp..";".."Humidity:"..humi)
elseif status == dht.ERROR_CHECKSUM then
print( "DHT Checksum error." )
elseif status == dht.ERROR_TIMEOUT then
print( "DHT timed out." )
end
dht.read11()
Read DHT11 humidity temperature combo sensor.
Syntax
dht.read11(pin)
Parameters
pin
pin
number of DHT11 sensor (can't be 0), type is number
Returns
status
as defined in Constantstemp
temperature (see note below)humi
humidity (see note below)temp_dec
temperature decimalhumi_dec
humidity decimal
Note
If using float firmware then temp
and humi
are
floating point numbers. On an integer firmware, the final values have to be concatenated from temp
and temp_dec
/ humi
and hum_dec
.
See also
dht.readxx()
Read all kinds of DHT sensors, except DHT11.
Syntax
dht.readxx(pin)
Parameters
pin
pin
number of DHT sensor (can't be 0), type is number
Returns
status
as defined in Constantstemp
temperature (see note below)humi
humidity (see note below)temp_dec
temperature decimalhumi_dec
humidity decimal
Note
If using float firmware then temp
and humi
are
floating point numbers. On an integer firmware, the final values have to be concatenated from temp
and temp_dec
/ humi
and hum_dec
.
See also