Long wire Water Tank Level Indicator, Floating Values when on Electrical outlet

Hi,

I have been using an Overhead Water Tank Level Indicator and Motor control system based on IC 4049 from last 2 years which was working fine and I thought to have it upgraded to be Controlled by Arduino so that I can enhance the system with some more logics. I did my research for few weeks and finally able to make it with Arduino Nano and Implement the system and it work exactly as I was expected.

Now after 2 weeks of daily use suddenly it just stopped behaving in the way it was made for so after some investigation I found the sensor reading is not stable and started fluctuating from 0 to 1 and vice versa.

Talking about the sensor it just a 5 feet PVC pipe with four steel screws at 4 different levels and one steel screw for +VCC at the bottom and I have managed to seal the PVC pipe in such a way that water cannot enter inside and damage the wire/joints at over the period of time. This might be the best option but I am ok to clean/replace it in few years and it’s cost effective.

The reason it stopped working after 2 weeks is because I was using 2 year old sensor which was with Iron screws and telephone line copper cable wrapped “outside” of PVC pipe which was completely burned out because of corrosion but I am not sure why now it is not working with the new sensor setup with steel screws I have described above. To be more precise here, everything works fine with short cable length of 1 feet or less but not when I connect 30 feet CAT5 cable as sensor values just float around.

I am using Arduino Nano with external 10k Pull-down register at pin 9 to 12 and cat 5 cable of around 30 feet attached with the sensor setup described above. I have just downloaded the Fritzing app to make the schematic but yet to see how to make one, if needed I will make the schematic and attach it.

Here are my findings so far:

  1. SOMETIME new sensor reading are stable with both short cable length and long cable length wire when the system is powered by my laptops 3.0 USB port running on batteries but its start floating when I attach the laptop charger. Same happens when the system is powered by 5 volt smartphone wall charger. Using of less or high ampere charger does not have any effect here.

  2. I have to use both Arduino’s Internal Pull-up and External pull-down register ate same time for each pin to get it work which should not be the case I believe.

  3. Because of the long wire I have tried to change the External pull-down values from 10k to 1k but it just stop reading values form sensor.

My code is too long to post here and also irrelevant to the actual problem so for debugging I am using below simple and short code nowadays and hoping it to work.

After going through all the section of the forum I have chosen this section to post my question , If this is not the correct section of forum please let me know.

Any help will be appreciated.

Thanks
Shantanu

#define forthLevel    9
#define thirdLevel    10
#define secondLevel   11
#define firstLevel    12

void setup() {

  Serial.begin(9600);
  pinMode(firstLevel, INPUT_PULLUP);                                        //PULLUP to avoid floating values when input is low, addition 10 k register is connected between 
  pinMode(secondLevel, INPUT_PULLUP);                                       //each pin and ground
  pinMode(thirdLevel, INPUT_PULLUP);
  pinMode(forthLevel, INPUT_PULLUP);

  digitalWrite(firstLevel, HIGH);
  digitalWrite(secondLevel, HIGH);
  digitalWrite(thirdLevel, HIGH);
  digitalWrite(forthLevel, HIGH);
}

void loop() {

  int firstLevelReading = digitalRead(firstLevel);
  int secondLevelReading = digitalRead(secondLevel);
  int thirdLevelReading = digitalRead(thirdLevel);
  int forthLevelReading = digitalRead(forthLevel);

  Serial.println("--------Status--------"); //reading it via Putty from my laptop.
  Serial.print("firstLevelReading - ");
  Serial.println(firstLevelReading);
  Serial.print("secondLevelReading - ");
  Serial.println(secondLevelReading);
  Serial.print("thirdLevelReading - ");
  Serial.println(thirdLevelReading);
  Serial.print("forthLevelReading - ");
  Serial.println(forthLevelReading);
  Serial.write(27);       // ESC command
  Serial.print("[H");     // cursor to home command

}

