DIY

Emergency valve closing device in case of water leakage

Device for emergency closing of the tap in case of water leakage Many people are familiar with the problem of water leaks and it is especially relevant in multi-storey buildings. It is unpleasant and costly when he flooded not only himself, but also the neighbors below.
The author of this homemade product lives on the second floor and is constantly worried about a possible water leak. For many years, he put a sump under the water heater and a 9V water leakage alarm in it. Such an alarm is simple, cheap, but effective only when someone is at home.
The master tried to make a system that not only detects a leak, but also closes the water supply taps throughout the house.
Based on his experience and his own and industrial solutions, he will try to find the best option.
Let's watch a short video. Note that two ball valves close at once.
Tools and materials:
Option 1:
-Motor gearbox, 12 V, 6 rpm; -Power supply 12 V DC; -Fine line;
-PVC pipe;
-Details printed on a 3D printer;
Option 2:
– Ball valve with electric drive;
-Ac power supply (voltage depending on the model of the electric drive);
General:
-Water leakage sensor;
-Adafruit HUZZAH32 microcontroller; -Relay; Step one: first option
Plumbing in any home most likely already has a manual water shut-off valve. One way to achieve the goal is to use the motor to mechanically drive the crane.
In this case, almost parallel to each other, there are two lines with a crane on one of the pipes. The master fixed a PVC pipe on the handle of the crane. I installed a gear motor on the second pipe. I installed a pulley on the geared motor.
From the pulley to the end of the PVC pipe I pulled a fishing line. When the motor starts running, the pulley starts to spin. The line starts to wind on the pulley and the line pulls the end of the PVC pipe. Thus, the tap closes.
After installation, this motor can be easily controlled using a microcontroller such as ESP32.
To install the gearmotor on a pipe, the master designed and 3D printed a special bracket.
Files for printing can be downloaded below, but you need to take into account that the diameter pipe and motor seat may differ from yours.
Winch design files on GitHubLever design files on GitHubpulley.stlcap.stlbracket.stlhead.stl
Device for emergency closing of the tap in case of water leakage  Emergency valve closing device in case of water leakage Device for emergency closing of the tap in case of water leakage  Emergency valve closing device in case of water leakage Step two: second option
The second option is not entirely successful. The goal was to make such a device that can be closed not only with a gear motor, but also without dismantling it – manually.
Crane emergency closing device in case of water leakage Device for emergency closing of the tap in case of water leakage The most the weak link was plastic. The metal valve stem is installed in a plastic seat. The force when closing the tap is large enough and the edges “licked off” in the rectangular footprint.
Device for emergency closing of the tap in case of water leakage If install a metal washer with a seat under the stem in a plastic bracket, then everything should work as it should.
OpenSCAD design files on githubmount.stlpusher.stl Step three: third option
The third option is to install an industrial-made crane with a motor. For example, one of these cranes. Once installed, this valve can just as easily be controlled by a microcontroller such as the ESP32.
 Device for emergency closing of the tap in case of water leakage Step four: electronics
There are several options to automate the process, but ESP32 has two key advantages:
It has a wireless connection, which allows multiple water leak sensors throughout the house to communicate with the ESP32 that operates the shutoff valve.
A water leak sensor can be directly connected to it.
Adafruit ESP32 Feather boards are a good choice for this build. … These boards can be connected to the relay module, and they can also be powered by battery.
Device for emergency closing of the tap in case of water leakage < a href = "https://usamodelkina.ru/uploads/posts/2021-04/1617626152_1-10.jpg" rel = "prettyPhoto"> Emergency valve closing device in case of water leakage Device for emergency closing of the tap in case of water leakage Step fifth: water leak detection with the ESP32
Detecting water with the ESP32 is very easy. Only two wires are required: one goes to GND and the other goes to one of the TOUCH pins, in this case GPIO # 4/TOUCH0.
For initial testing, the wizard uploaded the following sketch to the board using the Arduino IDE:

 void setup () & # 123; & lt; br & gt; Serial.begin (115200); delay (1000); //give me time to bring up serial monitor Serial.println (& # 34; ESP32 Water Detection Test & # 34;); } void loop () & # 123; Serial.println (touchRead (4)); //get value of Touch 0 pin = GPIO 4 delay (1000); }  

