AHT20 Temperature and Humidity Sensor
About 3 min
AHT20 Temperature and Humidity Sensor
Synchronized Device Documentation
This page corresponds to the synchronized Chinese source. Commands, JSON examples, API paths, field names, and screenshots are kept aligned with the Chinese device-side source documentation.
What This Page Covers
- Peripheral capability, supported device types, and wiring constraints.
- Web console configuration fields and recommended parameter values.
- PeriphExec integration, validation steps, and troubleshooting notes.
Source Reference
The detailed operational source is preserved below so implementation details stay exact while the English navigation, titles, and reading path remain available.
AHT20 温湿度传感器
AHT20 是低成本 I2C 温湿度传感器,适合替代 DHT11/DHT22 做更稳定的室内环境采集。当前驱动为轻量实现,不依赖额外第三方库,精简 ESP32 固件可用。
接线
| AHT20 | ESP32 |
|---|---|
| VCC | 3.3V |
| GND | GND |
| SDA | GPIO21 |
| SCL | GPIO22 |
默认地址为 0x38。
配置方式
方式1:Web界面配置(推荐)
AHT20 保存前重点核对 I2C 总线、地址和采集间隔。
步骤1:进入外设管理页面
- 打开浏览器访问 ESP32 IP 地址
- 登录后点击左侧菜单 外设配置
步骤2:添加AHT20外设
点击 新增外设 按钮
填写配置:
字段 填写内容 说明 外设ID aht20_i2c唯一标识符 名称 AHT20温湿度显示名称 外设类型 通用传感器 (type: 38) I2C传感器 SDA引脚 21I2C数据引脚 SCL引脚 22I2C时钟引脚 I2C地址 0x38默认地址 采集间隔 50005秒 点击 保存
步骤3:验证配置
- 在外设列表中找到刚添加的外设
- 点击 启用 开关
- 等待5秒后查看温度和湿度数据
💡 提示:AHT20是低成本替代DHT11/DHT22的I2C方案,精度更好
方式2:JSON配置文件导入
{
"id": "aht20_i2c",
"name": "AHT20温湿度",
"type": 2,
"enabled": false,
"pinCount": 2,
"pins": [21, 22, 255, 255, 255, 255, 255, 255],
"params": {
"frequency": 100000,
"address": 0,
"isMaster": true
}
}外设执行联动
Web界面配置步骤
创建湿度采集与控制规则
- 切换到 外设执行管理 标签
- 点击 新增规则 按钮
- 配置定时触发器:
- 触发类型:定时触发
- 执行间隔:30 秒
- 添加动作:
- 动作1:读取湿度
- 动作类型:传感器读取
- 目标外设:aht20_i2c
- 数据字段:humidity
- 动作1:读取湿度
- 开启 执行后上报数据
- 点击 保存
创建湿度过低打开加湿器规则
- 创建新规则
- 配置事件触发器:
- 触发类型:事件触发
- 事件ID:ds:aht20_i2c_humidity
- 比较操作:小于
- 比较值:40(%)
- 添加动作:
- 动作类型:高电平
- 目标外设:relay_humidifier(加湿器继电器)
- 点击 保存
💡 提示:事件ID格式为
ds:{外设ID}_{字段名}
JSON配置示例
{
"id": "exec_aht20_humidity_read",
"name": "AHT20湿度采集",
"enabled": false,
"triggers": [
{
"triggerType": 1,
"timerMode": 0,
"intervalSec": 30
}
],
"actions": [
{
"targetPeriphId": "aht20_i2c",
"actionType": 19,
"actionValue": "{\"periphId\":\"aht20_i2c\",\"sensorCategory\":\"AHT20\",\"dataField\":\"humidity\",\"sensorLabel\":\"湿度\",\"unit\":\"%\",\"decimalPlaces\":1,\"driverParams\":{\"addr\":\"0x38\",\"sda\":21,\"scl\":22}}",
"useReceivedValue": false,
"syncDelayMs": 0,
"execMode": 0
}
],
"reportAfterExec": true
}湿度过低打开加湿器继电器
{
"id": "exec_aht20_dry_relay",
"name": "AHT20低湿打开加湿器",
"enabled": false,
"triggers": [
{
"triggerType": 4,
"eventId": "ds:aht20_i2c_humidity",
"operatorType": 3,
"compareValue": "40"
}
],
"actions": [
{
"targetPeriphId": "relay_humidifier",
"actionType": 0,
"actionValue": "",
"useReceivedValue": false,
"syncDelayMs": 0,
"execMode": 0
}
],
"reportAfterExec": true
}可采集字段
| dataField | 含义 | 单位 |
|---|---|---|
temperature | 温度 | ℃ |
humidity | 相对湿度 | % |
