top of page

Measuring water flow rate and calculating quantity using Flow Sensor with Arduino.


What is a Water Flow Sensor?The water flow sensor consists of a plastic valve body, a water rotor, and a hall-effect sensor. When water flows through the rotor, the rotor rolls. Its speed changes with different rates of flow. The hall-effect sensor outputs the corresponding pulse signal. This one is suitable to detect flow in a water dispenser or coffee machine.

Specifications

· Mini. Working Voltage: DC 4.5V

· Max. Working Current: 15mA (DC 5V)

· Working Voltage: DC 5V

· Flow Rate Range: 1~30L/min

· Operating Temperature: 80 C

· Liquid Temperature: 120

· Operating Humidity: 35%~90%RH

· Water Pressure: 1.75MPa


Material Required:

Material Quantity

Arduino Uno 1

Water Flow Sensor 1

Jumper cables 3


Pinout Diagram:


Working:




This illustration gives a detailed working method of the Hall effect sensor-based water flow sensor, a turbine wheel embedded with a magnet is placed on a closed plastic envelope and a Hall effect sensor is placed, When the water flows through the pipeline, it makes the turbine wheel to rotate and hence the magnet flux interferes the hall sensor, the rate of interference depends on the speed of water flow, so the hall effect sensor produces pulse signal output, this pulse output can be calculated as water volume.


Circuit Diagram:




Connect the +5V wire to Arduino power pin 5V and Ground pin to Gnd then connect the Signal pin to Digital pin D2, this sensor has a control circuit hence there is no need for pull up resistor, some sensor requires to pull up resistors refer to the datasheet of water flow sensor before concluding hookup.


Tested Programming Code:


The code uses an external interrupt on the Arduino's digital pin 2. This is used to read the pulses coming from the flow meter. When the Arduino detects the pulse, it immediately triggers the pulseCounter() function. This function then counts the total number of pulses.


In this Arduino flow rate sensor, for every liter of liquid passing through it per minute, it outputs about 4.5 pulses. Dividing the total pulse count by 4.5 will give you the total amount of liquid passing through it in liters per minute. Dividing that by 60 will give you the flow rate in liters per hour, which gives us the total amount or quantity of water/liquid that has passed through it. The sensor is accurate to within 3%.


Code:


byte statusLed = 13;

byte sensorInterrupt = 0;

byte sensorPin = 2;

float calibrationFactor = 4.5;

volatile byte pulseCount;

float flowRate;

unsigned int flowMilliLitres;

unsigned long totalMilliLitres;

unsigned long oldTime;


void setup()

{

Serial.begin(38400);

pinMode(statusLed, OUTPUT);

digitalWrite(statusLed, 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) // Only process counters once per second

{

detachInterrupt(sensorInterrupt);

flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;

oldTime = millis();

flowMilliLitres = (flowRate / 60) * 1000;

totalMilliLitres += flowMilliLitres;

unsigned int frac;

Serial.print("Flow rate: ");

Serial.print(int(flowRate));

Serial.print(".");

frac = (flowRate - int(flowRate)) * 10;

Serial.print(frac, DEC) ;

Serial.print("L/min");

Serial.print(" Current Liquid Flowing: ");

Serial.print(flowMilliLitres);

Serial.print("mL/Sec");

Serial.print(" Output Liquid Quantity: ");

Serial.print(totalMilliLitres);

Serial.println("mL");

pulseCount = 0;

attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

}

}

void pulseCounter()

{

pulseCount++;

}


Precautions:

  • Double check the connections before powering on the circuit.

  • Don’t use loose jumper cables.

  • Check whether the proper board is selected from Arduino IDE.

  • Ensure proper placement of sensor for correct working.

  • Please keep your hardware away from water except, the water flow sensor.


Conclusion:


You can successfully measure the flow rate and quantity of the water flowing through a pipe through a cross-sectional area. This sensor can be deployed in many ways like water level automation systems, water meters, etc.


Output:

Situation Screenshot: Serial Monitor (Ctrl+Shift+M)






GET IN TOUCH

We'd love to hear from you

bottom of page