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.OKdht.ERROR_CHECKSUMdht.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.read()

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.read()


三、原文

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.OKdht.ERROR_CHECKSUMdht.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 Constants
  • temp temperature (see note below)
  • humi humidity (see note below)
  • temp_dec temperature decimal
  • humi_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 Constants
  • temp temperature (see note below)
  • humi humidity (see note below)
  • temp_dec temperature decimal
  • humi_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.read()

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 Constants
  • temp temperature (see note below)
  • humi humidity (see note below)
  • temp_dec temperature decimal
  • humi_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.read()




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值