Example Code for Arduino-Measure Liquid Flow

In this Tutorial, we'll measure liquid flow using this sensor.

Hardware Preparation

DFRduino UNO R3
Water flow sensor
Jumper Wires

Software Preparation

Arduino IDE, Click to Download Arduino IDE from Arduino®

Wiring Diagram

SEN0216 Gravity: Digital Water Flow Sensor For Arduino Connection Diagram

Sample Code

/*!
 * @file  SEN0216.ino
 * @brief  This example reads Water flow sensor Sensor.
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @license  The MIT License (MIT)
 * @author  berinie Chen <[email protected]>
 * @version  V1.0
 * @date  2016-3-13
 */

/***********Notice and Trouble shooting***************
  1.This code is tested on Arduino Uno.
 ****************************************************/

volatile double waterFlow;

void setup()
{
  Serial.begin(9600);  //baudrate
  waterFlow = 0;
  attachInterrupt(0, pulse, RISING);  //DIGITAL Pin 2: Interrupt 0
}

void loop()
{
  Serial.print("waterFlow:");
  Serial.print(waterFlow);
  Serial.println("   L");
  delay(500);
}

void pulse()   //measure the quantity of square wave
{
  waterFlow += 1.0 / 5880.0;
}

Key Installation Notes:
Use with a 6 mm hose for optimal performance.
Avoid exposure to corrosive liquids or chemicals.
Install vertically with a tilt of no more than 5°.
Keep liquid temperature below 120°C to prevent damage.

Was this article helpful?

TOP