Have you ever wanted to track how full your water tank is, detect how close an object is, or create smart automations based on distance—all without spending a lot of money?
Good news: you can do all of that with a DIY waterproof ultrasonic distance sensor for Home Assistant, and it’s easier than you might think!

In this short article, I’ll give you a simple overview of how I built mine, show you a few examples of what it can do, and tell you where to get the complete free PDF guide with everything you need—including wiring diagrams, ESPHome code, and automation examples.
Table of Contents
What Does This Waterproof Ultrasonic Distance Sensor for Home Assistant Do?
This sensor can measure distances accurately, even in wet environments like near a water tank or in your garden. And because it’s connected to Home Assistant, you can use it to:
- Turn on a light when something gets close
- Monitor the level of water or another liquid
- Trigger alerts or automations
- View distance data in real-time on your phone or dashboard
All of this works using the AJ-SR04M ultrasonic sensor and a small Wi-Fi board called the D1 Mini (ESP8266).

Want to see all the parts, code, and diagrams?
Download the free step-by-step PDF guide
Simple Setup (No Soldering or Resistors Needed)
The best part? The basic setup requires no soldering, no special tools, and no resistors.
I connected the AJ-SR04M sensor to a D1 Mini using just four wires:
D1 Mini Pin | Connects to AJ-SR04M |
---|---|
D1 (GPIO5) | Echo |
D2 (GPIO4) | Trig |
G | GND |
5V | 5V |
Then, I uploaded a small piece of ESPHome code to the D1 Mini, and just like that—Home Assistant detected the new smart sensor automatically!
The full ESPHome code is included in the PDF, ready to copy and paste.
Download the PDF to see the exact wiring diagram and full code:
Click here to get the guide
Real Example: Detecting Objects and Measuring Water Levels
To show how well it works, I ran a few tests:
- I placed a Rubik’s cube in front of the sensor to test the distance measurement. As I moved it closer and further away, the values updated in real time.
- Then, I made a Home Assistant automation: if the object comes closer than 25 cm, a light turns on. It worked instantly!
- I even tested the sensor above a glass of water to simulate a water tank. The readings changed as I added or removed water—proving the sensor works well in these conditions.
This makes it a perfect tool for monitoring tanks, smart bins, or even parking assistants.
Video Tutorial
Prefer to watch instead of read?
A full video walkthrough is available here:
It shows the wiring, the code, the Home Assistant setup, and a few live tests.
Want to Go Deeper? Optional Advanced Features Inside the PDF
If you’re the kind of person who likes to experiment, there are a few advanced features you can try:
- Switching between sensor modes using resistors (for different reading methods)
- Using the UART mode for serial data reading
- Adding a template sensor to turn distance values into percentages (like how full your tank is)
But don’t worry—you don’t need to do any of that for the basic setup to work. These options are only for those who want to explore further.
All the advanced modes and code examples are included in the PDF.
Download the complete PDF here and start building:
Get the Free PDF Guide
Physical Mounting Tips
You can mount the sensor in many ways:
- Drill a hole for the sensor head and attach it firmly
- Use the long cable to hide the electronics in a dry area
- 3D print a custom case for a cleaner setup (link in the PDF)
Why This Project is Great
This smart waterproof sensor project is:
- Beginner-friendly
- Useful for real-world automations
- Low-cost (under $10–15 total)
- Safe to use in wet environments
Plus, it’s a great way to learn about ESPHome, sensors, and Home Assistant integrations without needing advanced electronics knowledge.
Build It Yourself in Under an Hour
If you’re ready to get started, download the full step-by-step guide now. It includes:
- A complete parts list
- Clear wiring diagrams
- Copy-paste ESPHome code
- Home Assistant automation examples
- Optional advanced features
Click here to download the free PDF
Everything you need is inside, and it’s completely free.
Want the More DIY Smart Sensors for Home Assistant?
I also have multiple full written articles about how to build yourself a smart sensor for HA that you can find here.