You may find that your water supply is earthed (connected to the same ground potential as your computer or Arduino power supply), thus effectively short-circuiting the supply if VCC is immersed in the water. Even if it is not earthed by design, the water in the tank may be at an unpredictable potential with respect to the supply voltage which is almost certainly ground-referenced.

Either situation can fully explain the problem you are encountering.

You could try isolating the tank water from ground (although I suspect that will be difficult or impossible, and may not actually cure the problem, depending on the volume of water).

You could try a fully isolated supply. I think you have done that with batteries and found that worked.

You could design a probe that does not rely on being immersed in the ground referenced water tank. There's many options that would allow that.

Steve

Thank you for your reply Steve,

Yes i can't isolate the water tank completely but i have stimulated it with a small capacity tank laying in a completely different floor and different location but the problem remain same.

When powered by battry sometime it work but not always. Sensor value still float around but not very rapidly but it should not float at all by design.

As i indicated earlier, i have similar setup in past which work for more than 2 year without any complain and now with Arduino its not helping me.

The only alternative and cheap solutions i can think of is reed switch based magnetic floats but reading feedback from other people it sound like it does stuck sometime like 2 times out of 100 attempt or so.
Pressure/capacitance/ultrasonics have there own problem's and frankly i just dont want to go in that direction.

Apart from all these, the cheap diy sensor should work but just have to figure out how to stabilize the floating values.

Okay, understood. Can you provide a schematic of the wiring and connection arrangements? That will help diagnose the problem.

