Hello fellas, I write this looking if I can get help for a project i'm making.
I wanna make an automatic liquid filler where you can input X liters to dispense, and the basis for measuring volume will be a hall effect flow meter (YF-S201 in my case).
So, as a first major step I wanted to dispense exactly 1 liter, but I've ran into a hair pulling problem, the sensor, according to the datasheet, sends a certain amount of PWM pulses depending on the flow, measuring the flow of my pump manually, I get around 4.3 Litres per minute, however the output pulses of the sensors are all over the place, for the flow I measured, I should be getting around 40-50 pulses per second. On this pic I recorded some pulses per second readings on the serial monitor, and as you can see, they're definitely not lining up to the real flow.
This makes the arduino code detect a liter way faster than intended, making me only get about 400-700 ml of real liquid served.
I've already tried several code approaches to measure water flow through the flow meter pulses, and I also doble checked all my connections. I tried to buy a replacement flow meter, but the problem persists, so i'm all out of options here.
Here is a drawn circuit diagram of my project so far, hope it helps, also, here is one of my builds, it's messy for now, wanted to make it a lot more clean once I get it working.
And here is one of my versions of the code for getting the volume thru the flow readings. This one was made for recording the pulse readings but same principle as other versions, polling the flow meter for a certain amount of time and getting the current flow and volume values.
volatile int NumPulsos; //Variable for measuring pulses
int PinSensor = 2; //Sensor connected to pin 2, interrup pin on UNO
float factor_conversion=7.5; //Conversion factor from YF-S201 datasheet
float volumen=0;//Se inicializa la variable de volumen
long dt=0; //variación/diferencia de tiempo por cada repeticion
long t0=0; //millisegundos pasados despues de repeticion anterior
int PinBoton = 7; //Pin for polling the trigger button
int PinBomba = 8;//Pin for pump activation via relay
int LEDpin = 13;
void ContarPulsos () //Interrup routine for when a pulse is received from the flow meter
{
NumPulsos++; //incrementamos la variable de pulsos
}
int ObtenerFrecuecia() //Function for calculating frequency
{
int frecuencia;
noInterrupts();
NumPulsos = 0; //Pulse numer is reset
interrupts(); //Enable interrupts
delay(1000); //We poll the flow meter for 1 second
noInterrupts(); //Disable interrupts
frecuencia=NumPulsos; //We register the number of pulses on 'frecuencia'
return frecuencia;
}
void setup() //Funcion de configuracion inicial
{
Serial.begin(9600);
pinMode(PinBomba,OUTPUT);
pinMode(PinBoton,INPUT_PULLUP);
pinMode(LEDpin,OUTPUT);
attachInterrupt(digitalPinToInterrupt(2),ContarPulsos,RISING);//Se declara la interrupcion al pin 2 (indicado como 0), la funcion que se ejecutara en la interrupcion, y que reaccionara hacia un flanco hacia arriba
//Serial.println ("Para reiniciar el contador de litros envie una 'R' en serial monitor");
t0=millis();//Se inicializa t0
digitalWrite(PinBomba,HIGH);
}
void loop ()
{
// if (Serial.available()) {
// if(Serial.read()=='r')
// volumen=0;//Se restablece el volumen si recibimos 'r'
// }
if(digitalRead(PinBoton) == LOW){ //Poll the pushbutton
digitalWrite(LEDpin,HIGH);
delay(500);
}else{ //When the button is pressed
do{ //Loop for checking volume and update the flow
digitalWrite(PinBomba,LOW);
digitalWrite(LEDpin,LOW);
float frecuencia=ObtenerFrecuecia(); //We get our pulse frequency
interrupts();
float caudal_L_m=frecuencia/factor_conversion; //Flow is calculated in L/m
dt=millis()-t0; //We calculate time difference
t0=millis();//t0 is reset
volumen=volumen+(caudal_L_m/60)*(dt/1000); // volume(L)=flow(L/s)*time(s)
Serial.println(frecuencia); //For testing purposes we only output the current pulse frequency
}while(volumen < 1); //When the volume reaches 1 liter, stop the filling process
digitalWrite(PinBomba,HIGH);
digitalWrite(LEDpin,HIGH);
volumen = 0;
delay(1000); //We wait 1 second before we can trigger the pump again
}
}
Thanks for reading!