Good morning everyone, I need help with a code, what I am trying to do is that by means of a flowmeter and an electrovalve I can fill tanks with a certain number of liters that I enter through the serial port, the problem I currently have is that the program currently does the liter count but it does not stop at the number of liters that I enter through the serial port and instead it continues calculating the liters and the solenoid valve never turns off ![]()
I attach the code:
volatile int NbTopsFan;
float Calc;
int hallsensor = 2;
int pinRele=11;
int lecturaSt;
int caudalTope;
void rpm () {
NbTopsFan++;
}
void setup() {
Serial.begin(9600);
pinMode(hallsensor, INPUT);
pinMode(pinBotonStart, INPUT);
pinMode(pinRele, OUTPUT);
attachInterrupt(0, rpm, RISING);
}
void loop () {
if(Serial.available()){
caudalTope = Serial.read();
digitalWrite(pinRele, HIGH);
do {
NbTopsFan = 0;
sei();
delay (1000);
cli();
Calc = Calc + (NbTopsFan / 5.5)/60;
Serial.println(Calc, DEC);
}while(Calc < caudalTope);
digitalWrite(pinRele, LOW);
caudalTope = 0;
lecturaSt = 0;
}
delay(500);
}
caudalimetro.ino (803 Bytes)