Flow Rate Sensor Interfacing: How to Measure Liquid with an Arduino

Ever wanted to measure liquid flowing through a pipe or container? Wanted to create a control system based on the water flow rate or quantity? For example, while gardening, to measure the amount of water used to water your plants, to prevent wastage. If yes, then this easy DIY project is for you! Here is some step by step instructions on how to measure water flow rate and quantity using an Arduino flow rate sensor.

Required Materials


  1. Arduino/Arduino Clone or make your own custom Arduino board.
  2. Water/Liquid flow meter like a Flow meter.
  3. Connecting wires.

Software :

  1. Arduino IDE

How Does it Work?

The Arduino flow meter works on the principle of the Hall Effect. According to which, a voltage difference is induced in a conductor transverse to the electric current and the magnetic field perpendicular to it. Here, the Hall Effect is utilized in the flow meter using a small fan/propeller shaped rotor which is placed in the path of the liquid flowing.

The liquid pushes against the fins of the rotor, causing it to rotate. The shaft of the rotor is connected to a Hall Effect sensor. It is an arrangement of a current flowing coil and a magnet connected to the shaft of the rotor, thus a voltage/pulse is induced as this rotor rotates. In this flow meter, for every liter of liquid passing through it per minute, it outputs about 4.5 pulses. This is due to the changing magnetic field caused by the magnet attached to the rotor shaft as seen in the picture below. We measure the number of pulses using an Arduino and then calculate the flow rate in liters per hour (L/hr) using a simple conversion formula explained in step 2.

Arduino flow rate sensor tutorial

Flow rate sensor

Connecting the Arduino to the Flow Rate Sensor

The connections required for this flow rate sensor with respect to the Arduino is very minimal. There are only three wires coming from the flow rate sensor. The 5V Vcc (Red wire), The GND (Black wire), and the signal/pulse (Usually yellow) line. Connect the Vcc and GND of the flow meter to the Arduino’s Vcc and GND. The pulse line of the flow rate sensor is connected to the Arduino’s digital pin 2. The Arduino’s digital pin 2 serves as an external interrupt pin (interrupt pin 0). Now you have hooked up your flow meter to the Arduino!


Arduino flow rate sensor connections

Uploading the Flow Meter Code to the Arduino and Measuring Water Flow Rate

Upload the Flow Meter Code to your Arduino. 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 obtained 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%.

Here’s a video showing the Arduino flow rate sensor in action!


Use this Arduino flow rate sensor with a solenoid valve to monitor and control the water used. You can use it in your gardening system, or interface it with an LCD display for other applications that require you to measure water flow rate and quantity. Have fun with your new Arduino flow rate sensor!


Arduino Flow Rate Sensor

