top of page
ArudAndRelaySwitchHeaderImage.png

Article covers measuring water flow rate using flowmeter & Arduino.

Disclaimer

1. This step-by-step how-to covers lab setup and not the field setup or test.

2. This how-to does not cover the calibration of flow meter.

3. This does not cover the working principles of flow meter.

Working sample

Before we proceed further, let us take a look at what our end result would look like.

Items needed

- Arduino Uno.

- Hall effect flow meter sensor.

Pre-requisites

This post assumes you already have,

1.     Arduino Editor installed on your laptop.​

2.    Your laptop connected to Arduino using the USB cable.

3.    Basic familiarity with Arduino programming using C++.

Technical details

How flow meter works?

This post does not go into details of how flow meter works. There are numerous materials available on the internet.

GR201-FlowMeter.png
Schematic & Wiring diagrams
Schematic_IoT_2022-09-30.png
This is how the final setup looks like:
IMG_6437_edited.jpg
How-to steps

Step 1: Connecting Arduino to flow meter

Water flow sensors normally have three leads. +ve, -ve and interrupt.

Interrupt output from flow meter sensor send a certain amount of HIGH signals depending on the flow rate, and it needs to be connected to Arduino's interrupt pins.

Arduino Uno has two interrupt pins, pin #2 and pin #3. These pins are referenced as 0 and 1 in the c++ code, which you can see in the sample code below.

IMG_6438_edited.jpg
IMG_6439_edited.jpg

Step 2: Flow meter sensor

IMG_6440_edited.jpg

Water flow sensors normally have three leads. +ve, -ve and interrupt.

In the above diagram, you may notice,

F=(7.5 * Q), Q=L/Min.

F - Frequency

Q - Flow rate

Using above spec,

Q (flow rate) = F / 7.5 liters per minute

Step 3: Arduino C++ I2C code

There are no new libraries to be downloaded. Code is straight forward.

C++ code

int flowPin = 5;    //Digital input pin on the Arduino

double flowRate;    //Variable to hoold the calculated flow rate

 

//This variable is incremented when interrupt runs.

//This needs to be set as volatile ensure to ensure it updates correctly during the interrupt process.

 

volatile int count; void setup() {  

      // Setup code here, to run once:  

      pinMode(flowPin, INPUT);           //Sets the pin as an input  

 

      //Configures interrupt 0 which is pin number 2 on the Arduino Uno, which runs the function 'calculateNumberOfPulsees()'  

      attachInterrupt(0, calculateNumberOfPulsees, RISING);      

      Serial.begin(9600);  //Start Serial

}

 

void loop() {  

      // Main code here, runs repeatedly:    

 

      count = 0;      // Reset the counter before running the interrupt      

 

      interrupts();     //Enables interrupts on the Arduino.

                               //This will start checking the interrupt and run the calculateFlowRate() every time when the signal Rises                                                   //When the interrupt is active for 1 second, the  

 

      delay (1000);     

      noInterrupts();   //Disables the interrupt check on the Arduino. This will stop incrementing the counter  

 

     //LPM calculation: as per sepcifications, Frequency = 7.5 x liters per minute. So, Liters per minute = Frequency / 7.5    

 

     flowRate = (count / 7.5);          

 

     //Print the number of interrupts in the last second  

     Serial.print("Number of interrup is: ");           

     Serial.print(count);           

     Serial.print(" & The flow rate is : ");  

     Serial.print(flowRate);         //Print the variable flowRate to Serial  

     Serial.println(" lpm");          //Print the variable flowRate to Serial

 

}

 

void calculateNumberOfPulsees() {  

     

     count++; //count gets incremented every time this function is called

 

}

Step 4: Testing the flow meter

Now the setup should be ready. When the C++ code runs,

1. Interrupts are activated for 1 second through "delay(1000)" command in the code.

2. When there is an interrupt signal in Arduino's pin #2, the funtion 'calculateNumberOfPulsees()' gets called, which increments the counter variable by 1.

3. After 1 second, the interrupt is stopped, and we proceed to calculate the flow rate.

4. After calculating the flow rate, the counter is reset to 0.

Refer accompanying video to see a demo of this. Instead of water, I've used the air flow through the meter to activate the flowmeter.

Closing note

Hope this post gives you the basic details of measuring flow rate using hall effect flowmeter and Arduino.

bottom of page