Water Level - Using Bolts

Hello all, I have been searching around but have struggled to find the answer I am looking for.
I am building a garduino for my spinach plants. The water will pump out of a five gallon bucket and I have bolts installed to designate the dangerous water, low water, and half water levels in the bucket. The dangerous water sits just above the neck on my pump so it will stay submerged. I feed power into the system with a bolt below the dangerous water line. As the water level goes up the different bolts receive current via the water conductivity and then read back to analog pins.

Here is the issue, I get massive amounts of what I call ghost readings. When the water is below any of the bolts (except the one providing power) and the analog pins are receiving no input signal I get all kinds of random readings on the serial monitor. They are usually in the 200-400 range, but if one of the bolts is submerged and passing current the ghost readings from the other pins not receiving a signal move with it. Could any of you possibly be of assistance?

Try a 100K resistor to Gnd so the pins stay low unless there is current flow.

hooked to each of the analog pins?

Yeah, or digital pins with internal pullup resistors.
Have the water grounded, when it touches the bolt it will ground the pin and read as a low.

Connect 0.1 mfd disc cap bet analog pins and ground. That will solve your problem.

I'll give both of these a shot tonight.

a resitor from analog input pin to ground and see if that pulls my floating pin from random to 0 or at least a steady value.

a capacitor in the same setup and see if that pulls off the floating pin voltage and keeps it from being random.

When I set this system up I had no clue about floating values. Learning quite a bit now lol since when water is not in contact with one of the bolts the pin is floating. I am hoping I can pull these floating values down with the grounds you all are suggesting. If this doesn't work would my next step be to pass positive voltage to the pin with a high impedance resistor? In my mind this would give it a numerical of 100-300 or so when the bolts are not submerged and 1023 when they are. Does this make sense or am I just taking crazy pills here?

The water may well end up being grounded via whatever the pipes are connected to. For this reason, feeding +5V to a bolt in the water and looking for the other bolts to go to +5V is a bad idea. Instead, you should connect the bolt below the dangerous water level to ground. For each Arduino input that you connect to another bolt, also connect a pullup resistor between the input and +5V. You may even find that the internal pullup resistors are suitable. Then look for the inputs to be at +5V when the bolts are not covered by water, and near 0V when they are.

oh also, here is my code. Feel free to suggest anything, I am not too sensitive to changes.

//my first sketchy

//water power
const int water_power = 5;

//no water sensor
const int an_no_water = A0;  
const int an_no_water_out = 9; 

//low water sensor
const int an_low_water = A1;
const int an_low_water_out = 8;

//half water sensor
const int an_half_water = A2;
const int an_half_water_out = 7;

//soil sensor
const int an_soil = A3;
const int an_soil_out = 6;



//no water sensor
int no_water = 0;        
int no_water_out = 0;  

//low water sensor
int low_water = 0;
int low_water_out = 0;

//half water sensor
int half_water = 0;
int half_water_out = 0;

//soil sensor
int soil = 0;
int soil_out = 0;

void setup() {
  
  Serial.begin(9600); 
}

void loop() {
  
  digitalWrite(water_power, HIGH);
  
  //SET PINS AS INPUTS
  pinMode(an_no_water, INPUT);
  pinMode(an_low_water, INPUT);
  pinMode(an_half_water, INPUT);
  pinMode(an_soil, INPUT);
  
  
  
  
 
  
  //READ PINS
  no_water = analogRead(an_no_water);
  low_water = analogRead(an_low_water);
  half_water = analogRead(an_half_water);
  soil = analogRead(an_soil);
  
  
  
  if  (no_water < 980) 
{
pinMode(an_no_water_out, OUTPUT);
digitalWrite(an_no_water_out, HIGH);
} 
  if  (low_water < 980) 
{
pinMode(an_low_water_out, OUTPUT);
digitalWrite(an_low_water_out, HIGH);
}
  if  (half_water < 980) 
{
pinMode(an_half_water_out, OUTPUT);  
digitalWrite(an_half_water_out, HIGH);
}
  
  if  (soil < 500 && no_water > 980) 
{
  pinMode(an_soil_out, OUTPUT);
  digitalWrite(an_soil_out, HIGH); //pump on
  delay(1000); //how long to run pump
  digitalWrite(an_soil_out, LOW);  //pump off
  digitalWrite(water_power, LOW); //turn power off to pin
  delay(1000); //how long to wait before reading again
} 
  
else
{
delay(1000);//delay once plants are fully watered before repeat
}

  //print to serial monitor
  Serial.print("sensor no water = " );                       
  Serial.print(no_water);      
  Serial.print("\t output = ");      
  Serial.println(no_water_out);

  Serial.print("sensor low water = " );                       
  Serial.print(low_water);      
  Serial.print("\t output = ");      
  Serial.println(low_water_out);  
 
  Serial.print("sensor half water = " );                       
  Serial.print(half_water);      
  Serial.print("\t output = ");      
  Serial.println(half_water_out);
 
  Serial.print("sensor soil = " );                       
  Serial.print(soil);      
  Serial.print("\t output = ");      
  Serial.println(soil_out); 

 
                      
}

Those bolts are going to corrode, even more quickly with current flowing through them.

How about a float with a magnet in it, and reed switches at the levels of interest? Or a capacitive water reading? No metal in contact with the water.

