学物联网,来万物简单IoT物联网!!
AHT21B是一款极具性价比的数字温度传感器,其基于AHT21开发的集成式温湿度传感器模块,模块内部配有一个全新设计的ASIC专用芯片、一个经过改进的MEMS半导体电容式湿度传感单元以及一个标准的片上温度传感单元;输出接口为标准的I2C通信格式,具有响应速度快、精度高、稳定性高等特点,性能达到国际水平,是国产替代进口的理想选择。
应用领域:广泛应用于消费、电子、医疗、汽车、工业、气象等领域,包括暖通空调、除湿器、冰箱等家电产品。
引脚定义
aht21bObj = AHT21B(i2cObj)
参数 | 类型 | 必选参数? | 说明 |
---|---|---|---|
i2cObj | I2C | 是 | 传入i2c对象 |
from machine import I2C,Pin # 驱动库
import aht21b # AHT21B加速度计传感器驱动库
# 初始化I2C类型的设备
i2cObj = I2C(1, scl=Pin(22), sda=Pin(21), freq=400000)
print("AHT21B inited!")
aht21bObj = aht21b.AHT21B(i2cObj) # 初始化AHT21B传感器对象
AHT21B inited!
AHT21B.getTemperature()
from machine import I2C,Pin # 驱动库
import aht21b # AHT21B加速度计传感器驱动库
import utime
# 初始化I2C类型的设备
i2cObj = I2C(1, scl=Pin(22), sda=Pin(21), freq=400000)
print("AHT21B inited!")
aht21bObj = aht21b.AHT21B(i2cObj) # 初始化AHT21B传感器对象
while True:
utime.sleep(1)
readtemp = aht21bObj.getTemperature()
print("temperature is ", readtemp, "°C")
AHT21B inited!
temperature is 25.3°C
temperature is 26.1°C
temperature is 25.7°C
AHT21B.getHumidity()
from machine import I2C,Pin # 驱动库
import aht21b # AHT21B加速度计传感器驱动库
import utime
# 初始化I2C类型的设备
i2cObj = I2C(1, scl=Pin(22), sda=Pin(21), freq=400000)
print("AHT21B inited!")
aht21bObj = aht21b.AHT21B(i2cObj) # 初始化AHT21B传感器对象
while True:
utime.sleep(1)
readhum = aht21bObj.getHumidity()
print("humidity is ", readhum, "%RH")
AHT21B inited!
humidity is 65.3%RH
humidity is 78.1%RH
humidity is 69.7%RH
AHT21B.getTempHumidity()
from machine import I2C,Pin # 驱动库
import aht21b # AHT21B加速度计传感器驱动库
import utime
# 初始化I2C类型的设备
i2cObj = I2C(1, scl=Pin(22), sda=Pin(21), freq=400000)
print("AHT21B inited!")
aht21bObj = aht21b.AHT21B(i2cObj) # 初始化AHT21B传感器对象
while True:
utime.sleep(1)
readtemp,readhum = aht21bObj.getTempHumidity()
print("TempHumidity is ", readhum, "%RH",readtemp, " °C")
AHT21B inited!
TempHumidity is 65.3%RH 26.3°C
TempHumidity is 78.1%RH 25.6°C
TempHumidity is 69.7%RH 26.2°C
# Python代码
from machine import I2C,Pin # 驱动库
import aht21b # AHT21B加速度计传感器驱动库
import utime
# 初始化I2C类型的设备
i2cObj = I2C(1, scl=Pin(22), sda=Pin(21), freq=400000)
print("AHT21B inited!")
aht21bObj = aht21b.AHT21B(i2cObj) # 初始化AHT21B传感器对象
while True:
utime.sleep(1)
readtemp,readhum = aht21bObj.getTempHumidity()
print("TempHumidity is ", readhum, "%RH",readtemp, " °C")
AHT21B inited!
TempHumidity is 65.3%RH 26.3°C
TempHumidity is 78.1%RH 25.6°C
TempHumidity is 69.7%RH 26.2°C
[1] AHT21温度传感器中文数据手册参考
[2] AHT21传感器购买链接