Hot Water Tank Leak Detector with Automatic Shut-Off Valve
A prototype leak-detection controller that senses water near a hot water tank and closes a valve when a leak is detected.
Intermediate Project
— This is an intermediate prototype because it combines always-on sensing, safe actuator control, and inductive-load/power-fail handling, even though the core logic is simple.
Assumptions:
- The valve is a normally-closed or power-to-open shutoff valve that can be driven by a relay or solenoid output.
- The prototype can be mains-powered or wall-adapter powered; battery backup is optional but desirable for fail-safe behavior.
- Leak detection is based on a simple conductive water sensor placed on the floor or in a drip tray near the tank, not on pressure or flow sensing.
- The system only needs local autonomous operation; no remote app or cloud connectivity was requested.
Bill of Materials
Compatibility Notes
- STM32L431CCU6 runs at 3.3 V logic, so any relay or valve driver input should be compatible with 3.3 V control or use a transistor/driver stage.
- G6B-2114P-US-DC24 is a 24 V coil relay, so the coil supply must be separate from the MCU rail; do not drive it directly from the MCU pin.
- MTCH9010-E/REB and the STM32L431CCU6 are a good voltage match for a 3.3 V system.
- If you use R-78E5.0-0.5 for 5 V generation, you may still need a 3.3 V rail for the MCU and sensor, either from the MCU board or a small LDO.
- If the valve is a DC solenoid rather than a relay-switched valve, the SY21611FHC or AO3400A approach is electrically simpler and more efficient than a mechanical relay.
You'll Also Need
- Valve hardware itself is not included; you still need the actual shutoff valve or solenoid valve matched to your plumbing and supply voltage.
- You will need a proper enclosure, cable glands, terminal blocks, and waterproof sensor mounting hardware.
- Flyback protection, fuse protection, and any required snubber/TVS parts are not listed but are important for inductive loads.
- If using a relay, you may need a transistor driver and base/gate resistors depending on the exact relay module implementation.
- A wall adapter or battery pack is still required; the power block only covers regulation/charging, not the source itself.
Estimated BOM Cost: $25-30 (based on live distributor pricing)
Design Considerations
Fail-Safe Valve Behavior
For a leak shutoff system, the safest architecture is usually fail-closed: loss of power should leave the water supply off rather than open. If you use a relay, choose contacts and wiring so the default state removes power from the valve on MCU reset or brownout. Test the power-fail case explicitly by unplugging the supply and verifying the valve returns to the safe state.
Leak Sensor Placement
A conductive leak sensor only works if water can physically reach it, so placement matters more than the electronics. Put the probe at the lowest likely pooling point near the tank, and consider using two sensors: one near the tank base and one near the floor drain path. That reduces false negatives from water wicking or uneven flooring.
False Trigger Immunity
Hot water tanks can create condensation, drips, and occasional splashes, so firmware should require a sustained wet condition before tripping the valve. A simple approach is to sample every 100-500 ms and require several consecutive wet readings, then latch the fault until manual reset. This avoids nuisance shutoffs from brief droplets while still reacting quickly to real leaks.
Inductive Load Protection
If the valve is a solenoid or the relay coil is driven directly, add flyback suppression and verify the driver can handle the coil current. Inductive kick can reset the MCU or damage the switch device if not handled. Keep the high-current loop short and separate from the sensor wiring to reduce EMI into the leak input.
Power Backup and Brownout Handling
A leak detector is most valuable during outages and brownouts, so consider battery backup or at least a hold-up strategy for the control electronics. The MCU should detect undervoltage and force the valve to the safe state before the rail collapses. If you add MCP73871T-2CAI/ML later, you can keep the controller alive long enough to close the valve cleanly.
Validation and Test Plan
Do not validate only with a wet finger on the sensor; test with real drip rates, standing water, and condensation over several hours. Also test the full chain: sensor trip, MCU response time, driver activation, and valve closure under the actual supply pressure. A good prototype should log or indicate whether the trip came from sensor fault, brownout, or genuine leak detection.
Want to customize this project or build something different?
Try the Project Advisor


