Ultrasonic Sensor With Home Assistant

About the project

Will guide you to integrate the UltraSonic sensor with Home Assistant.

Project info

Difficulty: Easy

Platforms: DFRobotHome AssistantSparkFun

Estimated time: 1 hour

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

SparkFun Ultrasonic Sensor - HC-SR04 SparkFun Ultrasonic Sensor - HC-SR04 x 1
DFRobot Beetle - The Smallest Arduino DFRobot Beetle - The Smallest Arduino x 1

Software apps and online services

Home Assistant Home Assistant

Story

In this blog, I will show you how to integrate an ultra-sonic sensor with ESPHome in home assistant. An ultra sonic sensor is a device that can measure the distance to an object by sending and receiving sound waves. It can be used for various applications, such as obstacle detection, level measurement, parking sensors, etc.

What is ESPHome and Home Assistant?

ESPHome is a system that allows you to easily create and manage custom firmware for ESP8266 and ESP32 devices. It uses a simple configuration file that defines the components and sensors you want to use and generates the code and binary files for you. You can then upload the firmware to your device using a USB cable or over-the-air (OTA) updates.

Home Assistant is an open-source platform that allows you to control and automate your smart home devices. It supports hundreds of integrations with different services and devices, such as lights, switches, sensors, cameras, media players, etc. You can access and control your home assistant from a web browser, a mobile app, or a voice assistant.

ESPHome and Home Assistant work very well together, as they can communicate with each other using the native API. This means that you can easily add your ESPHome devices to your home assistant without any extra configuration or coding. You can also use home assistant to monitor and control your ESPHome devices, and create automations based on their states and events.

How to Integrate Ultra Sonic Sensor with ESPHome in Home Assistant

To integrate an ultra-sonic sensor with ESPHome in home assistant, you will need the following:

  • An ESP8266 or ESP32 device, such as NodeMCU, Wemos D1 Mini, or Xiao ESP32 S3 Sense
  • An ultra sonic sensor, such as HC-SR04
  • A breadboard and some jumper wires
  • A computer with ESPHome and Home Assistant installed.

Get PCBs for Your Projects Manufactured

You must check out PCBWAY for ordering PCBs online for cheap!

You get 10 good-quality PCBs manufactured and shipped to your doorstep for cheap. You will also get a discount on shipping on your first order. Upload your Gerber files onto PCBWAY to get them manufactured with good quality and quick turnaround time. PCBWay now could provide a complete product solution, from design to enclosure production. Check out their online Gerber viewer function. With reward points, you can get free stuff from their gift shop. Also, check out this useful blog on PCBWay Plugin for KiCad from here. Using this plugin, you can directly order PCBs in just one click after completing your design in KiCad.

Let's start with hardware the setup

Connect the ultra-sonic sensor to your ESP device using the breadboard and jumper wires. The wiring diagram is shown below:

Connect VCC to 5V and GND to Gnd and Trigger to pin 0 and ECHO to pin 1.

Home Assistant Setup

Next, navigate to the Home Assistant and open the ESPHome.

Next, select one of your ESP devices or create a new one. In this case I'm going to use my existing device.

Open the yaml file and add these following.

sensor:
- platform: ultrasonic
trigger_pin: 0
echo_pin: 1
name: "Ultrasonic Sensor"
update_interval: 2s

Then next, click install. and choose your prefer method. I'm going to use wirelessly. Because my device is already connected with my network.

Wait until it finishes the upload.

Then navigate to the device property and here you can see the Sensor measurement.

Next, add the measurement to the dashboard.

Conclusion

In this blog, I have shown you how to integrate an ultra-sonic sensor with ESPHome in home assistant. This is a simple and effective way to use an ultra-sonic sensor in your smart home projects. You can also use other types of sensors and components with ESPHome and home assistant and create your own custom firmware and integrations. I hope you found this blog helpful and informative. If you have any questions or feedback, please leave a comment below. Thank you for reading!

Credits

Leave your feedback...