超声波距离传感器允许您使用简单的超声波传感器,如HC -SR04(数据表, SparkFun)和 ESPHome 来测量距离。这些传感器通常不能测量超过约两米的任何东西,有时可能会发出一些恼人的咔嗒声。
该传感器平台期望传感器可以在特定引脚上发送触发脉冲,并在进行测量后发出回波脉冲。因为有时(例如,如果没有检测到物体)回波脉冲永远不会返回,这个传感器还有一个超时选项,它指定等待值的时间。
HC -SR04 超声波距离传感器。
采用esp8266
trigger_pin: D5
echo_pin: D6
Gnd:Gnd
VCC:5V
注意电源一定要接5V,接3.3V传感器失效,无法工作
配置基本引脚接口
sensor:
- platform: ultrasonic
trigger_pin: D5
echo_pin: D6
name: "Ultrasonic Sensor"
esphome:
name: nodemcu-test
esp8266:
board: nodemcuv2
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "ced33e5545b140bfcb5e681179b9bf33"
wifi:
ssid: "J09 502"
password: "qwertyuiop111"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Nodemcu-Test Fallback Hotspot"
password: "xzlKdVsXRfIy"
captive_portal:
# Example configuration entry
sensor:
# Example configuration entry(https://esphome.io/components/sensor/ultrasonic.html?highlight=hc)
- platform: ultrasonic
trigger_pin: D5
echo_pin: D6
name: "Saltlevel in percent"
update_interval: 10s
filters:
# Calculates in %
# Replace 0.42 by the height of your container. From the sensor to the bottom.
# I used this website to know how I should multiply my values :https://www.skillsyouneed.com/num/percent-change.html
- lambda: return (0.42-x)*(100/0.42);
unit_of_measurement: "%"
#(https://adonno.com/salt-level-sensor/)
- platform: ultrasonic
trigger_pin: D5
echo_pin: D6
name: "Saltlevel in cm"
update_interval: 10s
filters:
# Replace the 0.42 by the height of your container. From the sensor to the bottom.
# I multiplied by 100 in order to get CM since the sensor works in meters
- lambda: return (0.42-x)*100;
unit_of_measurement: "cm"
非常感谢各位大佬的支持,特别是ESPhome,到这里Homeassistant 与Ultrasonic Distance超声波距离传感器握手就算完成了。大家快去探索距离读取的乐趣吧!我们实现对外部世界进行感知,充分认识这个有机与无机的环境,科学地合理地进行创作和发挥效益,然后为人类社会发展贡献一点微薄之力。♂️♂️♂️
参考文献:
Salt level sensor for water softener in Home Assistant with ESPHome
Ultrasonic Distance Sensor