Water Flow Gauge

I have practical arduino book and was deciding to make the water flow gauge. That is an awesome project that I would like to incorporate into and application I am working on. I need to modify it so I can set to turn a light on at a certain amount (say 10 gallons) or charge a solenoid at another amount to turn the water off..

I don't know where to get started....

I don't know where to get started

Work out a way to transform liquid flow into a quantity measureable with an Arduino.

A shop in Germany http://bit.ly/aQ1rX1 sells flow meters, but I think they are available in any country. There is a nice datasheet http://www.btflowmeter.com/fileadmin/PDF/Flowmeter/97478324-FCH-midi-POM.pdf, There are several issues to think about when buying a flowmeter, min and max flow (liters or gallons per minute) #pulses per liter (0.01 liter) and the size of the hose connectors /nozzles.

You need code to count the pulses, did something very similar for a KWH meter with interrupts, see playground Arduino Playground - EEM12L-32AKWhMonitoring Should get you started.

Rob

thanks for the resopnses...

I guess I was too general.

Here is the project I am building:

Actual book, see chapter 10

this project shows all components to use and the project will meter the water. I would like to build and use this project but in addition I would like to get it to do something like light an LED (or any task for that matter) at a certain set point. For example 10.5 gallons

Once you have built the contraption, you'll need to calibrate it. Let some liquid flow for some period of time. Measure the time and count the pulses. From that you can determine the flow rate.

Then, counting pulses will allow you to determine when a given amount has flowed. When the pulse count reaches the desired value, turn the LED on.

It ain't rocket surgery.

thanks paulS, but the project already does all that and has an LCD display of how much water passed through it.

my question was how to make it turn the LED on. Also how would I input the value? would I have to re-write the code each time?

my question was how to make it turn the LED on.

If you know how much water has passed, it seems trivial to call digitalWrite at the appropriate point, then. Or am I missing something?

Also how would I input the value?

What kind of input mechanism do you have? 3 or 4 pushbuttons and a menu are all that is required. When one button is pushed, call a function to display a menu and read the state of the 3 or 4 buttons in a while loop.

One button increases the setpoint. One button decreases it. One button records the new setpoint and exits the while loop (and the function). The 4th (optional) button would act as a cancel button, exiting the while loop and function, but not changing the setpoint.

PaulS, you are not missing anything, I am an arduino noob and my programming skills are weak.

I happened to find the article (link mentioned above) searching the web to do something like this for a beer brewing application. I need to dial in an amount of water so I don't have to babysit the meter and manually turn it off. I just happened to come across this project which did 90% of what I need, and I am just trying to figure out the missing piece.

your suggestion does make sense, I am just trying to put it together

does anyone have any examples or could point me in the right direction to get this going. I am looking for some real input here, not "just hook this up to that"

Lets turn that around. You post the code you have, and describe what input hardware you have (for controlling the setpoint) and what output hardware you have (for viewing the menu and setpoint), and we can make concrete suggestions.

Until then, it's just hand waving.

that is why I included the links, I am reiterating the project from the links. Anyway, not sure how to incorporate it into what I am trying to do. The idea I had for the input buttons was to add more momentary-action pushbuttons: 2 for the gallon 2 for the tenth & hundreth of a gallon (one for up and one for down)

here is my example "<" would be my pushbuttons

10 . 32
< > < >

Parts Required:

1 Arduino Duemilanove, Arduino Pro, Seeeduino, or equivalent
1 Prototyping shield
1 Flow-rate gauge, such as a ZD1200 OR ZD1202
1 16x2 LCD module, HD44780-compatible
3 1K resistors
1 10R resistor
1 680R resistor
1 LED
2 Momentary-action pushbuttons
Ribbon cable
Three-core cable
Three-way line plug and socket

/**

  • Water Flow Gauge
  • Uses a hall-effect flow sensor to measure the rate of water flow and
  • output it via the serial connection once per second. The hall-effect
  • sensor connects to pin 2 and uses interrupt 0, and an LED on pin 13
  • pulses with each interrupt. Two volume counters and current flow rate
  • are also displayed on a 2-line by 16-character LCD module, and the
  • accumulated totals are stored in non-volatile memory to allow them to
  • continue incrementing after the device is reset or is power-cycled.
  • Two counter-reset buttons are provided to reset the two accumulating
  • counters. This allows one counter to be left accumulating indefinitely
  • as a "total" flow volume, while the other can be reset regularly to
  • provide a counter for specific events such as having a shower, running
  • an irrigation system, or filling a washing machine.
  • Copyright 2009 Jonathan Oxer jon@oxer.com.au
  • Copyright 2009 Hugh Blemings hugh@blemings.org
  • This program is free software: you can redistribute it and/or modify
  • it under the terms of the GNU General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. Licenses - GNU Project - Free Software Foundation
  • www.practicalarduino.com/projects/water-flow-gauge
    123456789abcdef
    1239.4L 8073.4L
    */

#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);

// Specify the pins for the two counter reset buttons and indicator LED
byte resetButtonA = 11;
byte resetButtonB = 12;
byte statusLed = 13;

byte sensorInterrupt = 0; // 0 = pin 2; 1 = pin 3
byte sensorPin = 2;

// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 4.5;

volatile byte pulseCount;

float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitresA;
unsigned long totalMilliLitresB;

unsigned long oldTime;

void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" ");

// Initialize a serial connection for reporting values to the host
Serial.begin(38400);

