Sunday, June 14, 2015

Arduino flow measurement

Ever wanted to measure liquid flowing through a pipe / container? Wanted to create a control system based on the water flow rate or quantity ? For example while gardening, to measure the amount of water used to water your plants , to prevent wastage , etc.  If yes, then this very easy DIY project is for you. Here, step by step instructions are given on how to measure water flow rate and quantity using an arduino flow rate sensor.

A flow sensor is a device for sensing the rate of fluid flow. Typically a flow sensor is the sensing element used in a flow meter, or flow logger, to record the flow of fluids.

Step 1: Components Requires
1. Arduino Uno
2. Flow Sensor
3. Connecting wires
4. LCD Display
5. 1K Ohm Resistor

Step 2: Circuit and Its Connections
Flow sensor Yellow Wire is output and it gives pulses in proportion with flow

Connect Flow Sensor and LCD as shown above, You may skip the connection of LCD display if you want to take readings on computer. Reading also displayed in serial monitor.

Step 3: Programming the Arduino


This tutorial Demonstrates the use of Flow Sensor
  The circuit:
Flow Sensor Connections
Yellow --- Pin 6
Red    --- +5V
Black  --- GND     
LCD Connections      
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 6
 * LCD D5 pin to digital pin 5
 * LCD D6 pin to digital pin 4
 * LCD D7 pin to digital pin 3
 * LCD R/W pin to ground
 * 1K resistor:
 * One end to ground
 * Another end to LCD VO pin (pin 3)
 This example code is in the public domain.

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 6, 5, 4, 3);

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

void setup() {
   pinMode(flowsensor, 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
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.setCursor(0, 1);
  lcd.print("Flow Meter");

void loop() {
 FlowPulse = 0;      //Set NbTops to 0 ready for calculations
 sei();            //Enables interrupts
 delay (1000);      //Wait 1 second
 cli();            //Disable interrupts
 Calc = (FlowPulse * 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
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 2);
  lcd.print(Calc,DEC);   // print the Flow Rate
  lcd.print(" L/hour");

void rpm ()     //This is the function that the interupt calls 
  FlowPulse++;  //This function measures the rising and falling edge of the hall effect sensors signal

Step 4: Testing and Results
1. Blow air or allow water flow through the sensor
2. Observe the reading on LCD or Serial Monitor
3. Readings get updated at every 1 Sec


  1. I cant get a read out for PIN 6 at all

  2. i only get 8 L/hour every time... why?

  3. avrdude: stk500_getsync(): not in sync: resp=0x00

  4. I cant read out for PIN 6

  5. Okay so for everyone that wants to run this on pin six, this code can only work on pin 2 and 3. Those are the only pins on the uno that accepts external interrupts, sooooo when you call "attachInterrupt(0, rpm, RISING);" you are attaching an interrupt to digital pin 2, when you call "attachInterrupt(1, rpm, RISING);" you are attaching an interrupt to digital pin 3!

    I do not know how the OP got this to work but only pin 2 and 3 can work (according to me :P )

  6. i need library file of this program can you help me with that

  7. i need a library for the same please at

  8. i need a code exactly like this but using a lcd keypad! Somebody can help me?

    1. You can get some help on keypad interfacing, If you tell complete project Idea I will make it and publish here.

  9. 'Calc' gives the value of flow rate in liter per hour which is Q(flow rate). So how come there is a Q in the denominator

    Calc = (FlowPulse * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour