Flow Meter using Arduino

In this tutorial we are designing flow meter using arduino, basically we use arduino boot loader controller on our custom made PCB.

A flow meter is a device used to measure the flow rate or quantity of a gas or liquid moving through a pipe. Flow measurement applications are very diverse and each situation has its own constraints and engineering requirements. Flow meters are referred to by many names, such as flow gauge, flow indicator, liquid meter, etc. depending on the particular industry; however the function, to measure flow, remains the same.

Flow Meter

Flow Meter
Flow Meter
Components Required
  1. ATmega328
  2. 7-Segment Display Common Cathode
  3. ULN2003
  4. Resistors 330 Ohm
  5. LM7805 Voltage Regulator
  6. 1N4007 Diodes
  7. 1000uF, 10uF, 22pf Capacitor
  8. Xtal 16MHz
  9. Flow Sensor YF-S201

 What are the various types of flow meters?

Positive Displacement (Also known as a Volumetric flow meter or PD flow meter).
Positive displacement flow meters are unique as they are the only meter to directly measure the actual volume. All other types infer the flow rate by making some other type of measurement and equating it to the flow rate. With PD meters, the output signal is directly related to the volume passing through the meter. Includes bi-rotor types (gear, oval gear, helical gear), nutating disc, reciprocating piston, and oscillating or rotary piston.

Mass
The output signal is directly related to the mass passing through the meter.
Thermal and Coriolis flow meters fall into this category.

Velocity
The output signal is directly related to the velocity passing through the meter.

  • Electromagnetic
  • Ultrasonic
  • Turbine, Propeller, and Paddle Wheel or Pelton Wheel
  • Vortex Shedding and Sonar
  • Variable Area and Rotameter
  • Orifice Plate, Open Channel, Flow Nozzle, Laminar, Venturi, and Pitot Tube

Circuit Diagram of Flow Meter

We are not using directly Arduino Board but we are using Arduino Boot loader chip ATmega328 for this project. Connector is provided for programming with RX, TX, RST and GND pins. In this circuit additional outputs are provided to control buzzer or relay for indicating flow rate is below set points. Flow sensor is connected to Pin 4 (PD2) INT0.

Arduino Flow Meter Circuit
Arduino Flow Meter Circuit

Flow meter PCB Layout

PCB layout downloadable pdf files are provided at bottom of the page

Flow Meter PCB Layout
PCB Layout

Flow meter Arduino Code

Coding is done using Arduino Software. we are displaying LPM on the display with two decimal point places. We are using “TimerOne” Library for display scan time generation.

/*
     Flow Meter using 4-Digit 7-segment Display
     Circuits4you.com
     Arduino UNO, ATMega328
 */

#include <TimerOne.h>

const int SEG3=14;
const int SEG2=15;
const int SEG1=16;
const int SEG0=17;

const int dp=6;
const int a=7;
const int b=8;
const int c=9;
const int d=10;
const int e=11;
const int f=12;
const int g=13;

const int Relay=18;
const int Buzzer=19;

const int Sensor=2;

int cc=0;
char Value[4];
const char SegData[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

int Count=0;
volatile int FlowPulse; //measuring the rising edges of the signal
int Calc;
//=============================================================
//                Setup
//=============================================================
void setup() {                
  // initialize the digital pin as an output.
  Serial.begin(9600);
  pinMode(SEG0, OUTPUT);  
  pinMode(SEG1, OUTPUT);  
  pinMode(SEG2, OUTPUT);
  pinMode(SEG3, OUTPUT);
  
  pinMode(dp, OUTPUT);
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);

  pinMode(Relay, OUTPUT);
  pinMode(Buzzer, OUTPUT);
    
  pinMode(Sensor,INPUT);
  
  digitalWrite(Buzzer,HIGH);
  delay(1000);
  digitalWrite(Buzzer,LOW);
  digitalWrite(Relay,LOW);
  
  //Initialize Display Scanner
    cc=0;
    Timer1.initialize(5000); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
    Timer1.attachInterrupt( timerIsr ); // attach the service routine here
    
    attachInterrupt(0, rpm, RISING); //and the interrupt is attached on Pin 2 (INT 0)    
}
//=============================================================
//               Loop
//=============================================================
void loop() {
  char cnt[4]; 
  
  //Display Count on Segments
  sprintf(cnt,"%04d",Calc);    //We get ASCII array in Volt
  Serial.println(Calc);        //Print Count on Serial for debug
  
  Value[0]=cnt[0] & 0x0F;    //Anding with 0x0F to remove upper nibble
  Value[1]=cnt[1] & 0x0F;    //Ex. number 2 in ASCII is 0x32 we want only 2
  Value[2]=cnt[2] & 0x0F;
  Value[3]=cnt[3] & 0x0F;  
  
  FlowPulse = 0; //Set NbTops to 0 ready for calculations
  sei(); //Enables interrupts
  delay (1000); //Wait 1 second
  cli(); //Disable interrupts
  Calc = FlowPulse * 100.0; //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
  Calc = Calc / 7.5;

  if(Calc < 700)
  {
    Count++;
    if(Count>10)
    {
      digitalWrite(Buzzer,HIGH);
      digitalWrite(Relay,HIGH);
      Count=0;
    }
  }
  else
  {
    digitalWrite(Buzzer,LOW);
    digitalWrite(Relay,LOW);
    Count=0;
  }
}

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
}
//=============================================================
//             Generates Digit
//=============================================================
void DisplayDigit(char dt)
{
  if((dt & 0x80) == 0x00)
  {digitalWrite(dp,LOW);}
  else
  {digitalWrite(dp,HIGH);}
  
  if((dt & 0x40) == 0x00)
  {digitalWrite(g,LOW);}
  else
  {digitalWrite(g,HIGH);}
  
  if((dt & 0x20) == 0x00)
  {digitalWrite(f,LOW);}
  else
  {digitalWrite(f,HIGH);}

  if((dt & 0x10) == 0x00)
  {digitalWrite(e,LOW);}
  else
  {digitalWrite(e,HIGH);}

  if((dt & 0x08) == 0x00)
  {digitalWrite(d,LOW);}
  else
  {digitalWrite(d,HIGH);}

  if((dt & 0x04) == 0x00)
  {digitalWrite(c,LOW);}
  else
  {digitalWrite(c,HIGH);}

  if((dt & 0x02) == 0x00)
  {digitalWrite(b,LOW);}
  else
  {digitalWrite(b,HIGH);}

  if((dt & 0x01) == 0x00)
  {digitalWrite(a,LOW);}
  else
  {digitalWrite(a,HIGH);}  
}
//===================================================================
//			TIMER 1 OVERFLOW INTTERRUPT FOR DISPALY
//===================================================================
void timerIsr()
{
	cc++;
	if(cc==5)  //We have only 4 digits
	{cc=1;}
	Scanner();
	TCNT0=0xCC;
}

//===================================================================
//		SCAN DISPLAY FUNCTION
//===================================================================
void Scanner()
{  
  switch (cc)    //Depending on which digit is selcted give output
  {
    case 1:
      digitalWrite(SEG3,LOW);      
      DisplayDigit(SegData[Value[0]]);
      digitalWrite(SEG0,HIGH);
    break;
    case 2:
      digitalWrite(SEG0,LOW);
      DisplayDigit(SegData[Value[1]] | 0x80); //Decimal Point
      digitalWrite(SEG1,HIGH);
    break;
    case 3:
      digitalWrite(SEG1,LOW);
      DisplayDigit(SegData[Value[2]]);    
      digitalWrite(SEG2,HIGH);
    break;
    case 4:
      digitalWrite(SEG2,LOW);    
      DisplayDigit(SegData[Value[3]]);
      digitalWrite(SEG3,HIGH);      
    break;    
  }
}
//===================================================================

Results

After Assembling Flow meter PCB you can see the zero reading on display. LM7805 used here is SMD type and it is on bottom side of PCB.

Flow Meter Assembled PCB
Assembled Flow Meter

Downloads

  1. Flow Meter PCB Component Layout
  2. Flow Meter Circuit pdf file
  3. Flow Meter Layout for making PCB

 

One thought on “Flow Meter using Arduino

Leave a Reply