Kegerator Flow Meter Test

The first step along the road to getting the kegerator monitor up and running

Flow meter used available from adafruit:

Based on the code from:



#define lcdPin 6

SoftwareSerial LCD = SoftwareSerial(0, lcdPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin
const int LCDdelay = 10; // conservative, 2 actually works

// which pin to use for reading the sensor? can use any pin!

// count how many pulses!
volatile uint16_t pulsesLeft = 0;
volatile uint16_t pulsesRight = 0;

volatile uint16_t lastPulses = 0;

// track the state of the pulse pin
volatile uint8_t lastFlowPinStateLeft;
volatile uint8_t lastFlowPinStateRight;

volatile int32_t lastFlowTimer = 0;

float litersPerTank = 18.9;
float pricePerTank = 78;

bool clearNextTick = true;

// Interrupt is called once a millisecond, looks for any pulses from the sensor!
uint8_t left = digitalRead(FLOWSENSORPINLEFT);
uint8_t right = digitalRead(FLOWSENSORPINRIGHT);

if (left != lastFlowPinStateLeft && left == HIGH) {
//low to high transition!

if (right != lastFlowPinStateRight && right == HIGH) {
//low to high transition!

lastFlowPinStateLeft = left;
lastFlowPinStateRight = right;

uint16_t pulses = pulsesLeft = pulsesRight;

if (pulses == lastPulses)
if (lastFlowTimer > -1)
if (lastPulses == 0)
clearNextTick = true;
lastFlowTimer = 0;

lastPulses = pulses;

void useInterrupt(boolean v)
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
else {
// do not call the interrupt function COMPA anymore

void setup()
Serial.print("Flow sensor test!");

lastFlowPinStateLeft = digitalRead(FLOWSENSORPINLEFT);

lastFlowPinStateRight = digitalRead(FLOWSENSORPINRIGHT);


pinMode(lcdPin, OUTPUT);
lcdPosition(0, 0);
LCD.print("Starting Up");

lastFlowTimer = -1;
clearNextTick = true;
pulsesLeft = 0;
pulsesRight = 0;

void loop() // run over and over again
uint16_t pulses = pulsesLeft = pulsesRight;

if (clearNextTick)
clearNextTick = false;

if (pulses == 0)
if (lastPulses > 0)

lcdPosition(0, 4);
lcdPosition(1, 1);
LCD.print("Begin pouring!");
float liters = pulses;
liters /= 7.5;
liters /= 60.0;
liters /= 1.4; //weird const

float ounces = liters * 33.8;

float price = liters / litersPerTank * pricePerTank;

if (pulsesRight > 0)
lcdPosition(1, 0);
LCD.print("Oz: ");
lcdPosition(1, 9);
LCD.print(" $:");

// Reset
if (lastFlowTimer > 1000)
lastFlowTimer = -1;
clearNextTick = true;
pulsesLeft = 0;
pulsesRight = 0;


// wbp: goto with row & column
void lcdPosition(int row, int col) {
LCD.write(0xFE); //command flag
LCD.write((col + row * 64 + 128)); //position
void clearLCD(){
LCD.write(0xFE); //command flag
LCD.write(0x01); //clear command.


8 responses to “Kegerator Flow Meter Test

  1. wow this is awesome! how were you able to get the your data to start and stop based on the amount of flow that’s being measured. I’m also working on a similar project trying to measure gal/min, but when I’m using adafruits code i realized that their loop is continuous regardless when i stop my flow-meter. Also if i’m not using an LCD monitor display how would you do that only using the Arduino Serial Monitor?


    • Hi Darren,
      Your best bet is to take my code, run it, and start modifying it to suit your needs.
      If you wanted to write to the serial monitor instead of the lcd, just replace the ‘LCD.print()’s with ‘Serial.println()’ once your serial port is open (Serial.Begin(speed))

  2. If you wanted to skip the facial and camera parts but have users pick who they are pouring would one just skip those steps?

    100% new at RPi stuff
    Thanks for the time

    • Hi notrubr, if you’re not using the camera or facial recognition, you should be able to skip step 4, you’ll just need to take out the references in the project once you’ve got it loaded up. I’ve not personally tried this though, so let me know if you encounter any issues!

      • Thanks Randy. I have not seen that item before. That is an interesting chip, but I’m not sure it would be worth it for $40, unless you needed much more precise measurement and that can provide it. I have my flowmeters plugged directly into the pi and I get fairly consistent results, but +/- 2oz accuracy per pint. I do use the adafruit flowmeters, no mention of food safe, but others had looked inside and saw no reason it wouldn’t be food safe, so I gambled 🙂 No problems yet!

  3. Very cool project! I haven’t seen any updates for a while and am wondering if you ever got facial recognition to work. I am hoping to take your project and start with it, then add the load cells like you mention. Have you done any updated work for this since your last post?

    • Thanks Max!
      I have not touched the project in quite a while. The facial recognition is bare bones, and not feature complete, but it should be a good starting point for improvements. I do plan on coming back and finishing that, but I have no ETA for when I’d have the time.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s