Long lines (I don't know how long your signal line is) can introduce capacitance effects and may be subject to external RF that can affect the signal. We may need to look at how to isolate that. I am using multiple signals into a weather station and these are up to 15 metres in length, but have no interference or irregular readings, so we can fix this. On long lines I tend to use strong pullup or pulldown resistors (4k7) rather than weak ones (10k, 100k). I also in some cases use a latch or buffer to stabilise and reconstruct the signal before delivering it to the microcontroller inputs. Happy to share all that design stuff, but let's isolate the problem you're having.

A schematic will help me understand.

Sorry, missed the point it is 30 feet of CAT5. Can I check you are using a true CAT5 pair (white/whiteBlue) for example? That's important for these signal types.

Dropping the pulldown to 1k will be too much and will affect the input reading range. I'd not go under 4k7.

Thanks for sticking into this Steve

Please note that my final project involve RTC Clock, Rain drop sensor, single channel relay module, buzzer, push switch, IR module, I2C .96 OLED soldered on general purpose PCB with a RJ45 socket for CAT5 connection but after the problem I have dismantled all including the sensor and back to solderless breadboard for troubleshooting and just reading the sensor values via putty with the help of the sketch I have mentioned in my initial post , please see attached "Actual Project.jpg" to get an idea what I want to achieve.

CAT5 is UNSHIELDED twisted pair one, see attached "cat5.jpg"

schematic "Sketch.jpg" is attached which is showing the portion on which I am doing the troubleshooting, it's bare minimum to avoid any clash/interface with other components.

I have attached the reference image "Reference Image for Sensor.jpg" inspired from below blog.
<www(.)makingstuff.info/Projects/Water_Level_Sensor_Part_1>

I have also attached pics from those good days when it was working :slight_smile: at least 2 weeks.

cat5.jpg

Your images do not yet give me an overall picture of the project. None of these is a schematic diagram. A schematic shows the electronic components, power supply and all sensors and connections. I am happy to diagnose from a schematic, but not from separate and incomplete pictures.

Specifically, the picture of the four pairs of Cat5 is typical, so tells me nothing. Which wire pair are you using for what connections?

In your code, have enabled or disabled the inbuilt pull-up resistors? If enabled, then you have 10k pullups and 1k pulldowns on the inputs.

The image of the "actual project" tells me nothing. I need a full schematic, not a picture.

I am keen and happy to help, but there is not enough information.

ok understood, I will make a start to end full schematic then and show you by coming weekend.

somehow I have managed to create full wiring, this is the fist time i am creating such wiring I am not very good in it, if something is not cleat please let me know.

before posting this wiring diagram I have again tested it in breadboard and result are below.

For testing, I submerge +VCC wire in a glass of water then submerge other 4 sensor wires one by one and it shows HIGH values correctly for each pin and values are stable every time, but when i connect the 30 meter long wire in similar way i got HIGH for the 1st level but then it start fluctuating for 2-3 seconds and then freeze at LOW. Putting other 3 sensor wire in glass of water have either dose not show any effect or it just fluctuate form high to low and unstable.

I am not sure if changing the arrangement of CAT5 pairs will have any effect because i have tried different random combination but results were same.

I've a couple of thoughts that I want to prove or disprove before we go any further. Can you please ground (zero volts ) all wires not in use in the CAT5. Preferably ground all unused wires at both ends. Do only that as a first check to see if we are dealing with noise on the cable or something else.

Okay, i will test it in next few days or by weekend.

Although i did checked one thing in past, connected all unused wire to Arduino GND but did not noticed any difference. The only thing i did not check what you suggested is to GND both side of unused wires and i will test this and let you know.

I have seen some very cheap Cat 5 cables from China which have atrocious build quality. The wires weren't even twisted properly, and placed loosely in the sheath. I did not check the wires themselves, but they are probably not made of copper as well. At that length, you might want to consider trying it on a good quality cat5e if all else fails.

Byork makes a good point, have you tested with the same arrangements but with short wire? I mean take the arduino and power supply near the tank and wire a short connecting wire - if that cure sit, then we are looking at something introduced on the long wire.

Hi Byork and steve, thank you for your suggestions
Yes i did check the arrangement with short wire near the tank and it was working ok, issue start when i connect the wire in question.

My cat5 is of a good quality single thread copper wire from DLINK, but its 2-3 year old wire exposed in open atmosphere and i doubt it may have build some sort of resistance or something so today i am going to buy a new cat5 and will test it and will post result.

That's useful info, thanks. CAT5 is not exterior rated so it's sheathing will fail when exposed to weather or sun. In addition, the internal insulation (Polythene) and the make up of the cable (it's tightly twisted but loosely bundled) makes it prone to capillary action which draws moisture along the internal channels. Water and copper are a bad mix, resulting in what's commonly called verdigris, which causes "low insulation" which can be tricky to find - and one usually needs an insulation tester or "megger" (essentially a high voltage test meter).

Low insulation is exactly the kind of thing that can cause the erratic symptoms you are seeing. Cat5 is cheaper, but fails fast. If you can, source an external rated, grease filled cable for a lasting solution.

Out of interest, was the cable out of service for some time before you re-used it?

My reply on this was strangely disappeared after posting so posting again.

My existing old cable was brand new and i had bought it just for my IC 4049 setup i have described initially and it was hanging outside from then only. Said setup was working on 12 volts and i am not sure if that can disturb any property of cat 5 in longer use.

As you suggested i will see the availability and budget before buying one today.

For sure my next test and investigation on Arduino setup will be on brand new cat5.

I also have another suggestion. If short wire works, maybe you can also consider using an ESP8266 instead of Arduino. You can leave one ESP near your tank and connect your sensor wires to it, then send the data over to another ESP, where you can connect your LCD etc. I have personally run an ESP-12 in a waterproof enclosure in a garden for 2 months without issue so far.

I have encountered similar problems as you in the past. My Arduino input readings were unstable, because they experienced signal interference from wires. I have many wires cluttered together, reading many sensors going into the Mega. My sensor network was also growing rapidly. So I decided to once and for all to use ESP8266s to transmit data. For me, it has solved all my data communication issues involving having to lay wires over long distances, cluttering mess, interference and managing the sensor network. I now connect my sensor(s) to ESPs, and use them as client nodes. They then transmit the data to my Raspberry Pi as a central server and database. If my project requires a lot of pins, I will still use an Arduino, then connect an ESP-01 to it via I2C to transmit the data.

Something you can consider for the future perhaps.

Yes Byork, that is a good suggestion on adding one ESP on both end for any similar future project.

Steve, now here is what I got with new cable. instead of cat5 now I have brand new DLINK cat6 30 meter cable but i did not noticed any significant change so the issue is remain same with this new wire in existing setup.

But...it looks like to facilitate things with such long and the issue you both have figured out which is long wire/interference/noise I have to do something with my pull down's because when I change the values of pulldown it started stabling the whole system, not fully stable but bit of progress.

Like you talk about 4.7 k before i tried that but no luck, now at this point I don't know what should be the calculation and if I have to use same value registers for all 4 sensor wire,I have replaced all 10 k with 15 k and things started stabling out.

then i have replaced 15 k with 27 k and it show some more stability. I will keep investigating this with different values but it will be great if you or Byork can guide me if this is the right approach of overcoming the issues you both have already figured out and if yes then how should i got to know what will be the suitable value of registers on long run?

like 4 different values for 4 sensors? because with 27 k, first 3 reading are showing correct every time but when i submerge the last sensor in water, the "first sensor" reading start fluctuating, although this is not a big issue because by logic if the value of next sensor is HIGH then by default it can be consider that the value is previous sensor is also HIGH so by changing the logic of code it will work but this is just a workaround and not a solution i believe.

Thanks
Shantanu

Hi Again,
That was a helpful experiment - good idea. It has given me an idea I want to test here as well so I'll set up a copy of your set up to try out.

I'm keen to have a look but it is holiday time here and i might be a week or two. I am also looking back at the code along with what we now know about the cable and what the change in resisitance is doing. I will contact you as soon as I have a chance to do some more work.
Steve

Hi Shantanu,
I did the numbers and can see why it is variable. The arrangement I used to work with is your 20,000 (20k) pullup resistors (built-in), turned on by code lines 9-13 INPUT_PULLUP, and 27k external pull-down resistors. Water resistivity varies a lot, due to changes in temperature, turbidity, mineral content etc. It will vary with electrical current in the water as well due to the ionisation process introduced by the dc current between the probes.

Let's say the water resistance is somewhere around 18k per 10cm. The circuit (+5 - probe - gnd) is a voltage divider with 20k probe to vcc and 10k8 probe to ground. The 10k8 is the combined parallel resistance of 18k in the water and 27k external pull down. Seen this way, the level probe is at about 1.75 volts above ground and 5v vcc is 3.25 volts above the probe.

Assuming a 10 cm gap, the current in the water will be in the range of 300 microamps. Any change in the water resistance will have an effect on the current, which will drive a change in the voltage seen at the pin, as it is the centre of a voltage divider.

When the AVR reads an input pin, a small but meaningful change in current results, since a small amount of power is consumed to make the reading. Since your current in the water is so small it may be affected by the read current, causing varying readings. In addition, the current in the water is ionising the water and that in itself causes a change in resistance which contributes to instability at the probe.

Thinking about how I would proceed, I would remove the INPUT_PULLUP directive and set the pins as INPUT. I cannot see why your code needs to set the pins HIGH (lines 15 – 18) because it is the same thing as setting the internal pullups on. I would advise we turn them off. To do that remove lines 15 – 18 and change lines 9 – 13 to pinMode(firstLevel, INPUT); would also suggest we use an external pull down value that will give us a bit more current in the water – while this will increase ionisation somewhat, it will also reduce any effect during the microprocessor read cycle. I would try either 10k or 4k7 pull downs. (An alternative approach would be to use the internal pullups and discard the external pull down, then measure from ground to pin rather than vcc to pin – I like that approach better, but it makes no technical difference other than removing the potential introduced because the water is grounded as mentioned in earlier posts).

This way, the only factor affecting the readings is the variance of water resistivity. Since you are only interested in whether the probe is covered or not, then you can interpret the change in pin voltage (which will now be significant) as covered or uncovered.