Regarding measuring the quantity of liquid

i am a mechanical engineer. i have very very little knowledge of coding . i want that after 100 ml, flow

sensor should send signal to pump to stop so that i could get 100 ml.

For this purpose i have Arduino Uno R3 ATmega 328 board and flow sensor Yf-S201.

So i want the code which will run for this purpose

Please help me

satishsv006:
So i want the code which will run for this purpose

The premise is that you make an attempt first. That is, write some code and test it. If it doesn't do what you want, then ask here. Before posting read the 'how to use this forum' sticky at the top of this topic, especially about how to post your code.

If you just want it done there is a 'gigs & collaboration' topic where you can solicit someone to develop the code for you - at a price.

This might get you started...

after 100 ml, flow sensor should send signal to pump to stop so that i could get 100 ml.

That's half a cup.... Tiny amount really.

By definition of "after" it's already too late, and depending on your mechanical design and layout you may still get an extra "pipeful" so to speak delivered.

I see here that the meter works between 1 and 30 L/min. For 0.1L that's going to be between 6 seconds (slowest) and 0.2 seconds (fastest).

Even at 6 seconds, will your pump shut off fast enough to prevent getting way too much liquid?

But in theory you can count 450/10 = 45 pulses and turn the pump off, that's easy.

Maybe you need a peristaltic pump?

A peristaltic pump, running time based, gives a very accurate dose. They tend to be quite slow, though - the fastest I have do about 80 ml/min. Surely there are faster ones around.

Alternative: regular water pump (use a fairly slow one) and a scale under the cup. Cut off the pump just before the 100 ml (about 100 gr depending on your liquid) to allow for reaction times, experiment to get this right. The slower the pump the more accurate you will be able to get.

Other alternative: syringe with linear actuator. Possibly the most accurate and reproducible of the setups but requires more complex hardware. Use two one-way valves and you can suck liquid in from your reservoir and expel it into your output container.

Right now i am checking my sensor either it is working properly or not. i used the codes which i got from

internet for flow sensor. I connected the yellow wire of flow sensor with Pin 2 on Arduino Board , red

wire to 5V power pin and black wire GND. When run these codes, it is giving 0 L/hr every time either

flapper of sensor rotates or not.

Please tell why it is happening

I already mentioned that i have no programming experience

int flowPin = 2;
double flowRate;
volatile int count;

void setup() {
pinMode(flowPin, INPUT);
attachInterrupt(0, Flow, RISING);
Serial.begin(9600);
}
void loop() {

count = 0;
interrupts();
delay (1000);
noInterrupts();
//Start the math
flowRate = (count * 2.25);
flowRate = flowRate * 60;
flowRate = flowRate / 1000;

Serial.println(flowRate);

void Flow()
{
count++;
}

What part of

Before posting read the 'how to use this forum' sticky at the top of this topic, especially about how to post your code.

Did you have trouble understanding?

As posted, it won't compile anyway. Your loop() isn't closed.

  Serial.println(flowRate);      
} //<<<<<<<<<<<<<<<<<<<<<< needs this
void Flow()

(Probably a copy/paste error into the forum though?)

So did you try the code I linked in #2?

i used the following codes. And it is giving 0 L/hr on my serial monitor every time either flapper rotates or not. But when i pulled out the signal wire it is giving some reading like of 2.33 L/hr, which is incorrect.

Please tell me, this code is wrong or my sensor is not working properly.

i saw on internet, users are getting some value with this code but i am not getting?

int flowPin = 2;   
double flowRate;    
volatile int count; 

void setup() {
  pinMode(flowPin, INPUT);          
  attachInterrupt(0, Flow, RISING); 
  Serial.begin(9600);
}
void loop() {
   
  count = 0;      
  interrupts();  
  delay (1000); 
  noInterrupts();
  //Start the math
  flowRate = (count * 2.25); 
  flowRate = flowRate * 60;  
  flowRate = flowRate / 1000;

Serial.println(flowRate);     
 
}

void Flow()
{
   count++;
}

What you can do is to get a cup that holds 120 ml and put two input pins at the 100ml point. One of the pins is a digital input pulled low by say a 100k resistor. the other would be 5v. When the liquid level reaches 100ml the liquid shorts the 5v to the input. The pump is stoped and a solenoid opens to empty the cup.

I don't know what liquid you are measuring but you should check that the pulldown resistor has the right value for the conductivity of the liquid you are trying to meter. 10K worked fine for me on spring water but will be to low for methanol wich has much lower conductivity.

A more elegant solution would be to ditch the solenoid and instead use a pythagoras cup. You would probably have to make it yourself but i think the simplicity of the solution is quite nice.

Edit: As mentioned above you should use a smaler pump because this one is designed for 1 - 30L/m.

void loop() {
   
  count = 0; 
//     
// other code
//

{
   count++;
}

These two things are working at cross purposes.

You might look at this article to get you started.

yf-s201-arduino-interface

As for the code, before you write any code you must understand the exact steps that need to be performed, in excruciating detail.

It might help if you drew a flow chart of the steps the code must perform.

JohnRob:
You might look at this article to get you started.

yf-s201-arduino-interface

Been there, done that.... see #2

elvon_blunden:
This might get you started...

RippoZero:
the liquid shorts the 5v to the input.

You really like risks of shorts, don't you? Because that's why we always switch to GND.

And a pythagoras cup is a nice idea but doesn't give you specific shots. It'll pour until you shut off the inflow...

wvmarle:
You really like risks of shorts, don't you? Because that's why we always switch to GND.

I live for danger