In this sketch, measurements are taken every second and displayed on the serial console.
During testing, the master noticed that if two wires are pulled out of the water, then the values ​​are about 70, and when immersed in water, the values ​​drop to zero.
Device for emergency closing of the tap in case of water leakage < a href = "https://usamodelkina.ru/uploads/posts/2021-04/1617626134_1-13.jpg" rel = "prettyPhoto"> Emergency valve closing device in case of water leakage Step six: control the water shut-off valve
The second half of this project is valve control. Regardless of whether a self-made locking device or an industrial one is used, it is necessary to somehow control the motor.
The master uses the Adafruit Latching FeatherWing mini-relay.
The “SET” contact of the board is connected to GPIO 16, and the “UNSET” contact is connected to Microcontroller GPIO 17.
Then you need to install the code, which can be downloaded below.

 #define SENSOR_PIN 4 //Touch 0 pin = GPIO 4 #define SET_PIN 16 //Relay SET Pin = GPIO 16 #define UNSET_PIN 17 //Relay UNSET Pin = GPIO 17 #define LOW_SENSE_THRESHOLD 10 //Threshold for detecting water #define HIGH_HENSE_THROLD //Threshold for detecting no water bool isOpen; void closeRelay () & # 123; Serial.println (& # 34; Closing relay & # 34;); digitalWrite (SET_PIN, HIGH); delay (20); digitalWrite (SET_PIN, LOW); isOpen = false; } void openRelay () & # 123; Serial.println (& # 34; Opening relay & # 34;); digitalWrite (UNSET_PIN, HIGH); delay (20); digitalWrite (UNSET_PIN, LOW); isOpen = true; } void setup () & # 123; Serial.begin (115200); delay (1000); //give me time to bring up serial monitor Serial.println (& # 34; ESP32 Water Shut-Off Controller & # 34;); pinMode (SET_PIN, OUTPUT); pinMode (UNSET_PIN, OUTPUT); openRelay (); } void loop () & # 123; const int value = touchRead (SENSOR_PIN); if (value & lt; LOW_SENSE_THRESHOLD & amp; & amp; isOpen == true) & # 123; closeRelay (); } if (value & gt; HIGH_SENSE_THRESHOLD & amp; & amp; isOpen == false) & # 123; openRelay (); } delay (1000); //Wait one second}  