If the bolts are stainless steel ones, then I don't think they will corrode very quickly. The current through them will be tiny, so the contribution from electrolysis will be small. However, there are a couple of better solutions:

  1. Capacitive sensing of the water level. I did this once, for the details see Water level sensor w/ nichrome wire no, now capacitive - #17 by dc42 - Project Guidance - Arduino Forum and the earlier posts in that thread.

  2. eTape may be a good option, if the water depth is suitable. See Liquid Level Sensor - 8" - SEN-10221 - SparkFun Electronics.

they are all stainless, and I think my code has them only on for a brief period of time to check water levels. If that is not the case let me know. I do like the wire loop idea, not a bad thought with it shorting out each loop as it rises.

I use a Parallax Ping style (actually a cheap clone) ultrasonic distance sensor to measure the distance from above, down to the water surface. I get results accurate to about +/- 3cm. Helps to have the ultrasonic sensor looking down a pipe stuck into the container as there is then a very clean echo and no outside noise or multipathing.

Pre-microcontroller, I've built a lot of capacitance meters, liquid level sensors, body sensors, etc. using a couple of 555 timers as a capacitance sensor.

Regarding the date, this wasn't the first time I built this, just the oldest schematic I have saved. I've been building this particular circuit in variations since the mid-70s.

Neither wire has to be in electrical contact with the water. I never let a cut end sit underwater. Instead, both the ground and the sensor wire go down and back out of the water, so both ends of each wire are out of the liquid.

For short tanks, I will coil the wire around a couple of plastic rods. The wire does NOT have to be wrapped around the same rod, but they should be relatively close to each other. The left 555 is just a clock firing off very short OFF pulses. The right 555 is wired as a monostable. So a single clock 555 can fire off to a host of monostable 555s. With an Arduino, I'd just measure the ON pulse width, then subtract the measurement when the tank is empty. Just pick off the pulse from pin 3 of the right 555, and forget all the resistors and caps after it.

No DC current flows, and the AC flow in the water is integrated to equal current both ways by the capacitance of the insulation to the water.

As dc42 points out in the other thread, you do need to have temperature compensation if the fluid is going to change temperature by more than a few degrees. A silicon diode sealed in epoxy works fine for that.

Oh, yeah.... you could use the Arduino to supply the clock pulses. Heck, you could just use the capacitive sensor library for this. But you do need a very high value resistor.

Try it a little simpler to start, see if you can sense wet bolts that are shorted to Gnd:

//my first sketchy - revised by Crossroads

//water power
const int water_power = 5;

//no water sensor
const int an_no_water = 14;  
const int an_no_water_out = 9; 

//low water sensor
const int an_low_water = 15;
const int an_low_water_out = 8;

//half water sensor
const int an_half_water = 16;
const int an_half_water_out = 7;

//soil sensor
const int an_soil = 17;
const int an_soil_out = 6;

//no water sensor
int no_water = 0;        
int no_water_out = 0;  

//low water sensor
int low_water = 0;
int low_water_out = 0;

//half water sensor
int half_water = 0;
int half_water_out = 0;

//soil sensor
int soil = 0;
int soil_out = 0;

void setup() {

  //SET PINS AS INPUTS with pullup resistors
  pinMode(an_no_water, INPUT_PULLUP);
  pinMode(an_low_water, INPUT_PULLUP);
  pinMode(an_half_water, INPUT_PULLUP);
  pinMode(an_soil, INPUT_PULLUP);

  pinMode(an_no_water_out, OUTPUT);
  pinMode(an_low_water_out, OUTPUT);  
  pinMode(an_half_water_out, OUTPUT);
  pinMode(an_soil_out, OUTPUT);
  pinMode (water_power, OUTPUT);

  Serial.begin(9600); 
}

void loop() {

  digitalWrite(water_power, HIGH);

  //READ PINS
  no_water = digitalRead(an_no_water);
  low_water = digitalRead(an_low_water);
  half_water = digitalRead(an_half_water);
  soil = digitalRead(an_soil);

  //print to serial monitor
  Serial.print("sensor no water = " );                       
  Serial.print(no_water);      
  //Serial.print("\t output = ");      
  //Serial.println(no_water_out);

  Serial.print("sensor low water = " );                       
  Serial.print(low_water);      
  //Serial.print("\t output = ");      
  //Serial.println(low_water_out);  

  Serial.print("sensor half water = " );                       
  Serial.print(half_water);      
  //Serial.print("\t output = ");      
  //Serial.println(half_water_out);

  Serial.print("sensor soil = " );                       
  Serial.print(soil);      
  //Serial.print("\t output = ");      
  //Serial.println(soil_out); 

}

Crevice corrosion

Crevice corrosion is a localised form of attack which is initiated by the extremely low availability of oxygen in a crevice. It is only likely to be a problem in stagnant solutions where a build-up of chlorides can occur. The severity of crevice corrosion is very dependent on the geometry of the crevice; the narrower (around 25 micro-metres) and deeper the crevice, the more severe the corrosion. Crevices typically occur between nuts and washers or around the thread of a screw or the shank of a bolt. Crevices can also occur in welds which fail to penetrate and under deposits on the steel surface.

http://www.bssa.org.uk/topics.php?article=95

Everyone,

Seriously thanks so much for all the help, pretty awesome how involved this forum is! I got the bolts working with pull down resistors last night, and it works great.

Going forward I am going to learn how to attach an LCD, a potentiometer to adjust soil saturation, and then work on getting it emailing/tweeting me, and a web interface. I am doing all of this for this project because I would like to eventually build myself a smart thermostat and it seems all the pieces would be there if I grew this project to that scale.

Looks like going forward I have another improvement to add to the list, get those bolts out of there and build a different water level sensor. With all the suggestions you have provided that should be a pretty fun task.

thanks again