Last active
October 28, 2015 18:21
-
-
Save barriault/0ed78a5523da29c6abc5 to your computer and use it in GitHub Desktop.
Dual Flow Meter (see hardware video at: https://youtu.be/110fMAtmgmk)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2014 Jeff Barriault | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software | |
// and associated documentation files (the "Software"), to deal in the Software without restriction, | |
// including without limitation the rights to use, copy, modify, merge, publish, distribute, | |
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in all copies or | |
// substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | |
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | |
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
// | |
// | |
// Interupt driven liquid flow rate sensor | |
// Connect signal (yellow) line to arduino digital pin 2/3. red to vcc and black to gnd. | |
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(12, 11, 7, 6, 5, 4); | |
int ftPin = 2; | |
int gbPin = 3; | |
volatile int pulseCount; | |
float calFactor = 4.8; | |
float convFactor = 3.78541178; // 1 US gallon per minute = 3.78541178 liters per minute | |
float flowRate; | |
unsigned int frac; | |
void increment() | |
{ | |
pulseCount++; | |
} | |
float getFlowRate(int interrupt) | |
{ | |
pulseCount = 0; | |
attachInterrupt(interrupt, increment, RISING); | |
sei(); //Enables interrupts | |
delay (1000); //Wait 1 second | |
cli(); //Disable interrupts | |
detachInterrupt(interrupt); | |
return ((pulseCount / calFactor) / convFactor); // convert to GPM | |
} | |
void setup() | |
{ | |
pinMode(ftPin, INPUT); | |
pinMode(gbPin, INPUT); | |
lcd.begin(16, 2); | |
} | |
void loop () | |
{ | |
flowRate = getFlowRate(0); | |
lcd.setCursor(0, 0); | |
lcd.print("FT: "); | |
lcd.print(int(flowRate), DEC); | |
lcd.print("."); | |
frac = (flowRate - int(flowRate)) * 10; | |
lcd.print(frac, DEC); | |
lcd.print(" GPM "); | |
flowRate = getFlowRate(1); | |
lcd.setCursor(0, 1); | |
lcd.print("GB: "); | |
lcd.print(int(flowRate), DEC); | |
lcd.print("."); | |
frac = (flowRate - int(flowRate)) * 10; | |
lcd.print(frac, DEC); | |
lcd.print(" GPM "); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment