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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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 2733 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 9 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 9 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 9 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…
  • RWReynolds
    RWReynolds over 9 years ago in reply to Former Member

    I got 100W of Red/Blue LED grow light for about $60. Not too bad. There is a bit of assembley that has to be done, no soldering, but that worked ou well because I could mount them the way I wanted.

     

    I got two of these kits from Amazon.

    http://ledgrowlightsguide.tk/gled-5pcs-10w-grow-light-bars-light-strip-hydroponic-plant-flowers-vegatables-greens-led-grow-plant-growing2-5m27red9blue-2015-review/

     

    Cheers,

    Rick

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago in reply to RWReynolds

    Nice. Yeah buying LEDs is super expensive....

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • RWReynolds
    RWReynolds over 9 years ago in reply to Former Member

    The kit is relatively expensive, around $300. That's way outside my budget for this project. I have already hit my budget limit. Everything from here on out will be fabricated from existing materials or repurposed devices. image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago in reply to RWReynolds

    Dang it, the one part I don't have:(. Maybe I can buy it online? Does anyone know where I could buy it? I have the EFM32 though.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • RWReynolds
    RWReynolds over 9 years ago in reply to Former Member

    This is from the terms and conditions...

     

    Chck out pages 2 and 3...

     

    The component from the Kit which must be utilised is: EZR32WG 868MHz Wireless Starter Kit.

     

    But what Joey said... Use as many of the provided devices as you can.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
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 © 2025 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