NodeMCU通过DHT11获取环境温度湿度

作者:贝壳物联 | 更新时间:2017-03-27 | 浏览量:4687

一、硬件

  1. esp8266模块 ×1
  2. DHT11模块 ×1
  3. usb转ttl模块 ×1
  4. 杜邦线若干

二、软件

  1. (DHT,CJSON)的NodeMCU固件 下载
  2. NodeMCU Studio 2015工具 下载

三、实现步骤

1、esp8266模块刷nodemcu固件

参见:http://www.bigiot.net/help/20.html

2、接线

DHT11模块 DATA针脚接esp8266 的GPIO2,其他也可以(针脚索引对照表参见:http://www.bigiot.net/talk/37.html)

3、写入代码

pin = 4

tmr.alarm(1, 5000, 1, function()

status, temp, humi, temp_dec, humi_dec = dht.read(pin)

if status == dht.OK then

    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

end)


4、运行界面如下

NodeMCU的dht模块更多用发参见官方文档:http://nodemcu.readthedocs.io/en/dev/en/modules/dht/

稍后添加对接贝壳物联,上传实时数据并保存历史数据......


评论:共7条

xianruiqi 评论于:2017-05-24 15:33:55
这个的后续程序能给下嘛?对于写lua程序登陆贝壳物联还是有点心有余而力不足的。@贝壳物联
贝壳物联 回复于:2017-05-24 18:06:37
回复 @xianruiqi:lua登录贝壳物联可以参考https://www.bigiot.net/help/20.html
长安爱玉兰 回复于:2020-01-28 00:11:04
回复 @贝壳物联:我想知道温湿度如何能同时上传到两个数据接口的程序,那儿不会,能给下后面给我看看吗@贝壳物联
木人泪 评论于:2017-06-11 11:21:12
上传实时数据的程序成功没
levid 评论于:2020-03-26 21:38:14


Not connected to comm port


Connected to COM5 at 9600 baud

0倊??揜??OAE抏圑O7E掋翃
捽萨

NodeMCU custom build by frightanic.com
branch: master
commit: c8037568571edb5c568c2f8231e4f8ce0683b883
SSL: false
modules: adc,cjson,dht,enduser_setup,file,gpio,hx711,net,node,pwm,tmr,uart,wifi
build built on: 2016-04-09 04:21
powered by Lua 5.1.4 on SDK 1.4.0
set up wifi mode
>
FYI: LuaLoader version 0.91 is available for download!

Connected to wifi as:192.168.1.29
{"M":"checkin","K":"6e86b3cc7","ID":"16936"}
DHT Temperature:29;Humidity:47
DHT Temperature:717.4;Humidity:1203.2
DHT Temperature:717.2;Humidity:1177.6
DHT Temperature:717;Humidity:1177.6
DHT Temperature:692.1;Humidity:1177.6
DHT Temperature:692.1;Humidity:1177.6
DHT Temperature:691.7;Humidity:1177.6
DHT Temperature:691.4;Humidity:1177.6
DHT Temperature:691.4;Humidity:1177.6
DHT Temperature:691.4;Humidity:1177.6
DHT Temperature:666.5;Humidity:1177.6
DHT Temperature:666.3;Humidity:1177.6
DHT Temperature:666.1;Humidity:1177.6
DHT Temperature:665.8;Humidity:1177.6
DHT Temperature:26;Humidity:46
DHT Temperature:640.9;Humidity:1177.6
DHT Temperature:640.6;Humidity:1177.6
DHT Temperature:640.3;Humidity:1177.6
DHT Temperature:640.2;Humidity:1177.6
DHT Temperature:25;Humidity:46
DHT Temperature:25;Humidity:46
DHT Temperature:615.2;Humidity:1203.2
DHT Temperature:615.2;Humidity:1203.2
DHT Temperature:614.9;Humidity:1203.2
DHT Temperature:614.8;Humidity:1203.2
DHT Temperature:614.7;Humidity:1203.2
DHT Temperature:614.5;Humidity:1203.2
DHT Temperature:614.6;Humidity:1203.2
DHT Temperature:614.5;Humidity:1228.8
DHT Temperature:614.5;Humidity:1228.8
DHT Temperature:589.7;Humidity:1228.8
DHT Temperature:589.5;Humidity:1228.8
DHT Temperature:589.5;Humidity:1228.8
DHT Temperature:589.6;Humidity:1228.8
DHT Temperature:589.5;Humidity:1228.8
DHT Temperature:589.3;Humidity:1228.8
这是我读取的温湿度,为啥不正常呀。
deng 回复于:2020-05-30 20:53:19
回复 @levid:你是不是就照着上面的流程下来的,我一直显示DHT超时诶
deng 评论于:2020-07-14 09:16:00
求后续连接平台教程
返回顶部