Recommended Posts
Showing 113 comments
  • Joseph Funk

    After i upload this code, when i open the serial monitor it just shows a bunch of boxes with no actual text. An idea what is going on?

  • Larry Fostano

    Can you tell me where the error is here?

    Stray \342′ in program

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

  • Kaisar

    Hello sir I have a problem on my system I used the same kind of water flow sensor you use and I also have a solenoid valve is it possible to put a limit or set point example if 400ml has pass the solenoid will close the pipe . hope you can help me i’m stuck on this and running out of time Thanks in advance .. sorry for my english not my first language :D

  • Gari

    We are stuck on a school project and could do with some help. Do you have a programme that we can use so that the water supply is cut off if there is water running through the flow meter for more than 21 minutes? We have a flow meter like the one you have and a relay plus stop valve.
    Hope you can help

  • Crystal Bekkers

    How to change this program to make it work with the NodeMCU board? I tried every pin combination possible but can’t seem to make it work…
    Do you by any means have a solution to make this work on the nodeMCU 0.9 board?

  • Ganapati

    As you shown in video, we have the water flow rate, but how can we calculate how much water consumed?

  • Scalde

    HI thanks for this info, any ideas on how i can add a second flow meter to this script using an UNO? thanks

  • Michael

    Hello all, I am trying to get the output of the flowmeter to print out to a tiny printer. I am unsure of where to put the code or even what code I should use. I am new to this stuff and Extremely bad at programming. Any help is appreciated! Happy new year, and thanks!

  • Md. Nasimul Haque

    Hi Arvind Sanjeev,
    This tutorial is great. It will be very useful for me. I have some questions. Kindly solve my issue .
    1. Can I use this sensor to detect diesel flow rate?
    2. Diesel engine pump takes diesel from tank uses a portion of it and sends the remaining diesel through the overflow pipe. I need to use two sensors to find out the fuel consumption and display it to 16*2 LCD.
    I want to use Arduino Mega2560 .
    Thank you.
    Nasimul haque

    • OldWiseMan

      Hello Nasimul,

      The old wise man says use the power of subtraction to solve your problem.
      Subtraction is a mathematical operation that represents the operation of removing objects from a collection. It is signified by the minus sign. For example, there are 5 − 2 apples—meaning 5 apples with 2 taken away, which is a total of 3 apples. Therefore, 5 − 2 = 3.

  • Shri

    The above hack works. Now i want to post the sensor data using the ESP8266 wifi module to a web server. How can i achieve this, the data should be sent 10 times in a minute. I really want to try this on my own, but the ESP8266 module is tricky and sometimes can dmg the module and the UNO. So i don’t want to take the risk of dmging both.
    Can anyone help me this stuff. Thanks in advance.

  • Kenneth

    Sir, I am using Arduino Uno, flow sensor (YF-S20) and a relay. Need to open/close the relay when the flow sensor reaches a reading of 1 liter. I used your code and it works perfectly with my flow sensor. But now I am trying to play the code to my project using the relay to open/close but i don’t know how to link the code regarding the sensor and the relay. Can you please help me to finish my project. Please send me the right code for my project. Thank you!!!

    • Ray Abad

      Try this code put your button on pin 4 and relay on pin 5
      Liquid flow rate sensor -DIYhacking.com Arvind Sanjeev Measure the liquid/water flow rate using this code. Connect Vcc
      and Gnd of sensor to arduino, and the signal line to arduino digital pin 2.
      byte statusLed = 13;
      byte sensorInterrupt = 0;
      // 0 = digital pin 2
      byte sensorPin = 2;
      int val = 0;
      // put your button on pin 4
      int startpin = 4;
      // The hall-effect flow sensor outputs approximately 4.5 pulses per second per
      // litre/minute of flow.
      float calibrationFactor = 4.5;
      volatile byte pulseCount;
      float flowRate;
      unsigned int flowMilliLitres;
      unsigned long totalMilliLitres;
      unsigned long oldTime;

      void setup() {
      // Initialize a serial connection for reporting values to the host
      // Set up the status LED line as an output
      pinMode(statusLed, OUTPUT);
      // put your relay on pin 5
      pinMode(5, OUTPUT);
      pinMode(startpin, INPUT);

      digitalWrite(statusLed, HIGH);
      // We have an active-low LED attached
      pinMode(sensorPin, INPUT);
      digitalWrite(sensorPin, HIGH);
      pulseCount = 0;
      flowRate= 0.0;
      flowMilliLitres = 0;
      totalMilliLitres = 0;
      oldTime = 0;
      // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
      // Configured to trigger on a FALLING state change (transition from HIGH
      // state to LOW state)
      attachInterrupt(sensorInterrupt, pulseCounter, FALLING); }
      /** * Main program loop */

      void loop()
      // fill button start if relay turn off
      if (digitalRead(5)==LOW)
      {val = digitalRead(startpin);
      digitalWrite(5, val);}
      if((millis() – oldTime) > 1000)
      // Only process counters once per second
      // Disable the interrupt while calculating flow rate and sending the value to
      // the host
      // Because this loop may not complete in exactly 1 second intervals we calculate
      // the number of milliseconds that have passed since the last execution and use
      // that to scale the output. We also apply the calibrationFactor to scale the output
      // based on the number of pulses per second per units of measure (litres/minute in
      // this case) coming from the sensor.
      flowRate = ((1000.0 / (millis() – oldTime)) * pulseCount) / calibrationFactor;
      // Note the time this processing pass was executed. Note that because we’ve
      // disabled interrupts the millis() function won’t actually be incrementing right
      // at this point, but it will still return the value it was set to just before
      // interrupts went away.
      oldTime = millis();
      // Divide the flow rate in litres/minute by 60 to determine how many litres have
      // passed through the sensor in this 1 second interval, then multiply by 1000 to
      // convert to millilitres.
      flowMilliLitres = (flowRate / 60) * 1000;
      // Add the millilitres passed in this second to the cumulative total
      totalMilliLitres += flowMilliLitres;
      unsigned int frac;
      // Print the flow rate for this second in litres / minute
      Serial.print(“Flow rate: “);
      // Print the integer part of the variable
      // Print the decimal point
      // turn on pin 3 if flowrate is greater than 4

      // Determine the fractional part. The 10 multiplier gives us 1 decimal place.
      frac = (flowRate – int(flowRate)) * 10;
      Serial.print(frac, DEC) ;
      // Print the fractional part of the variable
      // Print the number of litres flowed in this second
      Serial.print(” Current Liquid Flowing: “);
      // Output separator
      // Print the cumulative total of litres flowed since starting
      Serial.print(” Output Liquid Quantity: “);
      // Output separator
      // check if flow volume is > 1 litres
      if (totalMilliLitres > 1000)
      // reset volume to zero
      // Reset the pulse counter so we can start incrementing again
      pulseCount = 0;
      // Enable the interrupt again now that we’ve finished sending output
      attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
      /* Insterrupt
      Service Routine
      void pulseCounter()
      // Increment the pulse counter
      pulseCount++; }

      • Kenneth

        It works!!! Thank you so much. Is it possible to link a universal coin acceptor or coin slot to this code using multiple coins? I am using CH 923 https://www.sparkfun.com/products/11719 .

        • Ray Abad

          1. insert your coin code to get ‘coinsValue’
          2. then code the formula dispenseVol=rate*coinsValue where rate is how much you like to sell per cent
          example if 1 liter cost 50 cents then divide 1000 ml by 50 so your rate is 20

          int rate = 20
          int dispenseVol = 0

          inside the loop after to get the coinsValue
          dispensVol = rate*coinsValue;

          3. replace this code:if (totalMilliLitres > 1000)
          by this code: if (totalMilliLitres > dispenseVol)

          4. reset dispenseVol and coinsValue to zero

          happy coding

  • magdi

    Dear All,

    Kindly, I want failure rate for different control systems components (sensors, valves, switshes, pumps, etc

  • theophilus wiznar

    i had a problem to interface water flow meter sensor to arduino in simulation. since i didn’t get water flow sensor library in arduino. please tell how can i do?

  • rinku

    Sir. I am making a project with water flow senser (hall effect base) and 16*2 lcd
    Want to calculate total volume of water flow
    But i want use only atmega328pu ic..(programed via arduino uno) ant make new pcb with neccesory componet and thing…
    Help me in coding

  • Nathan Gant

    Thanks, Arvind, for the excellent Arduino sketch. I tested my flow sensor using your software code, and came out with the following 11 data points:

    3.5 13158
    3.6 12118
    3.625 12204
    3.73 11626
    3.75 11492
    3.76 11554
    3.8 11188
    4 10977
    4.04 11546
    4.33 10309
    4.75 8907
    pulses Milliliters

    Regression line equation: y=22405-2830.266x

    So based on above linear equation, the best K value (pulses per liter) to use in the Arduino sketch for this particular flow sensor would be 4.012. That would give me the closest number for metering, with some built-in mechanical variance from the flow sensor.

    • Nathan Gant

      Bivariate data from flow sensor #2:

      4.0 11824
      4.012 10920
      4.025 11345
      4.06 10411
      4.08 11939

      Data from this flow sensor appears to be randomly scattered. Also I rejected one data point, 4.0175, because I was getting over 20 liters and on a second run, over 30 liters, that’s far more than the bucket capacity of 11.053 liters. I did notice the signal pin next to the 10k resistor was loose, so next time I’ll start soldering the connections to eliminate that possibility. I don’t know if having a 4th decimal point in the K pulse value 4.0175 made a difference, there may be other factors causing the output to show excess flow.

      This demonstates a good reason to test your water flows before moving on to the next step.

      Sample size: 5
      Mean x (x̄): 4.0354
      Mean y (ȳ): 11287.8
      Intercept (a): 14420.271184913
      Slope (b): -776.24800141568
      Regression line equation: y=14420.27-776.248x

      So this particular flow sensor would apparently want a factor of about 4.33 to give me an accurate flow rate, a little higher than previous sensor (4.012).

      Also, for the stats, I used


      because it was very easy to cut and paste my data set into their site.

      • JuN

        Bro, do you follow all the coding and sensor type as what the website taught?

  • Mike Petterson

    When you say “In this arduino flow rate sensor, for every litre of liquid passing through it per minute it outputs about 4.5 pulses”
    Are you using the YF-S201 sensor as shown in the pictures?
    If yes, then shouldn’t the correct value be 7.5 as stated in the data sheet?

  • Agenda Généticien

    Hi, i believe that i noticed you visited my site so i came to return the desire?.I’m trying
    to to find things to improve my website!I suppose its adequate
    to make use of some of your ideas!!

  • abhilash

    im using the same sensor for my project.im getting the out when i compiled the code on aurdino uno but when i executed the same code on the intel galileo gen 2 im getting the output has 0.can anyone help me hoe to sort out this problem

  • Justine Fuentes

    What if you wanted to measure alcohol inside of a non-alcoholic beverage? How can we program this?

  • avinashjakkuva

    How can u connect to raspberry pi which doesn’t have a digital pin how will u connect to it

  • Emir Porcil

    Sir, I need help! I test the water flow sensor(model: YS-S201) with your program code then I use the faucet as the source of water to fill an empty 6.6 L empty bottle. After filled the bottle I checked the serial monitor then I found out that the output liquid quantity is much higher than water filled in the bottle which is a large amount of error. What can I do to fix this? I used a PVC pipe attached with the sensor and the faucet.

  • Jeff Nyika

    Hi, so I have 2 flow sensors similar to this and Im trying to use them at the same time, connected to an arduino.
    Im not a pro with arduino so wanted to find out if it is possible to use 2 sensors hooked to the same arduino to measure different places?
    thanks for a response in advance

    • Fong

      Brother, did you solve your problem with two sensors? Do you mind to share with me how you complete such as coding and schematic diagram because I am doing the same project with two sensors. I would appreciate if you lend a helping hand.

  • Andre

    Really nice-work ;)
    Have a quastion about the code though, if I wanted to change the time interval what would have to change?

    I’m guessing it’s just changing the 1000 (miliseconds) for another value, right?

  • Clay

    Excellent writeup! I was able to get the code to work on the Uno, but it doesn’t work on my Yun. I know it’s something to do with the PIN mapping. Could you help? The interrupt routine is not getting fired. I have the wiring the exact same.

    • Julio

      Hi Clay Did you figure it out what happens? Also have issues with yun Instead of using serial i use console to read values over the wifi It just print zero when the yf s201 is working I really dont know what to do

      • sylvain

        Hi guys,

        I have a Yun as well. The mapping for Digital pins to Interrupt pins is different on the Yun. Mine works using Interrupt 1 instead of 0. The only bit of code to change is: byte sensorInterrupt = 1; // 0 = digital pin 2

  • Vijayanand

    can we connect this flow sensor to allen bradley plc, which has only digital input and output. urgent

  • David B

    Is there a device that will also show me the direction of the water (e.g. negative voltage?)

  • Aaron

    Hi Arvind,

    I was wandering how you knew that this particular sensor creates 4.5 pulses per litre because I am using a slightly different sensor and to get true values of liquid output from your code, I had to change the calibration factor from 4.5 to 65 (sixty five) by trial and error and was wanting to know if there was a more logical process to modifying your code to suits the specs of the flow sensor I am using?


  • vishal

    hey arvind i want to monitor whether water is flowing or stagnant through a pipe not the quantity of water flowing can i do that using this flow rate sensor if so where can i find the code??

  • daniel patterson

    I am building an aquarium control unit and have most of the code, now im adding the 2 flow meters and it is plowing my mind any help would be greatfull.

  • Shubham chhatre

    Arvind sir,
    i want to turn on or turn off the flow of water depending upon the sensor value. how we can write program for that condition?

    • Daniel patterson

      i have 2 meters and it is killing me on getting them into my current code any help would be helpfull

  • Miguel

    Hi Arvind,

    Thank you for the tutorial.

    I’m using a different sensor but am getting irregular readings even though I have a constant flow (I’m using air, not water).

    I can see that the sensor is giving me a constant square wave but my reading keep varying, about 30% up or down.

    This is the sensor:

    Any suggestions would be greatly appreciated.

    Kind regards,


    • Ana

      We are doing a similar project and we want to add in an LED indicator light for when a certain amount of water flows through the sensor. Do you have code to do that?


      • rebin

        also i need this led!
        did you find ? can i see your project?

    • ANDREW

      Is it possible to correct for the inaccuracy of the meter with the code?

  • love vegetables

    How many flow meters could theoretically be attached to a single Arduino? What considerations would I have to make?
    thank you

  • horoscopo gratis escorpio

    Thanks for every other fantastic article. Where else maay anyone get that kind
    of info in such a perfect means of writing? I have a presentation subsequent week,
    and I am at the lopok for such information.

  • swanand

    Hello sir,

    can you please provide me the code to interface the sensor with 8051 ucontroller.

  • chloe

    Hello everyone, can someone give an advice about what is important/advantages to know the flow rate of water?
    instead of to gardening, why we must control the flow rate…please, give an opinion..

    • Muhammad Ali

      my dear friend by controlling water flow you can make automatic system for watering the garden, you can fill constant quantity of liquid in bottles/cans/anything, these are some very basic examples , there are many magics happening with water flow rates

  • udin

    Hello sir,
    Im wondering, based on the sensor datasheet, the flow-pulses for 2L/minute= 16 Hz, so, what is the output voltage for 16Hz frequency?

  • udin

    Hello sir,
    Im wondering, based on datasheet
    it was flow- pulse for 2L/min=16hz, what is the voltage for 16hz?

  • Rahul

    Greetings friend.
    I created a similar system with flow sensor DN32 and I have very irregular readings is very unstable.
    You know how to improve the stability of measurement readings.
    I am measuring the fall of flow and for some reason my system is very unstable.
    If you know how to improve presicion of readings.

    • Craig Larson

      Rahul and others above with calibration problems: The datasheet, or something else I read, specified that the meter needed to be installed within 5 degrees of horizontal. Maybe this is the calibration problem? The hack shown here has the meter at 90 degrees to the horizon. I can’t figure out why this would matter since the hall sensor should be indifferent to gravity. And the flow should be indifferent to gravity.

  • ratnesh

    thank you sir. I am using water flow sensor model YF-S201 having a different calibration factor than yours.What modification is required in the code, also how one can measure rpm of the rotor.

  • Erik

    Is the totalMilli keeping track of the total amount of water in mL flowed through for just that one measurement cycle or for the entire time the unit is turned on? If I wanted to keep track for the total amount of water flowed through, for an entire day perhaps, how would you suggest this be done?
    Many thanks!

  • Matt

    Hi thanks for the great tutorial. I was wondering if you could explain how one would interface this with a LCD display. And would there be any reason that you couldn’t do a conversion in code to make the displayed value gal instead of liters? Thanks.

    • Arvind Sanjeev

      Hi Matt,
      Please check this tutorial: http://diyhacking.com/arduino-lcd-tutorial/ this will help you :)

      • Matt

        Hi Arvind,

        Thanks – your tutorials worked perfectly. I now have a UNO running a flow sensor and displaying results on my 20×4 lcd. Couple more questions if you don’t mind. How could I convert the l/min to gallons? And could you suggest a way to keep a running total of the fluids used? I’m trying to monitor how much rain barrel water we are using annually to water our garden. Sorry for the “entry-level” questions but I am very new to this. Thanks -Matt

        • Arvind Sanjeev

          1 L = 0.26 Gallon, you would have to convert it using this formula. And to store the total amount of fluid, you would have to save the data in EEPROM. Check for arduino EEPROM tutorials: http://www.arduino.cc/en/Tutorial/EEPROMWrite

  • amar mehdi

    void open_valve() {

    digitalWrite(RELAY_A, HIGH); // turn RELAY_A on
    // Serial.println(“Valve Open”);

    void close_valve() {
    digitalWrite(RELAY_A, LOW); // turn RELAY_A off
    // Serial.println(“Vavle Closed”);

    sir, this part of code I did’nt underatand ? for what purpose it has been used?

  • januar

    can you help me if i want to display output from sensor to web (chart) by using php

    • Arvind Sanjeev

      Read the data from the serial port of the computer and have a script which posts that to a webpage. Integrate serial communication and http modules for this, you can use python.

  • amar mehdi

    i,m using the same sensor as you use YF-S201. can you show your formula of converting of counts to ml/minute or hour as u did in your video.
    because rpm=rpmcoun*60/4.5 does not work correctly.

    • Arvind Sanjeev

      Please check the source code on the final step of this tutorial.

  • amarmehdi

    sir, you said that solenoid valves control the flow but you did not use any solenoid valve in your video.
    i,m asking about open and close valve function that you use in your code.for what purpose they are used.thanks

    • Arvind Sanjeev

      Please highlight the code you want me to explain, I dont think I have used any open/close valve commands there.

      • Kenneth

        Sir, I am using Arduino Uno, flow sensor (YF-S20) and a relay. Need to open/close the relay when the flow sensor reaches a reading of 1 liter. I used your code and it works perfectly with my flow sensor. But now I am trying to play the code to my project using the relay to open/close but i can’t fix it. Can you please help me to finish my project. Thank you!!!

  • Chuck Colby

    hey Arvind. I have been reading your work and find it interesting for sure. I’m looking to measure the volume of air flow through a tube of air flow traveling at 15 LPM. The goal is to control a pump to allow “x” amount of air through the pipe and then shut off the pump. Why i can calibrate the pump and control the time that the pump runs, then infer the air volume from those numbers, the pumps are not consistent and don’t necessarily run at 15 lpm all the time. Therefore, the ability to actually measure the volume would be ideal.. Do you think your above project would measure air volume?



    • Arvind Sanjeev

      Hi Chuck, Ideally it should. This sensor consists of a simple propeller like system, which turns when water/air hits its blades. Dont know about the accuracy, but the output from the sensor would be definitely proportional to the input air/water. Would suggest you go by with a trial & error approach.

    • Arvind Sanjeev

      Solenoid valves can control the flow of water based on the sensor data. Can you explain in detail what you want to know?

  • Ratnesh

    Which Arduino you has used kindly tell me how to buy it in india. How you run the software on windows 8 to measure flowrate

    • Arvind Sanjeev

      You can use arduino Uno. If you are new to arduino, please download this free eBook, it will help you: http://diyhacking.com

      • ratnesh

        thank you sir. I am using water flow sensor model YF-S201 having a different calibration factor than yours.What modification is required in the code, also how one can measure rpm of the rotor.

  • yunus

    hye..i want to ask.. i have problems with sensor flow rate.. i want to make the sensor have to dectect flow rate of fluid. if the sensor low than 2ml/min it will close the pump. did you have any idea or any link to refer

    • Arvind Sanjeev

      You can use a relay to control the pump based on the output of the flow rate sensor (simple if/else statements).

  • dayang madsiana

    hai, I want to ask about the program. How you program it?

  • Guillaume

    I have a problem about the display of the flow, when i run your code there is no information printed on the serial monitor :/ do you know where is the mistake?
    I have the Water flow sensor yf-s201 and im connected on the good COM (COM17 for me)
    And sorry for my english i’m french ;)

    • Arvind Sanjeev

      I think there might be some connection problem. Why don’t you try printing something on the serial monitor and check.

  • Viswa Devan

    Hi Arvind,

    Can i know what is your sensor output?
    Can i try out the code with using a 4mA-20mA output from sensor?

    I’m currently doing a project where i can measure air flow so i can estimate my savings i’ll get by savings air consumed by my tool.

    Thank you very much…

    • Arvind Sanjeev

      Hey, all the info is in the tutorial :)

  • Shaun Reed

    Hi Arvind,

    Your code works great! While I’m measuring flow, I activate my valve, which disrupts the flow measurements. I think this is due to the interrupt of the flowmeter being disrupted. As you suggested above, how do I modify your program to use a digital pin, say pin 4 or 7, instead of pin 2.


    • Arvind Sanjeev

      Hi Shaun,
      I fail to understand how the activation of a valve affects the interrupt? Also, why don’t you try the other interrupt pin 1 (digital pin 3).

  • Fabio

    Hi Arvind, I used your code on a Arduino nano 3.0 and it worked perfectly; after I used the same code on an Intel Galileo: the ide compiles the code but it isn’t able to read to measure from the sensor. Any suggestion?
    Thank you very much

    • Arvind Sanjeev

      Hello Fabio,
      Have you used the same sensor on the galileo? And also check the wiring connections for it, and whether the pin number for the arduino program matches that of the galileo.

  • Ali

    good day Arvind and thanks for this

    the displayed out put is ony line of squares, unreadable simples.

    what is the port setting you used?

    • Arvind Sanjeev

      Hello Ali, I used a baud rate of 38400.

  • Sukanya

    Great Aravind!
    Can you please help how to use this code in ARM cortex3.This is little urgent for me.
    Thanks in advance.

    • Arvind Sanjeev

      Hello Sukanya, you would probably have to port the corresponding functions used here. You just need to write a piece of code that reads the digital data from a pin on your controller.

  • Ali

    Hi Arvind Sanjeev
    do I need to attach any thing to the arduino except the wire connection of the sensor and the labtop?

    • Arvind Sanjeev

      Nothing else, I guess.

  • Sean

    Hey your code worked great. I appreciate it. If i wanted to output the data to .csv file how could do that? instead of a com monitor.
    Thanks for the help

    • Arvind Sanjeev

      Hello Sean, if you want to output your data to a csv file, I would recommend writing a python script which reads values from the serial port (Arduino) and writes it into a text file in the form of CSV.

  • JV

    Hi Arvind Sanjeev,
    can I use multiple flow meter in one arduino? what will be the configuration of connections? what will be the configuration on the program that you used?

    • Arvind Sanjeev

      Hello, this program uses the arduino external interrupt pin (digital pin 2) and since there are only 2 interrupts on the arduino, you can use two of these sensors for this program at the same time. However, you can also edit this program to add the desired number of sensors by simply connecting them to the digital pins.

  • Ashok

    hi Arvind sanjeev,
    how to convert the code to Raspberry pi? Please help me

  • Donald

    Hey, thanks for the video! I am using the adafruit sensor, but when I used your code, there is no printed information on the screen. Do I need to change some settings?

    • Arvind Sanjeev

      Hello Donald, can you please share the link to your sensor? I am using another China made sensor for measuring the flow rate.

  • Faiz Wahyudi

    please check baudrate setting.

  • Syazwan

    Good days sir.. I try to upload the sketch to my arduino UNO and run it. I can’t find the result as what you get sir. Im using G1/4 Flow Rate sensor.. Can you help me..

    • Arvind Sanjeev

      What is the output being displayed on the serial monitor?

pingbacks / trackbacks

Leave a Comment

29 − = 20

Start typing and press Enter to search