There are two functions in the code, “openRelay ()” and “closeRelay ()”, that set or disable the relay. Since a latching relay is used, you just need to pulse the output for 10-20 milliseconds.
There is also an isOpen variable that monitors whether the relay is open or closed.
The device reads the sensor every second and then compares it to two thresholds: LOW_SENSE_THRESHOLD and HIGH_SENSE_THRESHOLD. This function tells whether to close or open the relay. The device only opens a relay if a variable indicates that it is closed, and closes it only if a variable indicates that it is open.
Step Seven: Adding a Wireless Network
A sketch that was created on the previous step, allows you to place one ESP32 next to the water shut-off valve and run a couple of wires somewhere nearby to monitor for leaks.
To expand the capabilities of the device and monitor the condition with leaks throughout the house, the wizard sets up a wireless network.
To do this, you need to slightly change the sketch so that the device connects to a Wi-Fi network and configure wireless communication with the sensors.
The code can be downloaded below.

 #define WIFI_SSID & # 34; enter-your-ssid-here & # 34; #define WIFI_PSK & # 34; enter-your-password-here & # 34; #define SENSOR_PIN 4 //Touch 0 pin = GPIO 4 #define SET_PIN 16 //Relay SET Pin = GPIO 16 #define UNSET_PIN 17 //Relay UNSET Pin = GPIO 17 #define LOW_SENSE_THRESHOLD 10 //Threshold for detecting water #define HIGH_HENSE_THROLD //Threshold for detecting no water #include & lt; WiFi.h & gt; #include & lt; HTTPSServer.hpp & gt; #include & lt; SSLCert.hpp & gt; #include & lt; HTTPRequest.hpp & gt; #include & lt; HTTPResponse.hpp & gt; using namespace httpsserver; HTTPServer server = HTTPServer (); void handleRoot (HTTPRequest * req, HTTPResponse * res); void handleCloseRelay (HTTPRequest * req, HTTPResponse * res); void handleOpenRelay (HTTPRequest * req, HTTPResponse * res); void handle404 (HTTPRequest * req, HTTPResponse * res); bool isOpen; void closeRelay () & # 123; Serial.println (& # 34; Closing relay & # 34;); digitalWrite (SET_PIN, HIGH); delay (20); digitalWrite (SET_PIN, LOW); isOpen = false; } void openRelay () & # 123; Serial.println (& # 34; Opening relay & # 34;); digitalWrite (UNSET_PIN, HIGH); delay (20); digitalWrite (UNSET_PIN, LOW); isOpen = true; } void setup () & # 123; Serial.begin (115200); delay (1000); //give me time to bring up serial monitor Serial.println (& # 34; ESP32 Water Shut-Off Controller & # 34;); pinMode (SET_PIN, OUTPUT); pinMode (UNSET_PIN, OUTPUT); openRelay (); //Connect to Wi-Fi network with SSID and password Serial.println (& # 34; Setting up WiFi & # 34;); WiFi.begin (WIFI_SSID, WIFI_PSK); while (WiFi.status ()! = WL_CONNECTED) & # 123; Serial.print (& # 34;. & # 34;); delay (500); } Serial.print (& # 34; Connected. IP = & # 34;); Serial.println (WiFi.localIP ()); ResourceNode * nodeRoot = new ResourceNode (& # 34;/& # 34 ;, & # 34; GET & # 34 ;, & amp; handleRoot); ResourceNode * nodeOpen = new ResourceNode (& # 34;/open & # 34 ;, & # 34; GET & # 34 ;, & amp; handleOpenRelay); ResourceNode * nodeClose = new ResourceNode (& # 34;/close & # 34 ;, & # 34; GET & # 34 ;, & amp; handleCloseRelay); ResourceNode * node404 = new ResourceNode (& # 34; & # 34 ;, & # 34; GET & # 34 ;, & amp; handle404); server.registerNode (nodeRoot); server.registerNode (nodeOpen); server.registerNode (nodeClose); server.setDefaultNode (node404); Serial.println (& # 34; Starting server ... & # 34;); server.start (); if (server.isRunning ()) & # 123; Serial.println (& # 34; Server ready. & # 34;); }} void loop () & # 123; const int value = touchRead (SENSOR_PIN); if (value & lt; LOW_SENSE_THRESHOLD & amp; & amp; isOpen == true) & # 123; closeRelay (); } if (value & gt; HIGH_SENSE_THRESHOLD & amp; & amp; isOpen == false) & # 123; openRelay (); } server.loop (); } void handleOpenRelay (HTTPRequest * req, HTTPResponse * res) & # 123; openRelay (); handleRoot (req, res); } void handleCloseRelay (HTTPRequest * req, HTTPResponse * res) & # 123; closeRelay (); handleRoot (req, res); } void handleRoot (HTTPRequest * req, HTTPResponse * res) & # 123; res- & gt; setHeader (& # 34; Content-Type & # 34 ;, & # 34; text/html & # 34;); res- & gt; println (& # 34; & lt;! DOCTYPE html & gt; & # 34;); res- & gt; println (& # 34; & lt; html & gt; & # 34;); res- & gt; println (& # 34; & lt; head & gt; & lt; title & gt; ESP32 Water Shut-Off Controller & lt;/title & gt; & lt;/head & gt; & # 34;); res- & gt; println (& # 34; & lt; body & gt; & # 34;); if (isOpen) & # 123; res- & gt; println (& # 34; & lt; h1 & gt; The relay is open & lt;/h1 & gt; & # 34;); } else & # 123; res- & gt; println (& # 34; & lt; h1 & gt; The relay is closed & lt;/h1 & gt; & # 34;); } res- & gt; print (& # 34; & lt; p & gt; Your server is running for & # 34;); res- & gt; print ((int) (millis ()/1000), DEC); res- & gt; println (& # 34; seconds. & lt;/p & gt; & # 34;); res- & gt; println (& # 34; & lt;/body & gt; & # 34;); res- & gt; println (& # 34; & lt;/html & gt; & # 34;); } void handle404 (HTTPRequest * req, HTTPResponse * res) & # 123; req- & gt; discardRequestBody (); res- & gt; setStatusCode (404); res- & gt; setStatusText (& # 34; Not Found & # 34;); res- & gt; setHeader (& # 34; Content-Type & # 34 ;, & # 34; text/html & # 34;); res- & gt; println (& # 34; & lt;! DOCTYPE html & gt; & # 34;); res- & gt; println (& # 34; & lt; html & gt; & # 34;); res- & gt; println (& # 34; & lt; head & gt; & lt; title & gt; Not Found & lt;/title & gt; & lt;/head & gt; & # 34;); res- & gt; println (& # 34; & lt; body & gt; & lt; h1 & gt; 404 Not Found & lt;/h1 & gt; & lt; p & gt; The requested resource was not found on this server. & lt;/p & gt; & lt;/body & gt; & # 34;); res- & gt; println (& # 34; & lt;/html & gt; & # 34;); }  

