Level Sensor Height Change conversion to gallons

I am attempting to make a ultrasonic liquid level measurement system for my beer boil kettle and hit a snag. When the kettle reaches a certain height in liquid, a pump will turn off. This is my first arduino project.

I have two Sparkfun 4 character 7 segment LED serial displays. A PING ultrasonic sensor is pointing down into the kettle. The top display (A) shows distance to target. The bottom display (B) shows set point. When the system is turned on, A prompts you to press the tare button. This zeros the distance sensor on the bottom of the kettle. As liquid is added to the kettle the sensor will show an increase in distance, (counts up).

There is an up and down button that are used to control the B display.

When A = B a high signal is output to a separate PLC, which turns off my pumps. There is also a reset command for this.

My problem now is converting distance to gallons. What I would like to do is convert say 2 inches = 0.25 gallons. 4 inches = 0.50 gallons and so forth. I can only think of the brute way of doing this, using 40 IF statements.

if (inches = 2){
gal = 0.24;
}
if (inches = 4){
gal = 0.50;
}

ect.... until 10 gallons. There has to be a nicer way to do this. Any suggestion?

There has to be a nicer way to do this.

Arithmetic

if (inches = 2){

would be if (inches == 2){

Presuming your container has vertical sides, this will be a linear relationship so no need for a big complex if statement, instead how about:

float gallonsValue;  // belongs up in your declarations section 
gallonsValue = inches * 0.125; // where you had that huge IF planned to go

Cheers !
Geoff

AWOL, oops! Thanks.

Geoff: Yes, it can be assumed to be a cylinder. That would be the easy way out. I was attempting to only display the gallons in 1/4 gallon increments though. While the measurement taken by the US will be a large range. I used inches as an example, I actually have the system outputting millimeters. The system will measure 0-199 millimeters, before the system recognizes it as 0.25 gals. Then it would read 200-399mm as 0.25 gallons.

Round it back to the quarter gallon then? Will save you the RSI from all that typing :slight_smile:

I was attempting to only display the gallons in 1/4 gallon increments though

float gallons = measureINches() * 0.125; // or so

gallons = int(gallons *4) / 4.0; // This rounds down to quarter gallons

You might want to consider working with oz quantities and using integer math and only convert to gallons for printing if required. That also might make you math simpler as you might just be able to utilize a simple map() function to convert analogRead() count values to ounces. At least that is how I would approch it.

As liquid is added to the kettle the sensor will show an increase in distance, (counts up).

If the sensor is measuring the distance to the liquid, how does adding liquid INCREASE the distance?

float gallons = measureINches() * 0.125; // or so

gallons = int(gallons *4) / 4.0; // This rounds down to quarter gallons

That sounds like it will work! Let me give it a try.

If the sensor is measuring the distance to the liquid, how does adding liquid INCREASE the distance?

This is a function that is currently working. I added a tare function and afterwards put in a statement that reads
gallons = tare - inches;

how does adding liquid INCREASE the distance?

The more a man drinks the longer it takes to get home ... :slight_smile:

Nice idea,

But are those sensors liquid proof?
Are there any?

Nice idea,

But are those sensors liquid proof?
Are there any?

They are not liquid or humidity proof. They output sound waves so any water proofing would obstruct measurement. Laser is another option.

I'm a mechanical engineer, and I have already built a semi automated brewing system, but have nothing yet to measure the output of the lautering process. With everything else automated, I sometimes forget to turn off the pump when I reach my wort run-off level. Depending on the style of beer the amount of wort run-off I need to collect is different, to set point needs to be easily adjusted (makes capacitive probes difficult). And the area is direct heated by propane which limits sensor (weight, pressure).

I am attempting to use the US for non-contact measurement. This will be mounted in an enclosure above the kettle on a rotating arm. The arduino, and electronics will be housed in the enclosure as well. When lautering is completed, the arm will be rotated out of the way and a cap placed over the US to protect it from steam in the boiling process.

Made huge progress last night. I think the programing in the project is reaching an end!