nodeMCU 采集DS18B20温度

首先,用的是这种
DS18B20
连接方法也很简单:vcc接3.3V,GND接GND,中间那个D0我接的D3脚。

代码
local mk = 3  --DS18B20D3
ds18b20.setup(mk) --设置DS18B20


tmr.alarm(0, 3000, tmr.ALARM_AUTO, function() --每3秒发送一次数据
    ds18b20.read(
    function(ind,rom,res,temp,tdec,par)
       wd=string.format("%0.2f",temp)--获取浮点两位温度
print("xianzai:  " .. wd)
    end,{});
end)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/oXingChenWuJi/article/details/84403042