11.DHT11温湿度传感器
"""
DHT11实验
2022.10.9
"""
from machine import Pin
import time
import dht
dht11=dht.DHT11(Pin(15))
if __name__=="__main__":
#定时器0用于定期采集电压
time.sleep(1)#先稳定传感器
while True:
dht11.measure()
temp = dht11.temperature()
humi=dht11.humidity()
if temp==None:
print("检测失败")
else:
print("温度:%d C 湿度:%d RH",temp,humi)
time.sleep(2)#延时确保传感器正常工作