本帖最后由 slychen 于 2025-2-28 08:40 编辑
一直在用LD2410作为人体传感器在用,最近想在餐厅的开关里装人体传感器,但2410的尺寸偏大装不下,就找了个尺寸合适的2420装入,没想到居然还挺好用的。
硬件接法参照2420手册:esp8266的RX接2420的ot1、TX接2420的RX。
增加TEMT6000,接入esp8266点ADC接口作为光照传感器。
原来这86开关是8266控制的,用细线将几个IO口引出接左边为TEMT6000光线传感器,右边为LD2420:
装好点样子,左边的按键开了个孔,嵌入个亚克力给光照传感器透光:
web界面:
Homeassistant界面:
esphome代码如下:
esphome:
name: dinner_room_sensor_switch
esp8266:
board: esp01_1m
# Enable logging
logger:
baud_rate: 0
# Enable Home Assistant API
api:
ota:
platform: esphome
password: ""
wifi:
ssid: !secret wifi_ssid #改为你自己家的WIFI名称
password: !secret wifi_password #改为你家的WIFI密码
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Dinner Room Sensor Switch"
password: ""
web_server:
port: 80
captive_portal:
uart:
id: uart_bus
tx_pin: GPIO1 #使用D1 mini RX
rx_pin: GPIO3 #使用D1 mini TX
baud_rate: 115200
parity: NONE
stop_bits: 1
binary_sensor:
# 物理按钮开关
- platform: gpio
pin: GPIO05
name: "Switch1"
internal: true
on_press:
then:
- switch.toggle: relay_1
- logger.log: "Power Button Turned Press!"
filters:
- delayed_on_off: 50ms
- platform: gpio
pin: GPIO04
name: "Switch2"
internal: true
on_press:
then:
- switch.toggle: relay_2
- logger.log: "Power Button Turned Press!"
filters:
- delayed_on_off: 50ms
- platform: ld2420
has_target:
name: Presence
switch:
- platform: gpio
pin: GPIO14
#反向开关
#inverted: true
name: "餐厅开关1"
id: relay_1
- platform: gpio
pin: GPIO13
#反向开关
#inverted: true
name: "厨房大灯"
id: relay_2
ld2420:
uart_id: uart_bus
text_sensor:
- platform: ld2420
fw_version:
name: Firmware version
sensor:
- platform: ld2420
moving_distance:
name : Moving Distance
- platform: adc
pin: A0
name: "餐厅光照度"
device_class: illuminance
unit_of_measurement: lx
filters:
- lambda: |-
return (x / 10000.0) * 2000000.0;
update_interval: 10s
select:
- platform: ld2420
operating_mode:
name: Operating Mode
number:
- platform: ld2420
presence_timeout:
name: Timeout Presence
min_gate_distance: #最小门数,最小门数不要选择0,否则会有底噪干扰
name: Min Gate
max_gate_distance: #最大门数,超过12无效,每个门的距离大概是0.7米,按照自己的需求选择
name: Max Gate
# See "Number" section below for detail
gate_move_sensitivity:
name: Move Calibration Sensitivity Factor
gate_still_sensitivity:
name: Still Calibration Sensitivity Factor
#直接选择设置各个门的阈值,后面根据距离可以自己增加门数到12
gate_0:
move_threshold:
name: Gate 0 Move Threshold
still_threshold:
name: Gate 0 Still Threshold
gate_1:
move_threshold:
name: Gate 1 Move Threshold
still_threshold:
name: Gate 1 Still Threshold
gate_2:
move_threshold:
name: Gate 2 Move Threshold
still_threshold:
name: Gate 2 Still Threshold
gate_3:
move_threshold:
name: Gate 3 Move Threshold
still_threshold:
name: Gate 3 Still Threshold
gate_4:
move_threshold:
name: Gate 4 Move Threshold
still_threshold:
name: Gate 4 Still Threshold
button:
- platform: ld2420
apply_config:
name: Apply Config
factory_reset:
name: Factory Reset
restart_module:
name: Restart Module
revert_config:
name: Undo Edits
复制代码
因为开关距离餐桌较近(2米左右),每个门代表0.7米,所以可以将传感门设置最小为1、最大为3,避免误触发。gate_0到gate_4的那段为直接设置从门0到门4的阈值改变灵敏度;也可以改为选择每个门来分别设置每个门的阈值,用了这种设置原来每个门直接设置的滑块就不会出现,代码如下:
number:
- platform: ld2420
presence_timeout:
name: Detection Presence Timeout
min_gate_distance:
name: Min Gate
max_gate_distance:
name: Max Gate
gate_select:
name: Select Gate to Set
still_threshold:
name: Set Still Threshold Value
move_threshold:
name: Set Move Threshold Value
复制代码
另外LD2420的自动校准也挺好用的,可以排除干扰源:在前面没有人的情况下Operating Mode(运行模式), 选择 Calibrate(校准)让 它收集底噪信息约两三分钟后,它会计算这段时间的平均底噪信息,按下Aply Config, 就会自动保存校正结果排除底噪干扰。
另外简单说明下:所谓的门的概念有点不好理解,其实就是距离区间,一个门的距离大概0.7米,从离传感器最近的0门到最远12门大概就是8米多的距离;每个门的阈值调整就是调整这距离区间内的灵敏度,将人体移动感应到的信号值大小从0到65535分级,如设置值1000,就表示感应移动信号强度达到1000时传感器就发出有人的信号,设置数值越大就表示人体移动幅度越大传感器才发出有人信号。