Range narrowing function

Hello All,

I'm trying to crack my head open in order to get the code out of it but it seems to not want to leave my head.

I have a Flowsensor that is pulsing on the Analog port, it doesn't pulse 0 and 1023, no it's somewhere inbetween, most of the time there is 100 steps between the LOW and HIGH, but each session this value is different. Instead of manually typing in the values I see in the serial port I would like to automate this.

What I have now is:

void FlowCalculations(){
	if(analogRead(Flow1) > 380 && Flow1State == false){
		Flow1Count++;
		Flow1LongCount++;
		Flow1State = !Flow1State;
	}
	else if(analogRead(Flow1) < 380 && Flow1State == true){
		Flow1State = !Flow1State;
	}
	
	if(analogRead(Flow2) > 50 && Flow2State == false){
		Flow2Count++;
		Flow2LongCount++;
		Flow2State = !Flow2State;
	}
	else if(analogRead(Flow2) < 50 && Flow2State == true){
		Flow2State = !Flow2State;
	}
	
	if(analogRead(Flow3) > 370 && Flow3State == false){
		Flow3Count++;
		Flow3LongCount++;
		Flow3State = !Flow3State;
	}
	else if(analogRead(Flow3) < 370 && Flow3State == true){
		Flow3State = !Flow3State;
	}

	if (millis() >= FlowTime+2000) 
	{ 
		Flow1Value = 30*Flow1Count/169;	//60*1000/2000=24
		Flow2Value = 30*Flow2Count/169;	//60*1000/2500=24
		Flow3Value = 30*Flow3Count/169;	//60*1000/2500=24
		Flow1Count = 0;
		Flow2Count = 0;
		Flow3Count = 0;
		FlowTime = millis();
	}
	if (millis() >= FlowLongTime+60000) 
	{ 
		Flow1LongValue = Flow1LongCount/169;	//60*1000/2500=24
		Flow2LongValue = Flow2LongCount/169;	//60*1000/2500=24
		Flow3LongValue = Flow3LongCount/169;	//60*1000/2500=24
		Flow1LongCount = 0;
		Flow2LongCount = 0;
		Flow3LongCount = 0;
		FlowLongTime = millis();
	}
}

The range of the pulse difference from time to time.
Today LOW=320and HIGH=420
Tomorrow LOW=610 and HIGH=750

What I would like to have as code is to have the arduino find the Highest LOW value and the lowest HIGH value everytime it is running the sketch.

Any ideas on how to accomplish this?

Thank you very much in advance.

can you attach data sheet for flow sensor. Can you share your complete code.

can you explain which parameter represent.

Today  LOW=320and HIGH=420
Tomorrow LOW=610 and HIGH=750

Hi, as asked can you supply the specs of the flow meter, it may be an open circuit collector, you will to provide about 10K between the output and 5V.

The output will be pulses.

Tom.... :slight_smile:

AMPS-N:
can you attach data sheet for flow sensor. Can you share your complete code.

can you explain which parameter represent.

Today  LOW=320and HIGH=420

Tomorrow LOW=610 and HIGH=750

The rest of the code is important to the problem I believe because all the calculations for my Flowmeter is done in the FlowCalculations function.
There is a lot of other code all the pins on the UNO are used, there is also some power going through my board(shield) that contains 5V,12V and 24V.
The 12V is used to power the UNO.

The LOW and HIGH are the analog values I read for a low and high pulse.

TomGeorge:
Hi, as asked can you supply the specs of the flow meter, it may be an open circuit collector, you will to provide about 10K between the output and 5V.

The output will be pulses.

Tom.... :slight_smile:

I will make an adapter that contains a 10K between the output and the 5V and try it.

Also for both I'm using this flowmeter.

Opening it and searching on the interwebz reveal it's this datasheet which just mentions Output Signal: Pulse

Upon visiting their Download section I find this connection sheet:
I need a 4k7 between 5V and Signal also a 100nF between signal and ground
Could I just add the 4k7 and leave the 100nF out or would that still not work?

Why are these comments here? They appear wrong

		Flow1Value = 30*Flow1Count/169;	//60*1000/2000=24
		Flow2Value = 30*Flow2Count/169;	//60*1000/2500=24
		Flow3Value = 30*Flow3Count/169;	//60*1000/2500=24

Hi, have you run just some code to check the flowmeter output and your calculation functions?

169 impulses per liter

Gives it away, its pulse output, so use a digital rather than analog input configuration.

4K7 should do the trick if you are supplying the flowmeter with 12V.

Please, just write code for the flowmeter and get it working first.

It sound like you have a complicated sketch, I hope you developed it stage by stage and then integrated each stage into the main program.

That way you know that each stage works and any failure after that is probably code problems, which means posting ALL the sketch.

Tom.... :slight_smile:

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?