Coding help with flowmeter

I am building a device that is using a flow meter to measure the amount of water coming out of a tap in milliliters. I need some help with the programming of the Arduino Uno as I have no idea if I am doing this right and need to finish this by next week. I am using 7 LEDs to indicate when 100ml has been used (1 LED will light up once 100ml has been used). I need these LEDs to light up and stay lit until the device is reset. I will need to also have a button to reset the device as well. Some help with this project would be much appreciated ! Thank you everyone !

So far I have a program which measures the amount of fluid flowing through a flow meter at a rate of L/hour,but I do not want it to measure rate. I need the program to count the revolutions of the flowmeter, convert them into mililitres, than light up one LED once 100mL has been used. This is the code below.

volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;                               
int hallsensor = 2;    //The pin location of the sensor

void rpm ()     //This is the function that the interupt calls 
{ 
  NbTopsFan++;  //This function measures the rising and falling edge of the 

hall effect sensors signal
} 
// The setup() method runs once, when the sketch starts
void setup() //
{ 
  pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  Serial.begin(9600); //This is the setup function where the serial port is 

initialised,
  attachInterrupt(0, rpm, RISING); //and the interrupt is attached
} 
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop ()    
{
  NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
  sei();            //Enables interrupts
  delay (1000);      //Wait 1 second
  cli();            //Disable interrupts
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate 

in L/hour 
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
}

P.S. This is the Flow meter I am using : http://www.jaycar.com.au/productView.asp?ID=ZD1202

JonT:
I need the program to count the revolutions of the flowmeter, convert them into mililitres, than light up one LED once 100mL has been used.

Looking at Section 5 of the datasheet it would seem easy to get a 1'st order measurement of the ml's flowed since the measurement started.

http://www.jaycar.com.au/products_uploaded/ZD1202.pdf

A nominal flowrate yields a volume of 0.0038 liter (+/-10%) per pulse. So simply counting the pulses and converting that count into liters and then asking a series of if() questions would be a good start. Then you could add in a fudge factor that accounts for the variability of of the constant above vs flow rate, as seen in Section 5. Lastly I guess you could add in a cal factor, if you choose to measure the flow for that particular sensor.

So here’s a start on that. There are more compact and efficient ways to code it but this is simple to understand and modify. I’ve made some assumptions re: logic levels for the LEDs on/off and there are missing pins assignments and constants for you to fill in. Please read the new comments.

//declare the constants used
const int sensorPin = 2;       //The pin location of the sensor
const int led1Pin = ??;         //pin for LED corresponding to volume1
const int led2Pin = ??;         //pin for LED corresponding to volume2
const int led3Pin = ??;         //pin for LED corresponding to volume3
const int led4Pin = ??;         //pin for LED corresponding to volume4
const int led5Pin = ??;         //pin for LED corresponding to volume5
const int led6Pin = ??;         //pin for LED corresponding to volume6
const int led7Pin = ??;         //pin for LED corresponding to volume7

const float Kfactor = 0.0038;    //liters flowed per pulse from sensor

const float vol1 = ??;           //liters flowed when LED1 comes on
const float vol2 = ??;           //liters flowed when LED2 comes on
const float vol3 = ??;           //liters flowed when LED3 comes on
const float vol4 = ??;           //liters flowed when LED4 comes on
const float vol5 = ??;           //liters flowed when LED5 comes on
const float vol6 = ??;           //liters flowed when LED6 comes on
const float vol7 = ??;           //liters flowed when LED7 comes on
const unsigned long updateTime = 1000; //time btw printed updates, msec

//declare the variables used
volatile unsigned int NbTopsFan = 0; //variable to accumulate the number of pulses
float volFlowed = 0;         //the volume flowed since measurement started, liters                       

void countPulses()       //This is the function that the interupt calls
{
  NbTopsFan++;    //This function counts the number of rising edges from the sensor
}

