Hi. I am beginner at this with zero programming skills. I am trying to set up a system to monitor garage for water leakage and if there is one to trigger a vacuum cleaner to collect standing water. I wired up an off the shelf sensor (the Watchdog Water Alarm) to trigger the vac through an IoT Relay, as soon as water is present. Now I am trying to add arduino to this to control the system more intelligently. Specifically, a vac needs to run for few seconds longer after water has been collected, and the sensor is off to allow water inside the hose to be fully absorbed into the vac instead of leaking back on the floor after the vac shuts off. What is the best way to code this in arduino? Any suggestions would be great. Thank you
The code is pretty easy. The main task is to connect a suitable relay and water sensor to the Arduino.
The Watchdog Water Alarm creates a sound if my memory serves. You could either take that alarm apart and see if you can find a way to connect to it, or purchase / make a new water sensor.
What would be neat is if the vac body was somewhere it could be drained from the bottom. Installing a one way valve (out) would allow the collected water to drain when the vacuum is off.
Before writing code, you have to decide how the Arduino will turn the vacuum on and off. If you need help on that, post a link to the product page or user manual for the vacuum.
Understood.
This is the sensor I am using to turn the vac on/off:
THE BASEMENT WATCHDOG Model BWD-HWA 110 dB Battery Operated Water Alarm https://a.co/d/hvU9Igl
Inside it there is a buzzer that goes off if there is water present. I disconnected that buzzer and instead used that circuit to power on this IoT relay:
Iot Relay - Enclosed High-Power Power Relay for Arduino, Raspberry Pi, PIC or WiFi, Relay Shield https://a.co/d/fLrjzLJ
The vac is plugged into that relay as well in the 110v circuit, which is always on. There is a low voltage circuit in the same IoT relay that acts as a switch. It gets 3.5 v from the water sensor (that was the buzzer circuit originally), and activates the 110v circuit that switches the vac on. Once water is gone, the sensor no longer supplies 3.5 volts, and the vac turns off. I am adding the arduino in between the sensor and the IoT. 3.5 Volts from sensor will be plugged into A0 of arduino and the ground of the sensor will connect to arduino ground. Then pwm pin 3 will connect to the positive of the IoT relay, while the ground of Arduino will connect to the negative of the IoT. Important to note that the sensor has its own independent 9v power supply (it was a battery, but I rewired it for a 9v Dc power supply.
So, what I am trying to program into arduino is the ability to keep vac running for few moments longer after the sensor stops supplying 3.5v to enable complete emptying out of the hose from water. Otherwise, if the vac stops right away, the remaining water inside the hose leaks out back on the floor.
Sorry for a very long description. Thank you very much again
A very quick answer is for your program to remember that the vac was turned on and continue to remember and keep the vac on for as long as you want it to run. Surely you can code such a situation into your program.
The loop function could look something like this pseudo code
Loop {
Read water detector pin
if (water is detected) {
Turn on pump
}
else { //water is not detected
start time = millis()
while (millis() - start time < pump turnoff delay) {}//wait here
turn off pump
}
}
This will introduce a delay in the loop each time water is not detected. You could eliminate that by using a variable to remember if the pump is on, and only in that case perform the delay.
Perfect! Great starting point to begin tinkering with the program. Thank you very much for all feedback I see here on this subject!
Thank you again for feedback earlier. below is the sketch I came up with thus far. the code Serial.println ("Pump On"); is temporary substitute for sending power to the IoT switch just to make testing the code easier. This sketch kind of does 60% of what i need, which is maintaining power for 7 seconds after the water is not detected anymore and then pauses for 10 seconds, after which the loop resumes turning the Pump ON and the next 7 sec and then pausing again etc. I cannot figure out how to stop the loop after 7 seconds the pump is running and there is no water detected. lets say if after a week (during another storm), the water is detected again, the system needs to "wake up" and run the code again. here is the code i have so far:
#define LOAD_PIN 3
const unsigned long delayedOFF = 7000;
unsigned long startT = 0;
void setup() {
// put your setup code here, to run once:
pinMode (LOAD_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead (A0);
if (sensorValue > 3.2){
Serial.println("PUMP ON");
} else {
startT = millis();
while (millis()- startT < delayedOFF)
Serial.println("PUMP ON");
delay (10000);
}
}
thank you very much again for any suggestions you may have.
There is no need to "stop the loop". The loop function is expected to run all the time, adjusting action to changing input conditions.
This is equivalent to your code, but I've added a line to "stop the pump" and removed the useless delay(10000). The while statement was exactly equivalent to delay(7000).
#define LOAD_PIN 3
const unsigned long delayedOFF = 7000;
unsigned long startT = 0;
void setup() {
// put your setup code here, to run once:
pinMode (LOAD_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead (A0);
if (sensorValue > 3.2) // "3.2" should be an appropriate integer in the range (0 - 1023)
{
Serial.println("PUMP ON"); //turn on pump
}
else
{
delay(delayedOFF);
Serial.println("PUMP OFF"); //turn off pump
}
}
Note that analogRead returns an integer, not a voltage or a floating point number. The integer range depends on which Arduino you have and the chosen analog resolution.
I just wanted to thank you again for your input and feedback. Your recommendations worked very well. Below is the final draft of the code. One of the mistakes I made was using the 8 bit value on AnalogRead instead of a 10 bit. Correcting that and adding the DelayOff function did the trick. Thank you very much once again!
#define LOAD_PIN 3
const unsigned long delayedOFF = 7000;
unsigned long startT = 0;
void setup() {
// put your setup code here, to run once:
pinMode (LOAD_PIN, OUTPUT);
}
void loop() {
int sensorValue = analogRead (A0);
if (sensorValue > 700){
analogWrite (LOAD_PIN,178);
} else {
delay(delayedOFF);
analogWrite (LOAD_PIN,0);
}
}