以下是一个简单的NodeMCU采集JW01传感器数据的程序:

pin = 3 -- 设置传感器数据引脚为D3

function readJW01()
  status, temp, humi = dht.read11(pin) -- 读取传感器数据
  if status == dht.OK then 
    print("温度: "..temp.."℃  湿度: "..humi.."%") -- 打印数据
  elseif status == dht.ERROR_CHECKSUM then
    print("校验和错误")
  elseif status == dht.ERROR_TIMEOUT then
    print("超时错误")
  end
end

tmr.alarm(0, 3000, 1, function() readJW01() end) -- 每3秒读取一次数据

上述程序首先设置了传感器数据引脚为D3,然后定义了一个函数readJW01()用于读取传感器数据并打印。函数中使用dht.read11()函数读取传感器数据,根据返回的状态码判断读取是否成功,成功时打印温度和湿度数据。最后使用定时器每3秒调用一次readJW01()函数,实现数据采集。

nodemcu采集JW01传感器的程序怎么写

原文地址: https://www.cveoy.top/t/topic/bHol 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录