Flow sensor YF-S201

Hi everyone,

I don't understand the results from my sensor.
It works and gives me a result as L/h the pump is 1500L/h and Arduino (Yun) says I have 480L/h max, I think the formula is wrong but I need someone's help as I'm not good enough with maths..

Here my sketch, only the loop :

void flusso()
{
  NbTopsFan = 0;	         //Set NbTops to 0 ready for calculations
  sei();		         //Enables interrupts
  delay (1000);	                 //Wait 1 second
  cli();		         //Disable interrupts
 
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate 
                                 //in L/hour 
  Serial.print ("Eheim :                   ");
  Serial.print (Calc, DEC);      //Prints the number calculated above
  Serial.println (F(" L/hour\r\n"));  //Prints "L/hour" and returns a  new line

I'm afraid that you are going to have to apply some mathematics to the problem.

First, even if the pump is rated for 1500 L/h that is when it's going downhill with a tailwind. Anything attached to the outlet (like a pipe that goes uphill) will significantly reduce that flow rate. You may be getting the right answer.

Do you have anything else to measure the pulse frequency? Like an oscilloscope or frequency counter. Can you borrow one?

Can you show us the code for the interrupt?

Unfortunately I don't have anything else to mesure the flow.
I'm sure the flow will be reduce 'cause of the tube's length and the sensor itself, but this cannot explain the loose, this is too much.

I could just multiply by 4 the result to obtain something close to the result I expect, but I would like to understand what would be the right formula.

I am sure this is only a mathematical problem, but I don't know how to solve it!

Your formula looks correct according to the data sheet and other examples I have seen. I have also seen reference to 2.25 ml/pulse, and if you work back from that you get Freq x 8.1 = l/hr which is close enough to Freq*60/7.5.

To measure your flow, you can pump for a given period of time into a bucket and either weigh what you get, or empty it with a known smaller container. I'd be questioning the actual pump performance as much as the flow meter.

Please post more of your code. It would be best if you could just strip it down to the flow rate measurement if it does other things. The ISR, and how all the variables relating to flow rate are declared may be important.

My sketch

#include <DHT.h>                           //For DHT22 & AM2302 library
#include <OneWire.h>                       //For DS18B20
#include <LiquidCrystal.h>
#include <Bridge.h>
#include <HttpClient.h>

#define DHTPIN 3                           //DHT22
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float h = 0;
float t = 0;

const byte DS18B20_Pin = 4;                //DS18B20 Signal pin on digital 4
OneWire ds(DS18B20_Pin);                   // on digital pin 4

int Calc;                                  //Sensore flusso
volatile int NbTopsFan;                    //measuring the rising edges of the signal
int hallsensor;                            //The pin location of the sensor is 2 (int0 on Yun = Pin 2)
void rpm ()                                //This is the function that the interupt calls 
{ 
  NbTopsFan++;                             //This function measures the rising and falling 
                                           //edge of the hall effect sensors signal
} 

unsigned long ora = 0;
unsigned long ultimaEsecuzione = 0;
long intervalloEsecuzione = 10000;

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);


void setup()
{  
  pinMode(6, OUTPUT);                      //LED ROSSO ds18b20
  
  // ***For Flow sensor*****************************************
  pinMode(hallsensor, INPUT);              //initializes digital pin 2 as an input
  attachInterrupt(1, rpm, RISING);         //and the interrupt is attached
  // ***********************************************************
  
  // Bridge takes about two seconds to start up
  // it can be helpful to use the on-board LED
  // as an indicator for when it has initialized
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  
  Serial.begin(9600); 
  lcd.begin(16, 2);
  dht.begin();                             //DHT22
  
  while (!Serial); // wait for a serial connection

 }


void loop()
{
 ora = millis();
  
dht22();
ds18b20();
flusso();
//emoncms();
//emoncms_async();

//delay(1000);                              //just to slow down the output it's easier to read

}
void flusso()
{
  NbTopsFan = 0;	         //Set NbTops to 0 ready for calculations
  sei();		         //Enables interrupts
  delay (1000);	                 //Wait 1 second
  cli();		         //Disable interrupts
  
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate 
                                 //in L/hour 
  Serial.print ("Eheim :                   ");
  Serial.print (Calc, DEC);      //Prints the number calculated above
  Serial.println (F(" L/hour\r\n"));  //Prints "L/hour" and returns a  new line
  


}
1 Like

Your code has several problems which have been discussed previouslyhttp://forum.arduino.cc/index.php?topic=285091.0 but i do not see anything obvious as to why the flow rate would be 1/4 of expected. You will need to perform a calibration test to check the flowmeter and/or pump.

I tried a sketch with millis but I had the exact same result

can i exceed the maximum rating for this sensor? our pump is rated 60l/min.

hello guys need help!!!!!!!
I have to attach two hall effect sensors(YFS201) to one arduino, but I am facing a lot of problem with interrupt someone please help me out.

This is my code.....

volatile int NbTopsFan;
volatile int flowfrequency;
int Calc;
int value;
int hallsensor1 = 2;
int hallsensor2 = 3;

void rpm ()
{
NbTopsFan++;
}
void flow()
{
flowfrequency++;
}

void setup ()
{
pinMode(hallsensor1, INPUT);
pinMode(hallsensor2, INPUT);
Serial.begin(9600);

}

void loop()
{
yash();
neha();
}
int yash ()
{
NbTopsFan = 0;
attachInterrupt(digitalPinToInterrupt(2), rpm, RISING);
sei();
delay (1000);
cli();
Calc = (NbTopsFan * 60 / 7.5);
Serial.print (Calc, DEC);
Serial.print (" L/hour for first\r\n");
}
int neha ()
{
flowfrequency=0;

attachInterrupt(digitalPinToInterrupt(3), flow, RISING);
sei();
delay (1000);
cli();
value=(flowfrequency * 60 / 7.5);
Serial.print(value, DEC);
Serial.print (" L/hour for second\r\n");
}

Please don't hijack old, dead threads. Start your own by clicking the "report to moderator" and asking to be transferred to your own thread.

I am not surprised you have problems. Your code can't possible compile with calls to non-existant functions, and function names the same as variables.

Paul