Smoothening flow sensor output

Hi experts,

I am using a flow sensor to measure the flowrate of my pump. It does not give me consistent value and bounces intermittently. Is there anyway I can filter the bouncy values ?

this is my code:

volatile int noRisingEdgeTopsFan;                       
float flowLPM=0.00;
float flowOzM=0.00;
#define factorOz 33.814   //for litre to ounces. 
#define sensorInput 2    // arduino pin                       
 
 
void rpmRW ()                                   
{
    noRisingEdgeTopsFan++;                              
}
 
void setup()
{
    pinMode(sensorInput, INPUT);               
    Serial.begin(9600);                               // Keep the same value in Serial Monitor                   
    attachInterrupt(0, rpmRW, RISING);          
}
 
void loop ()
{
    noRisingEdgeTopsFan = 0;                            
 
    sei();                                            //interrupt enabled                                  
    delay (1000);                                     //delay                        
    cli();                                            // interrupt cleared                             
   
    flowLPM = float(noRisingEdgeTopsFan)/11;          // datasheet F= (11*Q)+/-3%   
    flowOzM = factorOz* float(flowLPM); 

    Serial.print("Pulses:");
    Serial.print (noRisingEdgeTopsFan); 
    Serial.print("\t");
    Serial.print (int(flowOzM)); 
    Serial.print (" Oz/min\r\n");             
}

and my Serial monitor

Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation of your ask).
(I provided the code tags for this time)


seems you get only a delta of 1 pulse which leads to the change you see... probably 1s is too short to have a good measure.

A frequent way to smooth out values is taking x% of the previous value and (1-x%) of the current one.
Depending how you choose x, you'll favour the sensibility to the new value or the history

for example (90% x previousValue + 10% currentValue) will be taking the new value impact just for a bit, so will be "slow" to react to changes

The results you are seeing may be the results from the type of pump you are using.
Paul

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.