, ,

Awhile back, the plants were not getting any water/nutrients because the pump relay stopped working.  It became clear to me after this incident that a flow meter monitoring whether the pump was working would be very beneficial to have as part of the Base section of the Leaf Spa.

This post is about incorporating the flow meter into the Leaf Spa.  

Thanks To Those That Went Before

Adafruit – Thank you for your awesome customer service.  Adafruit goes above and beyond any company I know providing sample code, tutorials, excellent forums, products I can trust to work.  Products cost a bit more…but I really want Adafruit and companies who respect their customers and employees.

The Flow Meter

I got a liquid flow meter in the mail from Adafruit yesterday.



How It Works

My goal is to detect whether water is flowing through the sensor.  I’ll do this in the firmware by figuring out if the flow rate is > 0 when the pump is supposed to be on.  I haven’t used a flow meter before so I figured I should know at least a little bit on how it works.

T.K. Hareendran’s blog post, “Working with Water Flow Sensors & Arduino”, gave me great info on the basics of how this type of flow meter works.  For example, I find out the type of sensor I bought is a YF-201 Hall-Effect Water Flow Sensor.  As pointed out in the article:  This sensor sits in line with the water line and contains a pinwheel sensor to measure how much water has moved through it. There is an integrated magnetic Hall-Effect sensor that outputs an electrical pulse with every revolution… By counting the pulses from the output of the sensor, we can easily calculate the water flow rate (in litre/hour – L/hr) using a suitable conversion formula.

I’ll be looking at the flow rate of water when the Leaf Spa firmware turns on the pump relay.  If there is no water flowing, something within the pump system (the pump itself, the relay) is not working.

As usual, Adafruit has provided superior support for the flow meter by making available a sample Arduino sketch at this GitHub location.  Getting this sketch working was easy and gave me a better feel for how the flow meter works with the Arduino.

I’ll blindly take the approach of “if you say so” based on Lady Ada’s comments in her Arduino Sketch:

  // if a plastic sensor use the following calculation
  // Sensor Frequency (Hz) = 7.5 * Q (Liters/min)
  // Liters = Q * time elapsed (seconds) / 60 (seconds/minute)
  // Liters = (Frequency (Pulses/second) / 7.5) * time elapsed (seconds) / 60
  // Liters = Pulses / (7.5 * 60)
  float liters = pulses;
  liters /= 7.5;
  liters /= 60.0;

I’m interested in the flow rate, not in how much water goes through the sensor.  Given what Lady Ada tells me about the flow rate (she’s using Q to represent the flow rate in liters/minute):

Pulses (Hz)) = 7.5 * Flow rate(liters/minute)

Flow rate (liters/minute) = Pulses (HZ)/7.5

Test Code

I’m going to use an external interrupt (the attachInterrupt() API) to let the firmware know when water is flowing through the sensor.  The test sketch that seems to work – FlowMeterTest2.ino – is located at this GitHub location.

Adding Code

Simpson DOHBut first…an OOPS…I thought it would be a “good thing” to update the SD library since I was informed I didn’t have the latest…BUT I FORGOT about what I talked about in this post about SD.end().  Here is the error I got:

Multiple libraries were found for “SD.h”
Used: /Users/margaret/Documents/Arduino/libraries/SD
Not used: /Users/margaret/Documents/Arduino/libraries/SD-master
Not used: /Applications/Arduino.app/Contents/Java/libraries/SD_ORIGINAL

seems I’m not lacking SD libraries :-).

Turns out the one being used was the library that I updated yesterday…the SD library folder within my Arduino/libraries folder.  I deleted the SD folder.  Now the firmware is back to using the SD-master library…which includes the end() API.

Bummer – attachInterupt() is only available on pins 2 and 3 on the Arduino Uno.  The firmware is already using these pins (from TheLeafSpa.ino sketch located at this gitHub location (version 8767e1d):

   2 - DHT temp/humidity
   3 - SD card detect
   4 - pump relay
   5 - LED relay
   6 - CO2 relay
   7 - Software Serial
   8 - Software Serial
   10 - SDI chip select
   11 - SDI DI pin
   12 - SDI DO pin
   13 - SDI CLK pin

The firmware is using attachInterrupt() with pin 3.  This means I’m restricted with the current hardware configuration to using pin 2 for the flow meter.

It doesn’t help that Seeed’s Grove Base Shield limits the digital i/o pins further:

I’m changing the pin mappings:

   2 - Flow Meter
   3 - SD card detect
   4 - DHT temp/humidity
   5 - LED relay
   6 - CO2 relay
   7 - Software Serial
   8 - Software Serial
   9 - Pump relay
   10 - SDI chip select
   11 - SDI DI pin
   12 - SDI DO pin
   13 - SDI CLK pin
  • DHT is on pin 4 instead of pin 2.
  • pump relay is on pin 9 instead of pin 4.
  • Flow meter is on pin 2.

 Adding the Flow Meter

It took a bit of emotional effort to cut into the plumbing and insert the flow meter..but it’s done…before and after:

NewImage   NewImage 

Checking the Log File

 Below are two snippets of the log file after adding the flow meter:

1 3/22/2017 11:40:28          
0 3/22/2017 11:41:28 23.5 71.5 1097    
5 3/22/2017 11:41:28          
2 3/22/2017 11:41:28 167.33        


1 3/22/2017 11:55:28          
0 3/22/2017 11:55:29 24.3 70.2 1113    
5 3/22/2017 11:55:29          
6 3/22/2017 11:55:37          
2 3/22/2017 11:56:28 175.33        

1 in the first column means the pump has turned on. 2 means the pump turned off.  The row identifying the pump was turned off now includes a column with the flow rate in liters/minute.  Both are > 0 which means water has gone through the plumbing.  YIPPEE!  The first flow rate shows 167 liters/minute (~44 gallons/minute).  The second shows 175 liters/minute (~46 gallons/minute).

The pump’s data sheet (I am using the 160 GPH model) states the model I am using has a min GPH of 106 and a max of 175.

I measured a WAY HIGHER value…SO…hmmm…

The values for the flow rate ARE NOT ACCURATE however, the Leaf Spa is detecting whether the water is flowing.

So, for what I need it to do, the flow meter is doing ok.  At this point, I do not need the flow rate.  If I did, I would debug this further.

Good better best  Of course, measuring the flow rate as accurately as possible should be part of the Leaf Spa.  But since my goal at this point is to detect water flow, I will not debug now.  Future builds should accurately measure water flow.  Frankly, I am not surprised measurements are off.  I did not do any flow rate accuracy testing before putting the flow meter in.


ChallengesBringOpportunites Yippee!  The flow meter is in place.