Adjustable Water Flow Meter

Hi, Am new to the site, but have been referencing for quite sometime.
I am building a water flow meter with a built in solenoid to control the amount of water that goes into something.
I want 3 buttons, 1 down, 1 up and one select/run button, i have written code to add increments of 10 with the up and down buttons and also once the select button is pressed to go into running the solenoid, waterflow meter. when it gets to the set flow the solenoid will shut off and the program will start again

i cant find the problem with my code, i may have put statements too early maybe? but it just keeps going through the loops without any input

any help would be awesome\

#include <Wire.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);

volatile byte pulseCount;

unsigned int flowMilliLitres;
unsigned long totalMilliLitres;
unsigned long oldTime;
const int selectButton = 5;
const int downButton = 6;
const int upButton = 7;
const int powerLed = 8;
const int offLed = 9;
const int onLed = 10;
const int sensorInterrupt = 0;
const int sensorPin = 2;
int buttonState = 0;
int totalflow = 0;
int litres = 0;
float calibrationFactor = 4.5;
float flowRate;
int upState = 0;
int downState = 0;
int selectState = 0;
void setup()
{
Serial.begin(38400);
lcd.begin(16, 2);
pinMode(selectButton, INPUT);
pinMode(upButton, INPUT);
pinMode(downButton, INPUT);
pinMode(offLed, OUTPUT);
pinMode(onLed, OUTPUT);
pinMode(powerLed, OUTPUT);
digitalWrite(powerLed, HIGH);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);

pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
oldTime = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}

void loop()
{
if((millis() - oldTime) > 1000)
{
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flowMilliLitres = (flowRate / 60) * 1000;
totalMilliLitres += flowMilliLitres;
unsigned int frac;
upState = digitalRead(upButton);
downState = digitalRead(downButton);
selectState = digitalRead(selectButton);

lcd.setCursor(0, 0);
lcd.print(“Set Flow Amount:”);
lcd.setCursor(0, 2);
lcd.print(totalflow);
}
if (upState == HIGH);
{
totalflow= litres += 10;
}
if (downState == HIGH);
{
totalflow= litres -= 10;
}
if(selectState == HIGH);
{
while (totalMilliLitres!=totalflow)
{

lcd.setCursor(0, 0);
lcd.print(“Setpoint:”);
lcd.print(totalflow);
Serial.print(“Setpoint:”);
Serial.print(totalflow);
lcd.setCursor(0, 2);
lcd.print(“Flow:”);
lcd.print(totalMilliLitres);
Serial.print(“Flow:”);
Serial.print(totalMilliLitres);
digitalWrite(offLed, HIGH);
}
if (totalMilliLitres==totalflow)
{
digitalWrite(offLed, LOW);
digitalWrite(onLed, HIGH);
Serial.print(“Done”);
lcd.print(“Done”);
delay(3000);

}
}

// 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);

}

void pulseCounter()
{
// Increment the pulse counter
pulseCount++;
}

FlowMeter1.ino (2.82 KB)

You appear to have a 3 sec delay in a 1 sec timed loop.

You are using serial prints inside the operation, which I understand is a bad idea. Check Nick Gammon's notes on serial.

You will win more friends if you check the instructions at the top of the forum and insert your code in the proper manner

Why are you reading the pin states only when it is time to calculate the flow rate?