Professional Documents
Culture Documents
Flow Sensor
Flow Sensor
Hardware Hook Up
Connecting the water flow sensor to arduino requires minimal interconnection. Connect the VCC
(Red) and GND (Black) wires of the water flow Sensor to the 5v and Gnd of Arduino, and link
Pulse Output (Yellow) wire of the water flow sensor to Arduino’s digital pin 2. Note that the
water flow sensor is not a power-hungry type; it draws a maximum of 15-20mA at 5V DC input!
Software Preparation
The Arduino Sketch (code) uses the external interrupt (int 0) on Arduino’s digital pin 2 (D2).
This is used to read the output pulses coming from the water flow sensor. When Arduino detects
the pulse, it immediately triggers the pulseCounter() function. This function then counts the total
number of pulses detected (wanna know more about
interrupts? h ttp://playground.arduino.cc/Main/AVR).
/*
YF- S201 Water Flow Sensor
Water Flow Sensor output processed to read in litres/hour
Adaptation Courtesy: www.hobbytronics.co.uk
*/
volatile int flow_frequency; // Measures flow sensor pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowsensor = 2; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interrupt function
{
flow_frequency++;
}
void setup()
{
pinMode(flowsensor, INPUT);
digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
Serial.begin(9600);
attachInterrupt(0, flow, RISING); // Setup Interrupt
sei(); // Enable interrupts
currentTime = millis();
cloopTime = currentTime;
}
void loop ()
{
currentTime = millis();
// Every second, calculate and print litres/hour
if(currentTime >= (cloopTime + 1000))
{
cloopTime = currentTime; // Updates cloopTime
// Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in
L/hour
flow_frequency = 0; // Reset Counter
Serial.print(l_hour, DEC); // Print litres/hour
Serial.println(" L/hour");
}
}
Flow sensors typically output a series of pulses proportional to the instantaneous flow rate which
means that to interpret them it is necessary to implement a simple frequency counter. Since this
project uses a water flow sensor containing a Hall-Effect sensor that outputs a pulse rate
proportional to flow rate, so not only is it a useful project in its own right but it also demonstrates
a very useful technique that you can use in a wide range of projects that need to measure the rate
at which something happens (an electronic wind instrument, for example).
In other words:
Data sheet
This sensor sits in line with your water line and contains a pinwheel sensor to measure how much liquid has moved
through it. There's an integrated magnetic hall effect sensor that outputs an electrical pulse with every revolution. The
hall effect sensor is sealed from the water pipe and allows the sensor to stay safe and dry.
The sensor comes with three wires: red (5-24VDC power), black (ground) and yellow (Hall effect pulse output). By
counting the pulses from the output of the sensor, you can easily calculate water flow. Each pulse is approximately
2.25 milliliters. Note this isn't a precision sensor, and the pulse rate does vary a bit depending on the flow rate, fluid
pressure and sensor orientation. It will need careful calibration if better than 10% precision is required. However, its
great for basic measurement tasks!
We have as example Arduino sketch that can be used to quickly test the sensor, it will calculate the approximate flow
of water in liters/hour.
The pulse signal is a simple square wave so its quite easy to log and convert into liters per minute using the following
formula.
Features:
● Model: YF-S201
● Sensor Type: Hall effect
● Working Voltage: 5 to 18V DC (min tested working voltage 4.5V)
● Max current draw: 15mA @ 5V
● Output Type: 5V TTL
● Working Flow Rate: 1 to 30 Liters/Minute
● Working Temperature range: -25 to +80℃
● Working Humidity Range: 35%-80% RH
● Accuracy: ±10%
● Maximum water pressure: 2.0 MPa
● Output duty cycle: 50% +-10%
● Output rise time: 0.04us
● Output fall time: 0.18us
● Flow rate pulse characteristics: Frequency (Hz) = 7.5 * Flow rate (L/min)
● Pulses per Liter: 450
● Durability: minimum 300,000 cycles
● Cable length: 15cm
● 1/2" nominal pipe connections, 0.78" outer diameter, 1/2" of thread
● Size: 2.5" x 1.4" x 1.4"
Connection details:
Documents
YF-S201 Datasheet
Example Arduino Code