// The setup() method runs once, when the sketch starts
void setup() //
{
  //initializes digital pin 2 as an input w/pullup resistor enabled
  //since the output of the sensor is an open collector
  pinMode(sensorPin, INPUT_PULLUP);
  //declare the LED pins as outputs
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(led3Pin, OUTPUT);
  pinMode(led4Pin, OUTPUT);
  pinMode(led5Pin, OUTPUT);
  pinMode(led6Pin, OUTPUT);
  pinMode(led7Pin, OUTPUT);
  //turn LEDs off
  digitalWrite(led1Pin, LOW);
  digitalWrite(led2Pin, LOW);
  digitalWrite(led3Pin, LOW);
  digitalWrite(led4Pin, LOW);
  digitalWrite(led5Pin, LOW);
  digitalWrite(led6Pin, LOW);
  digitalWrite(led7Pin, LOW);
  //set the serial port to 9600 baud
  Serial.begin(9600);
  //and the interrupt is attached to pin2
  attachInterrupt(0, countPulses, RISING);
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop ()   
{
  volFlowed = float(NbTopsFan) * Kfactor; //# pulses * vol per pulse = total vol flowed
  Serial.print(volFlowed);                //Prints the number calculated above
  Serial.println(" liters");
  if(volFlowed >= vol1){
    //turn on LED1 for volume1
    digitalWrite(led1Pin, HIGH);
  }
  if(volFlowed >= vol2){
    //turn on LED2 for volume1
    digitalWrite(led2Pin, HIGH);
  }
  if(volFlowed >= vol3){
    //turn on LED3 for volume1
    digitalWrite(led3Pin, HIGH);
  }
  if(volFlowed >= vol4){
    //turn on LED4 for volume1
    digitalWrite(led4Pin, HIGH);
  }
  if(volFlowed >= vol5){
    //turn on LED5 for volume1
    digitalWrite(led5Pin, HIGH);
  }
  if(volFlowed >= vol6){
    //turn on LED6 for volume1
    digitalWrite(led6Pin, HIGH);
  }
  if(volFlowed >= vol7){
    //turn on LED7 for volume1
    digitalWrite(led7Pin, HIGH);
  }
  delay(updateTime);                      //time, msecs, btw updates
}

Senior School technology project: http://forum.arduino.cc/index.php?topic=228690.0

Be sure to cite your sources!

Mee_n_Mac:

JonT:
I need the program to count the revolutions of the flowmeter, convert them into mililitres, than light up one LED once 100mL has been used.

Looking at Section 5 of the datasheet it would seem easy to get a 1'st order measurement of the ml's flowed since the measurement started.

http://www.jaycar.com.au/products_uploaded/ZD1202.pdf

A nominal flowrate yields a volume of 0.0038 liter (+/-10%) per pulse. So simply counting the pulses and converting that count into liters and then asking a series of if() questions would be a good start. Then you could add in a fudge factor that accounts for the variability of of the constant above vs flow rate, as seen in Section 5. Lastly I guess you could add in a cal factor, if you choose to measure the flow for that particular sensor.

So here’s a start on that. There are more compact and efficient ways to code it but this is simple to understand and modify. I’ve made some assumptions re: logic levels for the LEDs on/off and there are missing pins assignments and constants for you to fill in. Please read the new comments.

I actualy understand what you have written there!. The coding language seems to be similar to python for me. Thankyou very much ! You are a true legend ! . Could you explain more about what the fudge factor is please ?

JonT:
Could you explain more about what the fudge factor is please ?

I'd have thought that to be obvious, my explanation above was pretty clear. Did you look at Section 5 ?

BTW if this is for some engineering credit, I’m afraid you’ll get poor marks for matching system requirements to piece parts specs, if I’ve understood your 100 ml req. How accurately must you know that you’ve dispatched 100 ml ?

Mee_n_Mac:

JonT:
Could you explain more about what the fudge factor is please ?

I'd have thought that to be obvious, my explanation above was pretty clear. Did you look at Section 5 ?

BTW if this is for some engineering credit, I’m afraid you’ll get poor marks for matching system requirements to piece parts specs, if I’ve understood your 100 ml req. How accurately must you know that you’ve dispatched 100 ml ?

I read it yes, I understand what you are saying now sorry. It is not being assessed on the technical aspects as such but how it’s intended to be implemented in our chosen situation. We just need to make a working prototype to prove our purpose is attainable. Within 3-4 ml is accurate enough for this project, would you think this is an issue given my current flow meter ?

JonT couldn’t get the folks on the Arduino forum to do his project for him.

I see he is having better luck here.

Jon, be sure to footnote your project to give credit to Mee_n_Mac for writing the sketch for you.

John