Hi I've got a strange issue on my hands here. I've got two flow meters hooked up to a Arduino MEGA R3 (digital pin 2 and 3) that are tied to two interrupts that monitors flow rate of one or the other meter.
Right now I can run water through the "IN" flow meter, and get a reading back that only the "IN" meter had any flow change.. however if I run water through the "OUT" meter, I get a reading that says both "IN" and "OUT" had a flow change.
I'm not sure why the later flow meter's causing both interrupts to get triggered, but I'm at my wits end on this one
Here is my breadboard schematic:
Here is actual schematic:
Here is my code:
#include <LiquidCrystal.h>
#define FlowPinIn 3
#define FlowPinOut 2
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
float flowInRate, flowOutRate; //float might be over kill, int might be better?
boolean irrigationFlag = false; //Flag used when done flowing to store a value on SD card
volatile unsigned long pulseInFlowCount, pulseOutFlowCount; //our actual pulse counting variables
unsigned long homeMillis; //stored timestamp
void setup()
{
lcd.begin(16, 2); //setup LCD screen
//Setup Flow Sensor Pins
pinMode(FlowPinIn, INPUT); //"IN" flow meter
digitalWrite(FlowPinIn, HIGH);
pinMode(FlowPinOut, INPUT); //"out" flow meter
digitalWrite(FlowPinOut, HIGH);
//flow meters being hooked into flow counter methods using digitalPinToInterrupt as prescribed.
attachInterrupt(digitalPinToInterrupt(FlowPinIn), Fill, FALLING);
attachInterrupt(digitalPinToInterrupt(FlowPinOut), Drain, FALLING);
}
void loop()
{
if ((millis() - homeMillis) >= 1000){
checkFlowRates(); //made into function so it can be used here or inside methods for irrigaiton
}
}
void checkFlowRates(){
//Get our rate of flow for either irrigation directions
flowInRate = (int)((1000.0 / (millis() - homeMillis)) * pulseInFlowCount) / 5.5; //5.5 is flow meter calibration found in specs
flowOutRate = (int)((1000.0 / (millis() - homeMillis)) * pulseOutFlowCount) / 5.5; //5.5 is flow meter calibration found in specs
//do we have a flow rate for in?
if (flowInRate > 0){
lcd.clear(); //for debugging, not production
lcd.print("FLOW IN"); //for debugging, not production
irrigationFlag = true; //flag irrigation is taking place
delay(1000);
}
//do we have a flow rate for out?
if (flowOutRate > 0){
lcd.clear(); //for debugging, not production
lcd.print("FLOW OUT"); //for debugging, not production
irrigationFlag = true; //flag irrigation is taking place
delay(1000);
}
//did we previously have a flow rate, but now it it seems to have stopped?
if (irrigationFlag == true && flowInRate == 0 && flowOutRate == 0){
//store size to SD card once know we are done filling
irrigationFlag = false; //put flag back to false state
}
pulseInFlowCount = pulseOutFlowCount = 0; //reset pulse counts for next time around
}
//flow rate counter for in
void Fill(){
pulseInFlowCount++; //count pulses for "IN" meter
}
//flow rate counter for out
void Drain(){
pulseOutFlowCount++; //count pulses for "OUT" meter
}
Any suggestions would greatly be appreciated.
Also take note that I've separated power sources to the flow meters to ensure that current change on one was not effecting the other.