Close

Arduino Hall Effect Water Flow Meter

A project log for Hacking the way to growing food

Using Technology And A Hackers Mindset To Grow Food. Last Updated [16/01/2021]

michael-ratcliffeMichael Ratcliffe 08/28/2015 at 00:122 Comments

While the fish feeder project is on hold awaiting parts, we will take some time to work on the other aspects of this project. The Aquaopnics side using fly's as food and the PeePonics both need to be studied in detail. for both of these we will need a good idea about the amout of water consumed.

I am sure a lot of you are also working on ways to keep an eye on water flow, So I thought I would make a blog covering my implementation.

I opted for a hall effect flow meter because I salvaged it a while ago and had it handy. It has been up and running in the greenhouse for a while now as part of a larger code, Ive pulled the meter portion out and it is below, I've got no spare arduino to test it works but it is pretty simple [Point out any problems you see].

How It works:

I dont like the approach of measuring the frequency to calculate flow rate and then integrating to get water flow, So It works the opposite way.

>ISR to log number of pulses

>Convert the Pulses/second for a flow rate

>Logs Total Pulses for total water usage

>Checks there isnt a major leak [flow rate is reduced because I use drip irrigation]

Pinout.png

Things to keep in mind, the serial will reset every time you reconnect so it isnt goof for final implementation, the clock will roll-over every 50 days and could output one bad reading every 50 days.

The Code:

/* This script is used to make sense of the output from a hall effect water flow meter and make a note of any problems
 
 
Michael Ratcliffe  Mike@MichaelRatcliffe.com
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see .
 
 
 
 
    Components:
    See main folder for sensor data sheets, required liabaries and extra information: [can be downloaded via www.michaelratcliffe.com]
 
    All power systems should be powerd of DC voltage of below 48v for safter [water is around] 12v is prefferable and cheapest. As always this is a DIY project and done at your own risk.
 
 
    >Arduino Mega 2560 [1280 is not sutiable, ram problems and sensor conflict] compiled using Arduino 1:1.0.5
    >Hall Effect Water Flow Meter 5v
 
 
 
*/
//******************************** User Defined Variables *******************************************************//
#define Meter_power  5
#define Meter_ground 4
#define Water_pin 3
 
 
float Click_Per_L = 300; // this depends on your flow meter
 
 
 
 
const float Max_ExpectedFlow =2; //Max flow expected flowrate in L/s, if it is more than this we have a problem
 
 
 
 
 
 
//***************************** End Of User Defined Variables **************************************************//
 
 
unsigned long PulseCount=0;  //counter for water meter pulses
long Second;
long Last_Reading=0;
int Readings=0;
float Water_Used=0;
float Flow_Rate= 0;
long Last_Count =0;
 
 
int BurstPipe=0;
 
 
 
 
//**************************** Setup Routine , Runs Once and Sets used pins to correct value *******************//
void setup() {
     
pinMode(Meter_ground, OUTPUT);
digitalWrite(Meter_ground, LOW);
 
pinMode( Meter_power, OUTPUT);
digitalWrite(Meter_power, HIGH);
      
pinMode(Water_pin, INPUT);
digitalWrite(Water_pin, HIGH);// saves having an external pullup
   
//External Interrupts:  3 (interrupt 1),     
attachInterrupt(1, WaterCounter, FALLING);  //watermeter pulse output connected to pin3
};
 
 
 
//************************************** Main Loop that will continualy run ******************************************//
void loop(){
 
Second=millis()/1000;
 
 
//************** If Statment that will run every second ******************//
            if (Last_Reading!=Second) {
            Last_Reading=Second; //Makes note of the last second
            Readings=1;          //Tell serial there is data to transmit
            Flow_Rate=((PulseCount-Last_Count)/Click_Per_L);
               
         
            Water_Used=(1/(Click_Per_L/PulseCount)); //cant recall why I did it this way, maybe to retain float capabilities
            Last_Count=PulseCount;                   // Makes a note of the last reading
                   
                               //** Checks if there is a problem **//
                                  if(Flow_Rate>=Max_ExpectedFlow){
                                                       BurstPipe=1;
                                                                  };
 
 
                                    };
 
 
 
 
//**** Checks If there is Data To send over Serial- Recomended to be LCD instead ******//
if (Readings==1){
Readings=0;
 
Serial.print("Total Water Used");
Serial.print(Water_Used);
Serial.println(" L");
Serial.print("Current Flow Rate: ");
Serial.print(Flow_Rate);
  Serial.println(" L/s");
 
          if(BurstPipe==1){
            Serial.println("BurstPipe");
          }
     
 
}
 
 
   
delay(10);
};
//*************************************************END OF LOOP ******************************************************//
 
 
//***Interupt routine for water meter readings - Runs everytime sensor has a pulse ***//
 
 
void WaterCounter() {
 
   // Increment the pulse counter
  PulseCount++;
 
};

Recommendations: Add a LCD/ IOT solution to remove the serial resetting problem, add a uptime counter.

Discussions

geert2 wrote 02/03/2017 at 10:00 point

Thank you very much for this.

The flow meter gets clogged with muck from the bio-active slime. Regular cleaning seems not really to work. How do you tackle this? (or did I buy too cheap? ). 

  Are you sure? yes | no

Michael Ratcliffe wrote 02/03/2017 at 12:12 point

Hi, 

I was using this meter to measure the water usage of the system, it was placed on the fresh water inlet to the system that tops up the water to account for plant growth and evaporation. 

I would recommend a different flow meter for the main pump, either acoustic of pressure drop thru a known restricter [could be a length of pipe] 

  Are you sure? yes | no