// Set up the status LED line as an output
pinMode(statusLed, OUTPUT);
digitalWrite(statusLed, HIGH); // We have an active-low LED attached

// Set up the pair of counter reset buttons and activate internal pull-up resistors
pinMode(resetButtonA, INPUT);
digitalWrite(resetButtonA, HIGH);
pinMode(resetButtonB, INPUT);
digitalWrite(resetButtonB, HIGH);

pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);

pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitresA = 0;
totalMilliLitresB = 0;
oldTime = 0;

// The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
// Configured to trigger on a FALLING state change (transition from HIGH
// state to LOW state)
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}

/**

  • Main program loop
    */
    void loop()
    {
    if(digitalRead(resetButtonA) == LOW)
    {
    totalMilliLitresA = 0;
    lcd.setCursor(0, 1);
    lcd.print("0L ");
    }
    if(digitalRead(resetButtonB) == LOW)
    {
    totalMilliLitresB = 0;
    lcd.setCursor(8, 1);
    lcd.print("0L ");
    }

if( (digitalRead(resetButtonA) == LOW) || (digitalRead(resetButtonB) == LOW) )
{
digitalWrite(statusLed, LOW);
} else {
digitalWrite(statusLed, HIGH);
}

if((millis() - oldTime) > 1000) // Only process counters once per second
{
// Disable the interrupt while calculating flow rate and sending the value to
// the host
detachInterrupt(sensorInterrupt);
//lcd.setCursor(15, 0);
//lcd.print("*");

// Because this loop may not complete in exactly 1 second intervals we calculate
// the number of milliseconds that have passed since the last execution and use
// that to scale the output. We also apply the calibrationFactor to scale the output
// based on the number of pulses per second per units of measure (litres/minute in
// this case) coming from the sensor.
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;

// Note the time this processing pass was executed. Note that because we've
// disabled interrupts the millis() function won't actually be incrementing right
// at this point, but it will still return the value it was set to just before
// interrupts went away.
oldTime = millis();

// Divide the flow rate in litres/minute by 60 to determine how many litres have
// passed through the sensor in this 1 second interval, then multiply by 1000 to
// convert to millilitres.
flowMilliLitres = (flowRate / 60) * 1000;

// Add the millilitres passed in this second to the cumulative total
totalMilliLitresA += flowMilliLitres;
totalMilliLitresB += flowMilliLitres;

// During testing it can be useful to output the literal pulse count value so you
// can compare that and the calculated flow rate against the data sheets for the
// flow sensor. Uncomment the following two lines to display the count value.
//Serial.print(pulseCount, DEC);
//Serial.print(" ");

// Write the calculated value to the serial port. Because we want to output a
// floating point value and print() can't handle floats we have to do some trickery
// to output the whole number part, then a decimal point, then the fractional part.
unsigned int frac;

// Print the flow rate for this second in litres / minute
Serial.print(int(flowRate)); // Print the integer part of the variable
Serial.print("."); // Print the decimal point
// Determine the fractional part. The 10 multiplier gives us 1 decimal place.
frac = (flowRate - int(flowRate)) * 10;
Serial.print(frac, DEC) ; // Print the fractional part of the variable

// Print the number of litres flowed in this second
Serial.print(" "); // Output separator
Serial.print(flowMilliLitres);

// Print the cumulative total of litres flowed since starting
Serial.print(" "); // Output separator
Serial.print(totalMilliLitresA);
Serial.print(" "); // Output separator
Serial.println(totalMilliLitresB);

lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("Flow: ");
if(int(flowRate) < 10)
{
lcd.print(" ");
}
lcd.print((int)flowRate); // Print the integer part of the variable
lcd.print('.'); // Print the decimal point
lcd.print(frac, DEC) ; // Print the fractional part of the variable
lcd.print(" L");
lcd.print("/min");

lcd.setCursor(0, 1);
lcd.print(int(totalMilliLitresA / 1000));
lcd.print("L");
lcd.setCursor(8, 1);
lcd.print(int(totalMilliLitresB / 1000));
lcd.print("L");

// Reset the pulse counter so we can start incrementing again
pulseCount = 0;

// Enable the interrupt again now that we've finished sending output
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
}

/**

  • Invoked by interrupt0 once per rotation of the hall-effect sensor. Interrupt
  • handlers should be kept as small as possible so they return quickly.
    */
    void pulseCounter()
    {
    // Increment the pulse counter
    pulseCount++;
    }

You have, in that code, the interrupt handler disabled for a relatively long time. I'm not sure why you need to disable it at all. At least not any longer than require to reset pulseCount to 0. That is a one or two machine instruction operation, completing in 125 nano-seconds at most.

A lot of fluid can flow past the sensor which won't get measured, while you are computing the volume AND updating the LCD AND sending serial data.

As I mentioned in a previous reply, you'll need a way to trigger a function to alter the setpoint. That can be done by reading one of the new push buttons. You are already reading pushbuttons, so there is nothing new there.

The new stuff comes in the function, where you need to display different data, and read the state of two or more buttons. You need up and down buttons, and some "I'm done setting the new setpoint" button. You might want a "Forget it; leave the setpoint alone" button.

Incrementing and decrementing the setpoint by the amount that corresponds to the active state (liters, deciliters, centiliters, milliliters, bushels, whatever) is a matter of using the + or - operators.

Breaking out of the while loop that is reading the button state(s) is a matter of using a break statement.