To work, you need to install the “ESP32 HTTPS Server” library in your Arduino development environment.
Also, in the first two lines of code, you need to set your WIFI data.
Step Eight: Test
Now that the sketch is loaded into the ESP32, you need to open the console, reboot the board and write down the IP address that is registered at startup. In this case, it is 192.168.1.92.
In the web browser, enter “http://192.168.1.92” and go to the relay page.
Next, change the URL to “http://192.168.1.92/close ”, And a web page should open with a message that the valve is closed.
Then we enter “http://192.168.1.92/open”, and open a page informing that the valve is open.
 Emergency valve closing device in case of water leakage Device for emergency closing of the tap in case of water leakage Step ninth: wireless sensors
Remote sensors use the same basic water leak detection code, but instead of triggering a local relay, a request is sent to the microcontroller.

 #define WIFI_SSID & # 34; enter-your-ssid-here & # 34; & lt; br & gt; #define WIFI_PSK & # 34; enter-your-password-here & # 34; #define CONTROLLER_IP & # 34; 192.168.1.92 & # 34; #define SENSOR_PIN 4 //Touch 0 pin = GPIO 4 #define SET_PIN 16 //Relay SET Pin = GPIO 16 #define UNSET_PIN 17 //Relay UNSET Pin = GPIO 17 #define LOW_SENSE_THRESHOLD 10 //Threshold for detecting water #define HIGH_HENSE_THROLD //Threshold for detecting no water #include & lt; WiFi.h & gt; #include & lt; HTTPClient.h & gt; bool isOpen; void sendRequest (char * url) & # 123; HTTPClient http; http.begin (url); int httpCode = http.GET (); if (httpCode & gt; 0) & # 123; Serial.print (& # 34; GET & # 34;); Serial.print (url); Serial.print (& # 34; Status & # 58; & # 34;); Serial.println (httpCode); } else & # 123; Serial.println (& # 34; Error on HTTP request & # 34;); } http.end (); isOpen = false; } void closeRelay () & # 123; sendRequest (& # 34; http & # 58; //& # 34; CONTROLLER_IP & # 34;/close & # 34;); isOpen = true; } void openRelay () & # 123; sendRequest (& # 34; http & # 58; //& # 34; CONTROLLER_IP & # 34;/open & # 34;); isOpen = true; } void setup () & # 123; Serial.begin (115200); delay (1000); //give me time to bring up serial monitor Serial.println (& # 34; ESP32 Water Shut-Off Controller & # 34;); pinMode (SET_PIN, OUTPUT); pinMode (UNSET_PIN, OUTPUT); openRelay (); //Connect to Wi-Fi network with SSID and password Serial.println (& # 34; Setting up WiFi & # 34;); WiFi.begin (WIFI_SSID, WIFI_PSK); while (WiFi.status ()! = WL_CONNECTED) & # 123; Serial.print (& # 34;. & # 34;); delay (500); } Serial.print (& # 34; Connected. IP = & # 34;); Serial.println (WiFi.localIP ()); } void loop () & # 123; const int value = touchRead (SENSOR_PIN); if (value & lt; LOW_SENSE_THRESHOLD & amp; & amp; isOpen == true) & # 123; closeRelay (); } if (value & gt; HIGH_SENSE_THRESHOLD & amp; & amp; isOpen == false) & # 123; openRelay (); }}  

Here you will need to change the first three lines, indicating the network address and password of the wireless network, as well as the IP address of the microcontroller.
To test, you can dip the sensor wires in water and see if whether the relay closes.
Everything is ready. Of course, there are ready-made solutions, for example here, but they are not so cheap to stand. So the choice is yours, make the system yourself, purchase a ready-made solution or make expensive repairs for yourself and your neighbors.
Crane emergency closing device in case of water leakage  Emergency valve closing device in case of water leakage

Source:

usamodelkina.ru

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button