NodeMCU文档中文翻译 7 DHT温湿度传感器模块
2017-07-27 12:08
573 查看
【转载请注明出处: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)
参数
pinDHT传感器连接的引脚编号
(不能为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)
参数
pinDHT传感器连接的引脚编号
(不能为0), 数据类型是数字
返回结果
status常量定义
temp温度
(详情查看下面备注)
humi湿度(详情查看下面备注)
temp_dec温度小数
humi_dec湿度小数
备注
如果使用浮点型固件,那么 temp 和 humi 是浮点数字. 如果是整形固件, 连接
temp和
temp_dec或者
humi和
hum_dec即可得到最终值.
另请参阅
dht.read()
dht.readxx()
读取除了DHT11以外的所有温湿度传感器.
语法
dht.readxx(pin)
参数
pinDHT传感器连接的引脚编号
(不能为0), 数据类型是数字
返回结果
status常量定义
temp温度
(详情查看下面备注)
humi湿度(详情查看下面备注)
temp_dec温度小数
humi_dec湿度小数
备注
如果使用浮点型固件,那么 temp 和 humi 是浮点数字. 如果是整形固件, 连接
temp和
temp_dec或者
humi和
hum_dec即可得到最终值.
另请参阅
三、原文
摘自https://nodemcu.readthedocs.io/en/master/en/modules/dht/
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_TIMEOUTrepresent
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
pinpin
number of DHT sensor (can't be 0), type is number
Returns
statusas
defined in Constants
temptemperature
(see note below)
humihumidity
(see note below)
temp_dectemperature
decimal
humi_dechumidity
decimal
Note
If using float firmware then
tempand
humiare
floating point numbers. On an integer firmware, the final values have to be concatenated from
tempand
temp_dec/
humiand
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
pinpin
number of DHT11 sensor (can't be 0), type is number
Returns
statusas
defined in Constants
temptemperature
(see note below)
humihumidity
(see note below)
temp_dectemperature
decimal
humi_dechumidity
decimal
Note
If using float firmware then
tempand
humiare
floating point numbers. On an integer firmware, the final values have to be concatenated from
tempand
temp_dec/
humiand
hum_dec.
See also
dht.read()
dht.readxx()
Read all kinds of DHT sensors, except DHT11.
Syntax
dht.readxx(pin)
Parameters
pinpin
number of DHT sensor (can't be 0), type is number
Returns
statusas
defined in Constants
temptemperature
(see note below)
humihumidity
(see note below)
temp_dectemperature
decimal
humi_dechumidity
decimal
Note
If using float firmware then
tempand
humiare
floating point numbers. On an integer firmware, the final values have to be concatenated from
tempand
temp_dec/
humiand
hum_dec.
See also
dht.read()
相关文章推荐
- NodeMCU文档中文翻译 6 MQTT模块
- NodeMCU文档中文翻译 1 概要
- NodeMCU文档中文翻译 2 首页
- NodeMCU文档中文翻译 3 构建固件
- NodeMCU文档中文翻译 4 烧写固件
- NodeMCU文档中文翻译 8 Websocket模块
- NodeMCU文档中文翻译 6 MQTT模块
- NodeMCU文档中文翻译 5 上传代码
- Ext4.1.0 中文API文档已经全部翻译完成!
- SWFUpload 2.5.0版 官方说明文档 中文翻译版
- OAuth2.0官方文档中文翻译
- activemq-cpp-library-3.8.3中的README.txt中文翻译文档
- scikit-learn(sklearn) 0.19 中文文档的翻译计划,邀请你的加入 | ApacheCN
- hadoop2官方文档中文翻译---索引
- Spark SQL 官方文档-中文翻译
- ujquery.fancybox api开发文档中文翻译版
- Felomeng翻译:libsvm2.88之中文文档完全翻译版之目录
- 参与 Spring 4 中文文档翻译
- React-navigation 官方文档中文翻译(三) Configuring the Header
- ReactiveX文档中文翻译