How do you know you can't do something if you haven't tried

Valve Hardware

The water valve system utilizes a valve unit from AliExpress, controlled by a pair of relays and an ESP32 microcontroller on a custom PCB. These units communicate via WiFi broadcast messages, automatically connecting sensors with the valve. Each sensor pushes its status to the valve every 30 seconds. Notable features include:

  1. MQTT control, valve can be open/closed/locked open/locked closed by sending it MQTT messages via a broker.
  2. MQTT status updates for valve position, sensors missing, button presses, sensor status, and connection issues
  3. Configurable open/close durations (not all valves close in 10 seconds)
  4. Easy Wifi setup, unit powers up in a wifi station mode with a randomly generated password for each device, this password is output via serial when the device is first powered on and printed on a sticker on each device.
  5. Dynamic or static IP configuration, once again setup during the initial process, or can be modified from the web UI
  6. Stored log events, the device stores a log of the last 20 events in memory along with their timestamps, this includes, errors, warnings and status updates for valve operations.
  7. Manual and web-based valve control, buttons on the physical device, manual pin for controlling without power as well as web based and MQTT control for controlling the device remotely.
  8. Ability to lock the valve even if sensors are triggering. Once a problem has been resolved the water sensors can take time to dry out. The web interface provides controls for locking a valve in an open state regardless of sensor values
  9. Support for multiple valves on one network, currently an unlimited number of valves are supported with 25 water sensors per valve, each sensor module can support up to 10 sensor channels, each channel can have a maximum of 18 feet of water sensing wire.
  10. Web-based firmware updater for both the valves as well as the sensors. Valves have the ability to push firmware automatically to each sensor during the registration process.
  11. Supports user/password login with token-based authentication. Unfortunately still using HTTP, HTTPs is not supported at this time.
  12. Sensor whitelists to provide notifications when sensors are missing for more then a configurable number of seconds
  13. Single web interface that allows access to all individual sensors and their settings using token-based authentication between devices

Potential future features include:

  1. Fallback to WiFi station mode for the valve and sensors if WiFi is not configured, with valves automatically finding sensors and creating a mesh network
  2. Fallback to Bluetooth connectivity option, potentially using Bluetooth LR
  3. Optimization of power usage, enabling sensors to go to sleep while monitoring analog pins in a low-power state, allowing for extended battery life of a year or more on a single battery.
  4. Support HTTPs with LetsEncrypt keys.
  5. Support for additional valve types, currently this system supports latching valves but it could be modified to use spring loaded valves that require constant power to remain open or closed.

The Valve

The water valve itself is a simple unit from AliExpress. The valve moves 1/4 turn then hits a limit switch and stops, reversing the polarity causes it to rotate 1/4 turn back where it hits a second limit switch. When unpowered the unit stays at its current location. This valve has an enormous amount of torque and I cannot hold the motor to the point of stalling using my own strength.

The Circuit

The foundation of the valve circuit is straightforward, employing a pair of relays optically isolated from the ESP32 to manage the solenoid output terminals' polarity. Through coordinated programming, two ESP pins are synchronously switched to safeguard against relay burnout from potential short circuits. Operating within a voltage range of 5 to 24 volts, the circuit efficiently steps down power for electronic components while supplying a direct voltage feed to the solenoid output. Relay activation adheres to the time interval set in the web-based configuration, typically defaulting to 10 seconds per operation, although personal experimentation has revealed 15 seconds as optimal under load conditions. Manual open/close buttons, directly interfaced with the ESP32, offer versatility through software-defined functionalities. Additionally, two buttons facilitate manual board booting into firmware recovery mode. Firmware loading is facilitated via a TTL adapter connected to the board's dedicated header. Remaining circuitry includes power filtering mechanisms to ensure a stable, clean 3.3-volt power supply for the ESP32.

The Case

The case that houses these electronics is a simple 3D printed enclosure that accepts 4 M10x4 screws to mount the board and 4 M10x20 screws to secure the top of the case. The buttons are part of the 3D print and have long legs that push the surface mount buttons on the board. There are 2 versions of this case, one that breaks out the programing buttons and another that does not. The final version of the device is able to update via Wifi, programing buttons are only required to recover from bad firmware and as such are only needed during development.

The Files