element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Vertical Farming
  • Challenges & Projects
  • Design Challenges
  • Vertical Farming
  • More
  • Cancel
Vertical Farming
Blog Automated Green House Blog:8 -  Water Usage
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: m.ratcliffe
  • Date Created: 27 Aug 2015 2:47 PM Date Created
  • Views 3698 views
  • Likes 4 likes
  • Comments 24 comments
  • adapted_greenhouse
  • aquaponics
  • arduino
  • flowrate
Related
Recommended

Automated Green House Blog:8 -  Water Usage

m.ratcliffe
m.ratcliffe
27 Aug 2015

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]

 

 

image

 

 

 

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. This code is commented to allow anyone to implement it and you guys at Element14 will find them a little obvious,sorry.

 

Code - ISR Based FLow Meter

/* 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 <http://www.gnu.org/licenses/>.

   

   

   

   

    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

 

 

 

 

//************************** Just Some basic Definitions used for the Up Time LOgger ************//

long Day=0;

int Hour =0;

int Minute=0;

int Second=0;

int HighMillis=0;

int Rollover=0;

 

 

 

 

//***************************** End Of User Defined Variables **************************************************//

 

 

unsigned long PulseCount=0;  //counter for water meter pulses

unsigned long Current_PulseCount=0;

int Last_Reading=0;

int Readings=0;

float Water_Used=0;

float Flow_Rate= 0;

unsigned long Last_Count =0;

 

 

 

 

//**************************** Setup Routine , Runs Once and Sets used pins to correct value *******************//

void setup() {

 

 

//Making it easy to power the Flowmeter        

pinMode(Meter_ground, OUTPUT);

digitalWrite(Meter_ground, LOW);

pinMode( Meter_power, OUTPUT);

digitalWrite(Meter_power, HIGH);

 

 

//Stoping noise from being a problem, pin is high untill hall sensor pulls it low

pinMode(Water_pin, INPUT);

digitalWrite(Water_pin, HIGH);// saves having an external pullup

     

//External Interrupts: This is what the watr meter pulse count is collected from      

attachInterrupt(1, WaterCounter, FALLING);  //watermeter pulse output connected to pin3

};

 

 

 

//************************************** Main Loop that will continualy run ******************************************//

void loop(){

 

 

//calls uptime function below main loop

uptime();

 

 

 

 

//************** 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

 

 

            //Turn off interupt while we take a quick note of it and then turn it back on

            detachInterrupt(1); //

            Current_PulseCount=PulseCount; // making note of pulse count

            attachInterrupt(1, WaterCounter, FALLING);  //watermeter pulse output connected to pin3

           

            Flow_Rate=((Current_PulseCount-Last_Count)/Click_Per_L);  

            Water_Used=(1/(Click_Per_L/Current_PulseCount)); //cant recall why I did it this way, maybe to retain float capabilities

           

            Last_Count=Current_PulseCount;                   // Makes a note of the last reading

 

 

                                    };

 

 

 

 

//**** Checks If there is Data To send over Serial- Recomended to be LCD instead ******//

if (Readings==1){

print_Serial();

       

 

}

 

 

     

delay(10); 

};

//*************************************************END OF LOOP ******************************************************//

 

 

 

 

//******************* Uptime Counter **************************************************//

//WE need an uptime counter to verify our total flow readout is valid

 

 

void uptime(){

//** Making Note of an expected rollover *****// 

if(millis()>=3000000000){

HighMillis=1;

 

}

//** Making note of actual rollover **//

if(millis()<=100000&&HighMillis==1){

Rollover++;

HighMillis=0;

}

long secsUp = millis()/1000;

Second = secsUp%60;

Minute = (secsUp/60)%60;

Hour = (secsUp/(60*60))%24;

Day = (Rollover*50)+(secsUp/(60*60*24));  //First portion takes care of a rollover [around 50 days]                  

};

 

 

 

 

 

 

//******************** Prints To Serial Console **********************************************************//

 

 

void print_Serial(){

 

 

 

 

//Printing Some Uptime Values

  Serial.print(F("Uptime: ")); // The "F" Portion saves your SRam Space

  Serial.print(Day);

  Serial.print(F("  Days  "));

  Serial.print(Hour);

  Serial.print(F("  Hours  "));

  Serial.print(Minute);

  Serial.print(F("  Minutes  "));

  Serial.print(Second);

  Serial.println(F("  Seconds"));

 

 

//Printing Some Water Flow info

  Serial.print(F("Total Water Used"));

Serial.print(Water_Used);

Serial.println(F(" L"));

Serial.print(F("Current Flow Rate: "));

Serial.print(Flow_Rate);

  Serial.println(F(" L/s"));

 

};

 

 

 

//************8*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.

 

It looks like other contestants are moving a long quickly now, keep the content coming it makes a great read.

 

Mike

  • Sign in to reply

Top Comments

  • m.ratcliffe
    m.ratcliffe over 10 years ago in reply to screamingtiger +2
    My Blog is a little bit messy right now and wont make sense until the final blog and summary is written, it mostly related to aquaponics and goes off topic quite regularly. Take a look at the Greenhouse…
  • amgalbu
    amgalbu over 10 years ago +1
    Hi Michael Very interesting post. Could you provide some details about the flow meter? Seems to be a nice product, since it can be powered using an Arduino pin
  • m.ratcliffe
    m.ratcliffe over 10 years ago in reply to amgalbu +1
    The one I am using is old [Farnell had to look in their archives for the spec sheet, old]. This is the modern equivalent But any hall effect based flow meter should be ok for powering by any arduino pin…
