Bottle filler

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 :frowning:

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)

I think you have to convert the ASCII character you read from the Serial console into an int.

The ASCII value of '1' is 49, your code will count to 49.

Crossposted on the Spanish forum!

Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R

Hi, Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum". OR http://forum.arduino.cc/index.php/topic,148850.0.html. Then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Thanks... Tom.. :)

DON'T CROSS POST!

llenadora de botellas automatizada (POR FAVOR NECESITO AYUDA RAPIDO!!!!) I

3rd time. Thread locked.