Water Sensor Issue

Water gets into my house in major rainfall events so some time ago I built a simple water sensor that turns a wets vacuum on and off on a time schedule. The idea is that when it turns off the water gets emptied automatically out the back door, long story. In the most recent event, the rain was so intense that the time schedule couldn't keep up and it wasn’t possible for me to change it on the fly while dealing with the water.

I thought I would add a selection switch to the sensor so I can select from 3 schedules. The code still needs some work (I'm code challenged!). I tried setting the code up so the 3 analogue pins are read to see which one has a high reading and then that would be the schedule selected, what I didn't realise is, if the actual sensor isn't connected to a pin it returns a high reading anyway which defeats my idea. Does anyone know how to overcome this issue, should I connect the analogue pins that aren’t select to ground?
I have attached the sensor layout and the code. Also, the power (override) button only works when the sensor is not activated, any help with that would be good also but not essentia. :slight_smile:

#define buttonPin 3     // the number of the pushbutton pin
#define Relay2    4     // the number of the LED pin
#define sensorPinA5  A5 // 30Sec ON - 3Min OFF = Selector Pin 1
// #define sensorPinA6  A6 // 30Sec ON - 2Min OFF = Selector Pin 2
// #define sensorPinA7  A7 // 30Sec ON - 1.5Min OFF = Selector Pin 3


int sensorValue1;
// int sensorValue2;
// int sensorValue3;

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

void setup() {

  Serial.begin(9600); // set up serial port for 9600 baud (speed)

  pinMode(Relay2, OUTPUT);
  digitalWrite (Relay2, HIGH);

  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH);  // Enable pull-up resistor

  digitalWrite(sensorPinA5, LOW); //Analog
  pinMode(sensorPinA5, INPUT); //Analog

  // pinMode(A6, INPUT); //Analog
  // pinMode(A7, INPUT); //Analog
}

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

void loop() {


  if (digitalRead(buttonPin) == LOW)

  {
    digitalWrite (Relay2, LOW);
      }
  else if (digitalRead(buttonPin) == HIGH)
  {
       digitalWrite (Relay2, HIGH);
  }

  ///////////////////////////////////////////////////////////////////////////////////////

  sensorValue1 = analogRead(sensorPinA5);
  Serial.print("Value1");
  Serial.print("\t");
  Serial.print(sensorValue1);
  Serial.println();

  if (sensorValue1 >= 350) { // Switch Position 1

    digitalWrite (Relay2, LOW);

    //delay (30000);
    delay (2000);

    digitalWrite (Relay2, HIGH);

    // delay (120000);
    delay (5000);

  }

  /* sensorValue2 = analogRead(sensorPinA6); // Switch Position 2
    Serial.print("Value2");
    Serial.print("\t");
    Serial.print(sensorValue2);
    Serial.println();

    if (sensorValue2 >= 400) {

    digitalWrite (Relay2, LOW);

    delay (2000);

    digitalWrite (Relay2, HIGH);

    delay (4000);
    }

    sensorValue3 = analogRead(sensorPinA7); // Switch Position 3
    Serial.print("Value3");
    Serial.print("\t");
    Serial.print(sensorValue3);
    Serial.println();
    Serial.println();
      delay(2000);

    if (sensorValue3 >= 400) {

    digitalWrite (Relay2, LOW);

    delay (1000);

    digitalWrite (Relay2, HIGH);

    delay (2000);
    }  */

}

It doesn't matter which position the switch is in, the same signal is going to the inputs. The switch should be on the inputs of the Nano and select a different time cycle for different rain rates.
What keeps the water in the vacuum while it is running? How long does it take the vacuum to empty if it is full?
Looks to me like you need a float switch in the vac to indicate full and dump it

I know you, OP, posted about an issue with the program but I noticed that there are many delays in the code. A delay is a NOP. That means that when the delay of 4000mS is happening nothing else is happening. No button presses are being detected, no code is being ran, and things can be missed during a delay.

