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 () {

void setup() {

pinMode(hallsensor, INPUT);
pinMode(pinBotonStart, INPUT);
pinMode(pinRele, OUTPUT);
attachInterrupt(0, rpm, RISING);


void loop () {
caudalTope =;

digitalWrite(pinRele, HIGH);

do {
NbTopsFan = 0;
delay (1000);
Calc = Calc + (NbTopsFan / 5.5)/60;
Serial.println(Calc, DEC);
}while(Calc < caudalTope);
digitalWrite(pinRele, LOW);

caudalTope = 0;
lecturaSt = 0;

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.


Hi, Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum". OR,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.. :)


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

3rd time. Thread locked.