Parents
  • RWReynolds
    RWReynolds over 10 years ago

    Great info Michael!

     

    I am considering this now for my nutrient feed system. Have you ever looked at or tried any differential pressure type flow meters? They are pretty inexpensive and supposed to be fairly accurate.

     

    Something like this...

    http://www.omega.com/pptst/PX26.html

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • m.ratcliffe
    m.ratcliffe over 10 years ago in reply to RWReynolds

    I've used pressure sensors as flow indicators on some large projects but never had a chance to use a small one such as the one in the link.

     

    For the nutrient addition I just measured the pump output in L/s and used a basic calculation to add the amount I needed by varying the pump on-time, I wasn't to fussed about undershooting the set point by a couple of percent and did the adding every hour so I just set it to add 10% less than It thought it needed. It might not be the best solution but It worked quite well.

    the calculation went a little something like this:

     

    Va=((PPMd-PPMn)*Tv)/PPMs

    Pump Time Seconds = (Va/Ps)*0.9

     

    Va:          Volume of Nutrients to add L

    PPMd:     Desired PPM of tank

    PPMn:      PPM of main tank now

    Tv:           Volume of main tank L

    PPMs:     PPM of the nutrient tank

    Ps:          Pump flowrate in L/s

     

    I was using a Large Tank [1000L] and very strong nutrients, if you are using weak nutrients you will need to iterate the equation to take into account the new tank volume. Or just get rid of the *0.9 part because the equation doesnt take into account the nutrient addition also adds volume and it will still be in the ball park.check this code, because it is from memory, I lost the original code during a tired idiotic moment [chmod my whole hard drive instead of a single file]

     

    I need to make myself a EC probe before working on the automating this systems nutrient control.

     

    Good to see your project moving along, I like the idea of three units around a single LIght source.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • m.ratcliffe
    m.ratcliffe over 10 years ago in reply to RWReynolds

    Same thing different units. [assuming we are only talking about liquid EC and PPM]

     

    To measure TDS you first measure EC [the resistance of the water]  and then multiple the EC by a factor to get TDS. The Trouble is there are a few different EC to TDS factors and it gets confusing when discussing with people who's meters may have used a different factor.

     

    There is also correcting the EC reading to compensate for temperature. But most off the shelf units will do this for you.

     

    If you do implement a Ph-Probe I advice adding a problem checker, ie has it added much more than we expected today. Ive tried lots of different branded hand held ones and they always fail, drift of just outright packup.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • RWReynolds
    RWReynolds over 10 years ago in reply to m.ratcliffe

    I got the electrical conductance part. Just didn't realize they used that to determine total dissolved solids. Makes sense though. But it would seem that the makeup of the solids would be relevant as well.

     

    Understood on tpH probes. Any good info on building your own?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • m.ratcliffe
    m.ratcliffe over 10 years ago in reply to RWReynolds

    Yeah the conversion factor for EC to PPM depends on what chemicals are in the water and the strength of the fluid. To sum it up very low concentrations the factor isnt the same as for mild concentrations and high up the PPM can increase but the EC will remain the same. Luckily we are usually only measuring something in the middle range in aquaponics and its ussualy the same set of chemicals.

     

    No Idea about Ph, I dont like the way the current sensors work because they are problematic and always break. I am hoping to use a different approach by finding something that changes size/color with Ph without breaking down and measuring that change with a camera/distance sensor, but at the moment this is nothing more than an idea i'm entertaining and havent read up much about it.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • m.ratcliffe
    m.ratcliffe over 10 years ago in reply to RWReynolds

    Hey Rick, I just made the proof of concept and it works. The next tutorial will be a $5 EC meter that you can make with stuff you have knocking around, with easily replaceable $1 probe.

     

    Sorry, Had to tell someone.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • RWReynolds
    RWReynolds over 10 years ago in reply to m.ratcliffe

    Fantastic! Man, I love yaking about this stuff. Ya know... I started in hardware/software officially in the 80s. And then I veered off into business programming. I am just returning, within the last few years, back to my roots. So, I'm all ears.

     

    I'm very interested in building as much of this from scratch as I can. I'm already using, more than I'd like, off-the-shelf parts in the cultivator. Mainly because I'm recovering from this ankle surgery and couldn't get around very well. But it's getting better. With another 30 days to build before we start growing I plan on doing a lot of low-level hardware development. We'll see how that turns out. lol...

     

    Please let me know the details when you have the EC sensor worked out.

     

    Cheers,

    Rick

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • RWReynolds
    RWReynolds over 10 years ago in reply to m.ratcliffe

    Fantastic! Man, I love yaking about this stuff. Ya know... I started in hardware/software officially in the 80s. And then I veered off into business programming. I am just returning, within the last few years, back to my roots. So, I'm all ears.

     

    I'm very interested in building as much of this from scratch as I can. I'm already using, more than I'd like, off-the-shelf parts in the cultivator. Mainly because I'm recovering from this ankle surgery and couldn't get around very well. But it's getting better. With another 30 days to build before we start growing I plan on doing a lot of low-level hardware development. We'll see how that turns out. lol...

     

    Please let me know the details when you have the EC sensor worked out.

     

    Cheers,

    Rick

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube