Decrementing Volume

First off, yes, I'm a "noob". Second, yes, it's for a beer project.

So 95% of the people asking questions here? Make that 96% now!

For some reason I can't seem to find what I'm looking for...variations of such, but not the same.

[u]Scope[/u]: Trying to measure the amount of beer (in Litres) left in my keg. [u]Material[/u]: I'm using an [u]in-line flow sensor[/u], an Arduino Uno R3, and a 2x16 OLED display.

[u]The Idea[/u]: I know a full keg is 19L, therefore as the pulses come from the sensor, it decrements from 20L until it reaches 0. The OLED display would show both a percentage remaining (%) and a "Fuel gauge" style bar reading, therefore visually showing the amount remaining. A reset button would reset the unit to 19L (so 100%) and the bar would return to full.

[u]Extra[/u]: Thinking ahead, should the Arduino unplug/power go out, the unit would reset, therefore it would be nice to either have the information saved, or a dial to manually set the amount remaining.

Some people have weighed their keg etc...but I think the flow sensor provides a lot more potential.

I've tried a simple flow sensor code to familiarize myself, and I can also build the circuits, the more complex coding here is where I'm lost.

Any help would be greatly appreciated...maybe I can mail you some beer in return??

You need to post the datasheet for the sensor or a link to the vendor's website. That is required when asking questions about anything other than an arduino itself.

Right...thank you!

The flow sensor is from Adafruit. Its called the liquid flow meter 1/2" NPS. 5V/450 pulse per liter:

The OLED is also from Adafruit:


@AHewat: I've read your first post three times now, and can't find a question there.

What is it you want, or want to know?

As well as the value of 19000 (ml when full) have another variable with a value of 0 (ml used)

As the flow sensor provides data increment the amount used

Subtract that from the total to get the amount remaining.

I suspect weight would be a much more reliable measure and has the advantage that it can take up where it left off after a reset


As we say in spanish, perhaps this post is "cogérsela con papel de fumar" (I do not know how/dare to translate it): Do you need/want the meter to be food certified?


Hi, AHewat.

Can you please post a copy of your sketch, using code tags? Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

So we can see how far you have come in your project.

Tom.... :)


the more complex coding here is where I'm lost.

What more complex code ?

The dial is just a potentiometer (or rotary encoder with a knob)

The % remaining is simple arithmetic, and the Oled code seems to be no more difficult than LCD code, which is simple.

OLED Library

So what is the problem ? What are you referring to as "complex" ? What is your question ?


The question is: "What modifications to the basic code for a flow sensor should I make to achieve the scope of my project"

The flow sensor code is found here Flow Sensor.

In other words, how can I make the code subtract from a given initial value (19L, 19,000ml etc...) in order to show the remaining amount in my keg, and display it as a bar gauge and percentage rather than in volume capacity.

I maybe didn't make it clear enough that being so new to Arduino (just a handful of days) I don't know the limitations of the coding language, or how to implement what I desire. If I were doing this logically, I would use the following:

X = 19-(Accumulated total in L)

Whereby accumulated total as per the code (I think) is;

// if a plastic sensor use the following calculation // Sensor Frequency (Hz) = 7.5 * Q (Liters/min) // Liters = Q * time elapsed (seconds) / 60 (seconds/minute) // Liters = (Frequency (Pulses/second) / 7.5) * time elapsed (seconds) / 60 // Liters = Pulses / (7.5 * 60) float liters = pulses; liters /= 7.5; liters /= 60.0;

The wiring sketch for this is simple:

