The HC-SR04 and JSN-SR04T are both inexpensive ultrasonic distance sensors, but they are aimed at very different environments.
For a dry indoor robot or bench project, the HC-SR04 is hard to beat for simplicity and price. For a water tank, sump, cistern or outdoor installation, the waterproof transducer of the JSN-SR04T usually makes far more sense.
The catch is that the JSN-SR04T has a much larger minimum measurement distance. Current ESPHome documentation specifies roughly 25 cm to 600 cm for the supported JSN-SR04T/AJ-SR04M serial modes, while the classic HC-SR04 is commonly specified around 2 cm to 400 cm. That 25 cm blind zone can decide whether a tank installation works at all.
Quick Comparison
| Feature | HC-SR04 | JSN-SR04T |
|---|---|---|
| Typical range | About 2 cm to 400 cm | ESPHome-supported modes: about 25 cm to 600 cm |
| Waterproof sensor head | No | Yes |
| Electronics waterproof | No | No — controller board still needs protection |
| Transducers | Separate open transmitter + receiver | Single sealed remote transducer |
| Typical interface | Trigger + Echo pulse | Trigger/Echo on some modes; UART on ESPHome native component |
| Supply | Normally 5 V | Variant-dependent; commonly 3.3/5 V capable, verify board |
| 5 V signal risk to ESP32 | Yes, ECHO usually needs level shifting | Yes if module/TX is operated at 5 V; verify version |
| Native ESPHome | Yes via ultrasonic platform | Yes via dedicated jsn_sr04t component in supported UART modes |
| Best environment | Dry indoor | Tank / damp / outdoor transducer location |
| Biggest drawback | Not waterproof | Large blind zone |
Which One Should You Use for a Water Tank?
For most permanent tank installations, choose the JSN-SR04T. The remote sealed transducer can be mounted through the tank lid while the electronics stay in a dry enclosure.
Choose the HC-SR04 only when the sensor is completely protected from moisture and the very short 2 cm minimum range is genuinely useful. An exposed HC-SR04 above a humid water tank is cheap, but it is also exactly the kind of installation that works for a few weeks and then starts behaving strangely.
| Situation | Better choice |
|---|---|
| Indoor prototype / bench test | HC-SR04 |
| Covered domestic water tank | JSN-SR04T |
| Outdoor tank | JSN-SR04T |
| Very shallow container with <25 cm air gap | HC-SR04 or another short-range sensor |
| Deep tank up to several metres | JSN-SR04T |
| Wet / condensing environment | JSN-SR04T transducer, with electronics protected |
| Lowest-cost classroom project | HC-SR04 |
How Ultrasonic Tank Measurement Works
Neither sensor directly measures water level. It measures the air gap between the ultrasonic transducer and the water surface.
Sensor at tank top
│
│ measured air gap
│
▼
~~~~~~~~~~~~~~~~~~~ water surface
| |
| water |
| |
|_________________|
If the empty-tank distance and full-tank distance are known, the percentage can be calculated from the measured air gap.
level % =
(empty_distance - measured_distance)
------------------------------------ × 100
(empty_distance - full_distance)
Always calibrate using real measured empty and full positions rather than assuming the tank’s nominal height equals the acoustic measurement span.
HC-SR04: Strengths and Limitations
The HC-SR04 uses separate 40 kHz transmitter and receiver transducers. A short trigger pulse starts a burst of ultrasound; the ECHO output then remains active for a duration proportional to the round-trip sound travel time.
- Very inexpensive.
- Easy to understand and debug.
- Works with ESPHome’s generic ultrasonic sensor platform.
- Short minimum range around 2 cm.
- Widely supported by Arduino and ESP-IDF libraries.
- Good for dry robotics, parking-distance and object-detection projects.
Its main problem for tank monitoring is mechanical: the exposed transducers and PCB are not designed to live above a damp tank.
Humidity, condensation, droplets, corrosion and insects can all turn an apparently stable HC-SR04 installation into an unreliable one.
JSN-SR04T: Why It Suits Tanks Better
The JSN-SR04T separates the sensing head from the control electronics. The ultrasonic transducer is a sealed metal-bodied unit on a cable, so only the transducer needs to sit at the tank opening.
Dry enclosure:
ESP32 + JSN controller board
│
│ transducer cable
│
▼
sealed ultrasonic head
│
▼
water surface
That physical arrangement is much easier to make reliable in a tank installation.
- Sealed remote transducer.
- Longer practical tank range.
- Controller can stay outside the humid space.
- Current ESPHome has a dedicated JSN-SR04T/AJ-SR04M component for serial modes.
- Good fit for cisterns, sumps, rainwater tanks and other non-contact level measurements.
The controller PCB itself is not waterproof. Put it in a proper enclosure even though the transducer is sealed.
The Big JSN-SR04T Problem: 25 cm Blind Zone
The most important number in a water-tank design is often not maximum range. It is minimum range.
Current ESPHome documentation specifies about 25 cm minimum distance for its supported JSN-SR04T/AJ-SR04M setup. If the water can rise closer than that to the transducer, the top part of the tank becomes difficult or impossible to measure reliably.
Sensor
│
│ < 25 cm
│ BLIND / unreliable zone
▼
~~~~~~~~~~~~~~~~ water near full
Sensor
│
│ 35 cm
│ valid measurement
▼
~~~~~~~~~~~~~~~~ water
This means you should mount the sensor high enough that even a physically full tank keeps the water surface outside the blind zone.
For example, if the highest safe water level is only 10 cm below the lid, recessing the JSN transducer directly into that lid is a poor design. A raised sensor neck or another sensing technology may be required.
Maximum Range: The JSN-SR04T Has More Headroom
The classic HC-SR04 is commonly specified for measurements up to about 4 m under favourable conditions. ESPHome’s dedicated JSN-SR04T component documents a 25 cm to 600 cm range.
Real tank range depends on much more than the module’s headline number:
- Tank diameter and wall reflections.
- Water-surface turbulence.
- Foam.
- Condensation.
- Sensor alignment.
- Obstructions such as braces, pipes and ladders.
- Temperature and the speed of sound.
- Whether the transducer is looking straight down at the surface.
HC-SR04 Wiring to ESP32
The HC-SR04 is normally powered from 5 V. Its ECHO output usually rises to approximately the module supply voltage, so it should not be wired directly to an ESP32 GPIO.
ESP32 HC-SR04
5V ----------------------- VCC
GND ---------------------- GND
GPIO17 ------------------- TRIG
HC-SR04 ECHO ---- resistor divider ---- GPIO16
A simple resistor divider can reduce the 5 V ECHO pulse to around 3.3 V. For example, a 10 kΩ resistor from ECHO to the ESP32 input and a 20 kΩ resistor from that input to ground gives approximately 3.3 V.
HC-SR04 ECHO (5 V)
│
10 kΩ
│
├──── ESP32 GPIO
│
20 kΩ
│
GND
ESP32 GPIO is not a normal 5 V-tolerant input. A direct connection may appear to work, but it is outside the intended GPIO voltage range.
HC-SR04 with ESPHome
sensor:
- platform: ultrasonic
trigger_pin: GPIO17
echo_pin: GPIO16
name: "Tank Distance"
id: tank_distance
update_interval: 10s
timeout: 4m
ESPHome’s generic ultrasonic component sends the trigger pulse and measures the ECHO pulse width. The component defaults to a 10 µs trigger and supports a configurable timeout.
JSN-SR04T Versions and Modes Matter
The name JSN-SR04T covers several board revisions and many clone modules. Their mode-selection pads and resistor values are not always identical.
ESPHome’s current dedicated component supports the JSN-SR04T and AJ-SR04M in Mode 1 and Mode 2 serial configurations, with board-specific resistor/pad instructions documented by ESPHome.
That means you should identify the exact board revision before soldering a mode resistor or copying a random diagram from an older blog post.
Current ESPHome JSN-SR04T Setup
ESPHome’s dedicated JSN component communicates over a 9600-baud UART. In controlled mode, ESPHome requests a measurement and reads back the module’s distance frame.
uart:
id: tank_uart
tx_pin: GPIO17
rx_pin: GPIO16
baud_rate: 9600
sensor:
- platform: jsn_sr04t
uart_id: tank_uart
model: jsn_sr04t
name: "Tank Water Distance"
id: tank_distance
update_interval: 10s
For an AJ-SR04M, set model: aj_sr04m and configure the physical board for the corresponding supported mode.
ESPHome currently defaults the update interval to 60 seconds in the on-request mode. For most domestic tanks, a 10–60 second interval is already far more frequent than necessary.
JSN-SR04T Voltage Levels
Do not assume every waterproof ultrasonic module has 3.3 V-safe logic simply because an ESP32 example exists.
Some current JSN-SR04T/AJ-SR04M hardware can operate from 3.3 V or 5 V, but board revisions differ. If the module is powered at 5 V, its TX/ECHO output may also be at a 5 V logic level.
Verify the exact board and use a divider or level shifter on the module-to-ESP32 signal if required. The ESP32-to-module trigger/TX direction is usually less problematic because 3.3 V is typically recognised as a logic high, but again the module documentation wins over assumptions.
Trigger/Echo JSN Mode vs UART Mode
| Mode style | How it works | ESPHome route |
|---|---|---|
| Trigger/Echo | HC-SR04-style pulse timing | Generic ultrasonic component if the hardware mode matches |
| Continuous UART | Module streams distance frames periodically | Dedicated jsn_sr04t component supports documented serial mode |
| Triggered UART | ESP32 requests a measurement and module replies | Dedicated jsn_sr04t component |
For a new ESPHome tank build, the dedicated UART route is attractive because it avoids measuring microsecond pulse widths in software and explicitly supports the current JSN/AJ module family.
Why Tank Walls Cause Bad Readings
Ultrasound reflects from any suitably hard surface, not just water. In a narrow tank, the emitted acoustic cone can hit walls, reinforcing ribs, pipes or the neck of the tank.
Sensor
/ \
/ \
/ \
tank wall tank wall
\ /
\ /
water surface
A closer wall echo can sometimes dominate the desired reflection from the water. This is why a sensor that works perfectly above an open bucket may produce strange values after being mounted in a narrow plastic tank.
- Mount the sensor vertically.
- Keep it away from fill pipes and internal braces.
- Avoid pointing across a sloped wall.
- Use a straight mounting neck rather than a long narrow acoustic tube unless you have tested it.
- Test the whole operating range before permanently fixing the sensor.
Condensation Is the Real Enemy
A waterproof transducer solves rain and splashes, but it does not make ultrasound immune to condensation.
A film of water or droplets on the transducer face changes how acoustic energy couples into the air. Heavy condensation can produce missing readings or false distances.
- Mount the sensor where droplets are less likely to sit on its face.
- Keep the transducer face horizontal and pointing downward unless the manufacturer says otherwise.
- Avoid cold metal mounting arrangements that encourage condensation.
- Use median filtering to reject occasional outliers, but do not try to filter a sensor that is physically wet all the time.
Temperature Changes the Speed of Sound
Ultrasonic distance is calculated from sound travel time, and the speed of sound changes with air temperature.
For a domestic tank this may only create a small percentage error, but the effect becomes more visible over long distances or large seasonal temperature changes.
If centimetre-level accuracy across several metres matters, add air-temperature compensation or calibrate against the conditions your installation actually sees. If you only need a 10% low-level alarm, the added complexity may not be worthwhile.
Filter the Raw Distance Before Calculating Level
Tank surfaces can ripple, pumps can create turbulence and ultrasound can produce occasional outliers. Apply filtering to the raw distance first, then calculate percentage.
sensor:
- platform: jsn_sr04t
uart_id: tank_uart
name: "Tank Water Distance"
id: tank_distance
update_interval: 10s
filters:
- median:
window_size: 5
send_every: 3
send_first_at: 3
A median filter is particularly useful because one wildly wrong echo is rejected instead of dragging the reported level upward or downward.
Convert Distance to Water Level
Suppose your installation measures 190 cm when the tank is empty and 30 cm at the maximum safe water level.
empty distance = 1.90 m
full distance = 0.30 m
usable span = 1.60 m
sensor:
- platform: template
name: "Tank Level"
unit_of_measurement: "%"
accuracy_decimals: 0
update_interval: 10s
lambda: |-
const float empty_distance = 1.90;
const float full_distance = 0.30;
float d = id(tank_distance).state;
if (isnan(d)) return NAN;
float pct = (empty_distance - d) /
(empty_distance - full_distance) * 100.0;
if (pct < 0) pct = 0;
if (pct > 100) pct = 100;
return pct;
Notice that the 30 cm full-distance value also keeps the JSN-SR04T outside its roughly 25 cm blind zone.
Litres Are Not Always Linear with Water Height
For a vertical rectangular tank or upright cylinder with constant cross-sectional area, litres scale linearly with level percentage.
litres = tank_capacity × level_percent / 100
For a horizontal cylindrical tank, sphere or irregular tank, volume is not linear with water height. Use the correct geometry or a calibration table rather than pretending 50% height always equals 50% capacity.
Do You Need One-Second Updates?
Usually no. A 1,000- or 2,000-litre domestic tank does not need ten measurements per second.
Useful for most tank monitoring:
10–60 second update interval
Usually unnecessary:
100 ms updates sent continuously to Home Assistant
Slower updates reduce pointless database traffic and make temporary surface movement less visible.
HC-SR04 vs JSN-SR04T for Small Tanks
The HC-SR04 can actually be the better geometry fit for a very shallow tank because its minimum range is much shorter.
For example, if the sensor is only 12 cm above the maximum water surface, the JSN-SR04T is inside its blind zone. The HC-SR04 may measure it, provided you can keep the entire sensor dry.
That is the main case where the cheaper sensor has a genuine technical advantage for tank level.
HC-SR04 vs JSN-SR04T for Outdoor Tanks
For an outdoor tank, the JSN-SR04T wins easily because the exposed sensing element is designed to tolerate a much harsher environment.
However, still protect the control PCB, connector joints and ESP32 from rain and condensation. A waterproof transducer does not turn the whole project into an IP-rated device.
Common Problem: Tank Reads Full When It Is Not
- The sensor is seeing the tank neck or an internal brace.
- The fill pipe is in the acoustic beam.
- Condensation is creating a false near echo.
- The water is inside the JSN blind zone.
- The transducer is not pointing vertically.
- The conversion formula uses the wrong empty/full calibration distances.
Common Problem: Distance Suddenly Jumps to Maximum
- No valid echo returned.
- Surface turbulence temporarily scattered the pulse.
- Foam absorbed or scattered sound.
- The target moved beyond the practical range.
- A connector or cable fault interrupted the transducer.
- The module is in a different operating mode than the firmware expects.
Use logs to inspect raw distance before changing filters. A median filter can remove occasional bad samples, but it should not hide persistent hardware or mounting problems.
Common Problem: ESP32 Resets or Behaves Strangely
Check power and logic levels before blaming ESPHome.
- Do not feed a 5 V ECHO/TX signal directly into an ESP32 GPIO.
- Use a stable 5 V supply if the ultrasonic module requires it.
- Share ground when using a non-isolated low-voltage interface.
- Keep long ultrasonic-module cables away from relay and motor wiring.
- Do not use boot-sensitive GPIOs if attached hardware can force the wrong reset state.
When Neither Sensor Is the Right Choice
Ultrasonic sensing is attractive because it is non-contact, but there are installations where a pressure sensor is simply better.
- Heavy condensation all year.
- Steam.
- Persistent foam.
- Narrow irregular tank geometry.
- Internal obstructions.
- Very long distance with a weak acoustic return.
- Measurement through an awkward tank neck.
A hydrostatic pressure sensor at the bottom measures liquid head instead of bouncing sound from the surface. It introduces its own wiring and calibration requirements, but avoids many acoustic problems.
Final Recommendation
For a permanent ESP32 water-tank monitor, the JSN-SR04T is normally the better sensor. The sealed remote transducer and longer documented range make it much more suitable for real tanks than an exposed HC-SR04.
But check the geometry before buying it. You need roughly 25 cm or more between the transducer and the maximum water level for the current ESPHome-supported JSN/AJ setup. If your tank is too shallow for that, the HC-SR04 or another short-range technology may be a better fit.
For either sensor, the quality of the installation matters as much as the module: keep the acoustic path clear, protect electronics from moisture, level-shift any 5 V return signal, filter occasional outliers and calibrate the real empty/full distances.
Related ESP32 Guides
- ESP32 Water Tank Level Monitor with Home Assistant & ESPHome
- ESP32 Sump-Pump and Flood Monitor with Home Assistant
- ESP32 Water Leak Sensor with Home Assistant
- VL53L0X vs VL53L1X: Best Time-of-Flight Sensor for ESP32
Datasheets and External Resources
- ESPHome JSN-SR04T Waterproof Ultrasonic Range Finder — current 25–600 cm range, UART modes, model selection and update behaviour.
- ESPHome Ultrasonic Distance Sensor — HC-SR04-style trigger/echo configuration, pulse time and timeout.
- ESP-IDF HC-SR04 component — ESP32 hardware notes including 5 V ECHO level shifting.
- ESP-IDF AJ-SR04M / JSN-SR04T driver — current mode and voltage-level notes for common waterproof modules.