Thanks for replay
Sure this is all program below:
// *********************************************************************
// Macros settings
// *********************************************************************
#define _INPUT_SEN_SIG 2 //square wave input
// *********************************************************************
// Global variables
// *********************************************************************
unsigned char LockTEMP = 0;
float FlowRate, Frequency, Time = 1, LitersCount;
unsigned long NextValueMilli, NextValueMilli_1;
unsigned long FirstValueMicro, SecoundValueMicro, TherdValueMicro;
float HighTime, LowTime;
void setup()
{
// Initialize IO pins
pinMode(_INPUT_SEN_SIG, INPUT);
Serial.begin(57600);
}
void loop()
{
if ((digitalRead(_INPUT_SEN_SIG) == HIGH) && (LockTEMP == 0))
{
FirstValueMicro = micros();
LockTEMP = 1;
//LowTime = FirstValueMicro - SecoundValueMicro;
}
if ((digitalRead(_INPUT_SEN_SIG) == LOW) && (LockTEMP == 1))
{
SecoundValueMicro = micros();
LockTEMP = 0;
HighTime = SecoundValueMicro - FirstValueMicro;
}
//Time = HighTime + LowTime;
Frequency = 500000 / HighTime;
FlowRate = Frequency / 7.5; // Flow rate in L/min
//LitersCount = LitersCount + (FlowRate/60);
if (NextValueMilli <= millis())
{
NextValueMilli = millis() + 1000;
LitersCount = LitersCount + (FlowRate / 60);
}
if (NextValueMilli_1 <= millis())
{
NextValueMilli_1 = millis() + 100;
Serial.print(Frequency);
Serial.print(" ");
Serial.print(HighTime);
Serial.print(" ");
Serial.print(LitersCount);
Serial.print(" ");
Serial.println(FlowRate);
}
}
and this is what I got:
199.36 2508.00 inf 26.58
198.10 2524.00 inf 26.41
196.23 2548.00 inf 26.16
203.25 2460.00 inf 27.10
196.85 2540.00 inf 26.25
203.25 2460.00 inf 27.10
199.36 2508.00 inf 26.58
197.16 2536.00 inf 26.29
203.25 2460.00 inf 27.10
198.10 2524.00 inf 26.41
203.92 2452.00 inf 27.19
Thanks in advance