Your program a prime candidate for [ using millis()/url and doing several things at the same time[/url]

If those models were applied to your program you'd realize a performance increase and the issues you are having will be solved.

Any reason for using the Analog pins to read digital signals?

Post some info on the water sensor.

"It doesn't matter which position the switch is in, the same signal is going to the inputs."
For example, if A5 is selected and the sensor module is dry the reading that is returned to the Serial Monitor is 0, when you wet the sensor the read goes up to 500ish and this rise in reading activates the vac.
The issue is, with no sensor module connected to A6 & A7 the readings that are returned to the serial monitor are also 500ish, which also activates the vac which is a problem. So my question is, is there a way to get the unconnected inputs to return a low value so they are not setting off the vac?

I'm very happy with how the setup works and has done so for years but I would just like to add the schedule selector rather than start over.

Idahowalker:
I know you, OP, posted about an issue with the program but I noticed that there are many delays in the code. A delay is a NOP. That means that when the delay of 4000mS is happening nothing else is happening. No button presses are being detected, no code is being ran, and things can be missed during a delay.

Your program a prime candidate for [using millis()/url and doing several things at the same time[/url]

If those models were applied to your program you'd realize a performance increase and the issues you are having will be solved.

Any reason for using the Analog pins to read digital signals?

Post some info on the water sensor.

Thanks, I'll study up and see if I can improve the program.
The water sensor module is sold as an Analog sensor that (I believe) returns a different value depending on the water level, but in my situation I need the vac to start running the schedule as soon as water is present otherwise more of my parquetry floor will be ruined!

Module Info:

Water sensor brick is designed for water detection, which can be widely used in sensing the rainfall, water level, even the liquate leakage. The brick is mainly comprised of three parts: An Electronic brick connector, a 1 MΩ resistor, and several lines of bare conducting wires.This sensor works by having a series of exposed traces connected to ground and interlaced between the grounded traces are the sens traces. The sensor traces have a weak pull-up resistor of 1 MΩ. The resistor will pull the sensor trace value high until a drop of water shorts the sensor trace to the grounded trace. Believe it or not this circuit will work with the digital I/O pins of your Arduino or you can use it with the analog pins to detect the amount of water induced contact between the grounded and sensor traces. This item can judge the water level through with a series of exposed parallel wires stitch to measure the water droplet/water size.This High Sensitivity Water Sensor can easily change the water size to analog signal, and output analog value can directly be used in the program function, then to achieve the function of water level alarm.This item have low power consumption, and high sensitivity, which are the biggest characteristics of this module.The High Sensitivity Water Sensor can be compatible with Arduino UNO,Arduino mega2560,Arduino ADK etc.
Specifications :

  • Working voltage: 5V.
  • Working Current: <20ma.
  • Interface: Digital.
  • Working Temperature: 10°C~30°C.
  • Weight: 3g.
  • Size: 65mm×20mm×8mm.
  • Arduino compatible.
  • Low power consumption.
  • High sensitivity.
  • Output voltage signal: 0~4.2V.

Pin definition:

  • "S" stand for signal input.
  • "+" stand for power supply.
  • "-" stand for GND.

Applications:

  • Rainfall detecting.
  • Liquid leakage.
  • Tank overflow detector.

Of course the Analog pin will read max volts when you remove the input.

I do not know or understand why you are looking for a High from an Analog sensor when the sensor will give a voltage represented of the measured value. Analog is not High/Low.

The High/Low will come from the reading you take, such as <350 is a low and >= 350 is a high. Then you write code to respond to the matter.

Putting a pulldown resistor to make the signal read low when an analog pin is disconnected will change the math of the circuit.

As you are using multiple Analog signals, inputs and the Uno only has one AD converter with multiplexed inputs. It would be best to take 2 or 3 analog readings discarding the first or first/second reading to allow the residual charge of the previous reading to bleed off.

OR

Ground one analog input. Before taking a reading of a sensor, read the grounded analog channel first. Discard the grounded analog channel. Make your real reading.

Your code has the potential to be asleep for >=20 seconds, issues about responsiveness cannot be addressed with >=20 seconds of sleep time.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.