measure distance to water surface with IR module?

After two years of service my ultrasonic hs sr04 fell apart.

It was part of a project to measure the water level in a tank so I would know when to fill the tank and when to stop the pump filling the tank.

It worked well and I want to keep this project running. However the ultrasonic module is kind of bulky and won't handle condensation for longer than 2 years.

My idea was to replace the ultrasonic with an IR module. Distance to water surface would be between 15 and 20 cm and between 80 and 85 cm. So not so high accuracy needed.

Anybody had experience with measuring distances to water surfaces with IR? Is it doable will the water reflect enough light to read anything?

I'll add a simple drawing of the setup to this post.

Hi,
Other possibility is the waterproof Ultrasonic sensors with same SR04 interface. The electronics module is separate and could be boxed/protected.

On AmaZZON here:

That also looks good.

At the moment have some IR modules laying around so that's why my first thought went to them.

Bringamosa:
That also looks good.

At the moment have some IR modules laying around so that's why my first thought went to them.

Solar water heaters work by absorbing the IR. But you could float something on the water and reflect from it.

Paul

Just use a float switch, lots available and easy to use

Paul the opening in the tank is a 20cm round hole. The water surface is 100 by 100 cm. A little 20cm disc will fload all around. except underneath the sensor when trying to measure i bet :wink:

Hammy, I will look into that. Can there be 2 installed?
One would be under water when the tank is not empty...

"Paul the opening in the tank is a 20cm round hole. The water surface is 100 by 100 cm. A little 20cm disc will fload all around. except underneath the sensor when trying to measure i bet :wink:

Hammy, I will look into that. Can there be 2 installed?
One would be under water when the tank is not empty..."

You can do similar to my irrigation tank level sensors using float switches to tell the Arduino Nano to turn on the solenoid valve to fill the tanks, or to turn the valve off.

Trying to get the post modify to show the images, but no success. Sorry.

Paul

That looks like a nice setup there Paul. Do you have a link or maybe a name to those switches? The quick search I did gave me big switches or cheap looking Styrofoam using switches.

However the waterproof ultrasonic is also only 10 bucks, just replace the sensor.

I'll do some more research with the idea's you all gave me

The float switches are from Ebay :Float switches

Paul

If you blow across the mouth of a partly full bottle, the tone it makes is higher the more full the bottle is.

See, spending time in bars can teach something!

What feature of IR and the IR sensor is going to allow you to measure the distance to the liquid. Are you hoping to measure the time delay from transmission to reception ? If so then calculate the range of delay values you are going to be working with.

If you reflect a tight cone off the surface, the return will be wider the farther the surface is away.

Paul_KD7HB:
"Paul the opening in the tank is a 20cm round hole. The water surface is 100 by 100 cm. A little 20cm disc will fload all around. except underneath the sensor when trying to measure i bet :wink:

Hammy, I will look into that. Can there be 2 installed?
One would be under water when the tank is not empty..."

You can do similar to my irrigation tank level sensors using float switches to tell the Arduino Nano to turn on the solenoid valve to fill the tanks, or to turn the valve off.

Trying to get the post modify to show the images, but no success. Sorry.

Paul

Paul do you have some example code of your setup for me to look at? Switches are ordered.

Sure. Simple code that ran flawlessly all last season:

/* Program to control the irrigation system tank filling procedure. Checks the low water and full water switches regularly, and 
 *  turns on the relay which turns on the piloted solenoid valve to allow well water into the storage tanks.
 *  Checked with breadboard on June 26, 2018. Logic seems correct.
 */

 int lowerSwitch = 7;
 int upperSwitch = 8;
 int relayControl = 9;       // This pin controls a SSR that controls the solenoid valve for fill water.

byte lowLevelsw = HIGH;     // switch at bottom of tank. High = magnet hanging down, needs more water
byte highLevelsw = HIGH;    // switch at top of tank. LOW= magnet floating = turn off the fill water
boolean fillingTank = false;  // current relay setting. TRUE if water coming in. FALSE if no water coming in.
boolean almostFull = false;  // Stops the float switch from bouncing open/closed

void setup() {
  //  Serial.begin(9600);
    pinMode (lowerSwitch, INPUT_PULLUP);  // use internal pullup resistors
    pinMode (upperSwitch, INPUT_PULLUP);
    pinMode (relayControl, OUTPUT); 
}

void loop() {
 // get the  conditions of the water level reed switches.
   lowLevelsw = digitalRead(lowerSwitch);
   highLevelsw = digitalRead(upperSwitch);

   if((lowLevelsw == HIGH) & (highLevelsw == HIGH))   // reed switch magnets are both hanging down, tank is empty
   {
    fillingTank = true;   // begin filling 
    almostFull = false;   // but don't cycle off and on
   }

   if((lowLevelsw == LOW) && (highLevelsw == HIGH)&&(almostFull == false))   // bottom magnet is floating, top magnet hanging, keep filling tank
   {
    fillingTank = true;
   }

   if((lowLevelsw == LOW) && (highLevelsw == LOW))    // both magnets are floating, so tank is full
   {
    fillingTank = false;
    almostFull = true;    // stop the float switch from bouncing
   }

   if ((fillingTank == true) && (almostFull == false))     // keep filling the tank
   {
    digitalWrite (relayControl,HIGH);  // SSR is active when LED turns on
   }

   if(fillingTank == false)   // stop filling the tank
   {
    digitalWrite (relayControl,LOW);   // turn SSR off
   }

}

Thank you very much. I love the amount of comments in you posted code this will be very helpful. You rock! :slight_smile:

I do wonder how good an IR mirror that water surface is?

Because with a linear detector, the return from full tank will be much more than low tank by (2 x distance to water) squared.

When shining light on water perpendicularly (which you need to stand a chance of getting back a reflection) it doesn't reflect much if anything. In case of clean water you'll be looking at the bottom of the tank. In case of muddy water you may actually get a reflection thanks to the mud. I'm assuming the OP has clear water in the tank.

When shining at an angle water of course becomes reflective (thanks to the difference in speed of light in the water and in air) but you would not get any reflection back to the source, and the position of the reflection would change with the water level.

Well for now ir became floatswitch