As for the OLED (yes I know the're similar), I'm learning lots, but am again still trying to understand the language beyond simple text outputs, I understand it may be obvious arithmetic to many to get a percentage and a level bar to display (and logically it is), but it's the output to code that has me hung up. I can follow the code when its written, but beyond simple changes I'm a a bit lost

VFFGaston - Nice! Thanks

If you're an expert, this clearly might be too mundane for you, I get it. Just looking for beginner help over here...


Where's your code ? Have you got the OLED working ? Did you run the Flow sensor example ? I get that you want us to write your program but we are here to provide help. You have to make an effort to write the code. There's plenty of examples online . You already have example code for the sensor and probably the OLED. So what's your first question ?

I can follow the code when its written, but beyond simple changes I'm a a bit lost

This is clearly not a request for help writing a program . This is obviously a request to have a program written. Start at the beginning and ask questions. All programs are written one line at a time. So what's your question/issue/problem ? We know the sensor and the OLED work and have examples, so where is YOUR code ? (where you try to integrate the two). I hope this isn't a homework assignment that you're trying to outsource

What exactly have you done toward writing the code?

I'm not seeing any effort to learn. .

The sensor is not food safe and will not work (well) with carbonated liquids.

That sensor can only be used under these two conditions: 1. You like your beer super-extra-ultra-foamy. 2. You want to invite montezuma and his revenge to your next keg party.

A scale under the keg would be a better use.

Put full keg on scale. Push button -> copy start weight into eeprom. Query scale for weight. Calculate "19 - (start - current)" value to get the remainin beer in kg. Resulting weight in kg is the same value as the remaining volume in liters for all practival purposes. Output result on Display.

I thought the beer was carbonated after it left the keg.

Anyway, another approach would be something like a water-tank level sensor. One I read about a while ago used a pressure sensor at the top of a tube. The higher the water level the more it compressed the air in the tube.

Have you read Adafruit Kegomatic - The latest from Adafruit's kegerator ?

They're using the same flow meter as the OP. Doesn't that negate the comment that it's not food safe ?

First, no this isn't a homework assignment, but I guess I can understand the arrogance "raschemmel" if this is what kids these days are tricking you into...

The Adafruit Kegomatic is a great project, but made to run with the Raspberry Pi, not an Arduino. But, I do know the flow sensor will work, without foaming my beer or killing my friends. I appreciate the concern, and suggestions to use everything but what I'm actually using.

The flow sensor, Arduino and everything is already up and running, so yes, I have tested all items, modified the code to change the LCD description etc.....Everything has been working for over a week. Just fine

I'm not looking for any help other than for someone to guide me as to how I can take the accumulated total that is calculated in the flow sensor example code attached so that it deducts from a previously said total, instead of accumulating from "0". Not looking for someone to write my project.

The beer offer was a friendly (joking) offer, not payment for work. I'm just looking to tap into someone's knowledge...isn't this how we learn?

I'm not looking for any help other than for someone to guide me as to how I can take the accumulated total that is calculated in the flow sensor example code attached so that it deducts from a previously said total, instead of accumulating from "0".

Well that sounds simple enough. Where are you storing the previous total?

It’s not arrogance .It’s a daily occurance we deal with here on the forum . Post your entire code.

raschemmel: They're using the same flow meter as the OP. Doesn't that negate the comment that it's not food safe ?

I said that because it does not state what plastic is used, it apears it can not be opend to clean it and i have never seem a wheel type flowmeter in a bar installation. They allways used meters with no moving parts, ultrasonic, very expensive.

But i have to admit, i gave it a look and found wheel type flowmeters that seem to be used and sold for beer/postmix lines. But they have a service hatch to open and clean them.

You would not belive how filthy a beer line gets even after a short time. If you have seen the "snot" that comes out of a dirty line you do not want to think about the cultures growing on the wheel of this meter after a month.

So ok, wheel meters are used with cabonated beverages, i will take that back :)

Greetings, Peter

@AHewat, I'm finding it hard to understand where, exactly, the problem is.

You have most of the conceptual thinking for the code figured out in Reply #8. Just write a short Arduino program that does that and see what happens. If it does not compile or it does not do what you want post the code here and we will try to help.

DON'T expect to conceive of the code for the whole project all at once. Nobody writes code that way. Just do it in little pieces.

Have a look at Planning and Implementing a program.


He said in his last post (Reply#14) that he already has a program that has been working fne for over a week now but he doesn't know how to calculate beer remaining.. I don't think you learn by asking other's to do it. I think you learn by trying to do it yourself. He won't post his entire code like I asked . He only posted a " snippet".from an example program. Don't know why he refuses to post his code.