Interrupt problems (Large Code)

Hello Forum members,

I am new to this forum and would like to use your expertise.

I am making a foam extinguisher filling station so that I can refill foam extinguishers to use for fire training purposes.

I will briefly explain what the code should do step by step.

In the project I use 2 flow sensors, a 20x4 lcd screen via I2c protocol
A pair of relays, a buzzer and a push button.
I also use a 1.2Mpa pressure sensor. I am still working on that.

The meaning of the code should be from the point you start the arduino:

step 1:
Press start.

step2:
Relay1 goes on, water flows through flow sensor 1.
If it has reached its target, relay1 goes out, so flow sensor 1 does not get flow and stops counting.

step3:
Relay 2 goes on, foam pump goes on (connected to relay 2)
Causing flow sensor2 to do its job.
If it has reached its target, relay2 goes out, so flow sensor 2 does not get flow and stops counting.

step4:
Then relays 3 on which a small compressor is connected.
I'm still working on this to enable a pressure switch to work.
Maybe you can help me too?

When I upload the code, everything goes according to plan but the flow rate does not stop if it is triggered once.
And the interrupt no longer works from step2.

I hope that one of you can support me with this.
Kind regards.
Kannekens

Somewhere\Blusstation_v10\Blusstation_v10.ino:146:46: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
         if (current_volume1 < target_volume1);
                                              ^

Somewhere\Blusstation_v10\Blusstation_v10.ino:176:48: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
         if (current_pressure < target_pressure);
                                                ^

You have a strange switch construct, without any ‘case’ or ‘default’.
Will that code ever be executed? I never tried… see #4

What are all the superfluous curly brackets good for?

 switch (reactions)
  {
      {
        if (digitalRead(SOLENOIDPIN1 == HIGH))
        {
          digitalWrite(SOLENOIDPIN1, LOW);      //STOP WATER FLOW
        }
        break;
      }
      {
        if (digitalRead(SOLENOIDPIN2 == HIGH))
        {
          digitalWrite(SOLENOIDPIN2, LOW);      //STOP SOAP FLOW
        }
        break;
      }
      {
        if (digitalRead(SOLENOIDPIN3 == HIGH))
        {
          digitalWrite(SOLENOIDPIN3, LOW);      //STOP AIR FLOW
        }
        break;
      }
      {
        if (digitalRead(SOLENOIDPIN1 == LOW))
        {
          digitalWrite(SOLENOIDPIN1, HIGH);      //START WATER FLOW
        }
        break;
      }
      {
        if (digitalRead(SOLENOIDPIN2 == LOW))
        {
          digitalWrite(SOLENOIDPIN2, HIGH);      //START SOAP FLOW
        }
        break;
      }
      {
        if (digitalRead(SOLENOIDPIN3 == LOW))
        {
          digitalWrite(SOLENOIDPIN3, HIGH);      //START AIR FLOW
        }
        break;
      }
      { // vessel size adjustment (trim)
        if (target_volume1 >= hltSIZE1)  //don't go larger than the size of the vessel
        {
          target_volume1 = hltSIZE1;
          break;
        }
        {
          if (target_volume2 >= hltSIZE2)  //don't go larger than the size of the vessel
          {
            target_volume2 = hltSIZE2;
            break;
          }
          {
            if (target_pressure >= hltSIZE3)  //don't go larger than the size of the vessel
            {
              target_pressure = hltSIZE3;
              break;
            }
            else
            {
              target_volume1 += 0.1;
              break;
            }
            {
              target_volume2 += 0.1;
              break;
            }
            {
              target_pressure += 0.1;
              break;
            }
          }
        }
      }
  }

Hey,
thanks for your comment!
The lower part of the code is to adjust the diameter of the tube.
This allows you to connect different thickness tubes.
To make a correct calculation.

And I inverted the relay because I had ordered the wrong one.
High trigger, low trigger etc.

A millisecond isn't a very long time to allow the use of floating point math in an ISR. You might be getting away with it, but it's dangerous.

Also when you read the variables that are manipulated by the ISR in the main program, you don't disable interrupts. That is mandatory for non-atomic types.

Kannekens:
Hey,
tThe lower part of the code is to adjust the diameter of the tube.
This allows you to connect different thickness tubes.
To make a correct calculation.

Then it would be nice to execute that code, wouldn't it?

Code outside any case is not executed:

void setup() {
  int select = 2;
  Serial.begin(250000);
  Serial.println(F("before the switch"));
  switch (select) {
      Serial.println(F("outside any case, inside switch"));
  }
  Serial.println(F("after the switch"));
}
void loop() {}
before the switch
after the switch

Oke, I definitely have to look at that!

SIGNAL(TIMER0_COMPA_vect) {
  uint8_t x1 = digitalRead(FLOWSENSORPIN1);
  uint8_t x2 = digitalRead(FLOWSENSORPIN2);
  uint8_t x3 = analogRead(PRESSURESENSORPIN);
  ...
  ...
  if (x3 == HIGH)
  {
    pressure++;
  }

PRESSURESENSORPIN is treated as digital everywhere except in that analogRead() call.

Is correct. The part of the pressure section. Is still being worked on.
I'm looking for a way to create 1 function that I can use for 2 or more flow sensors.

I've written everything three times the same. Except the pins :wink:

Is correct. The part of the pressure section. Is still being worked on.

Comparing the result of a call to analogRead() to HIGH is never correct...

You need one ISR for each sensor, each calls a shared function with the relevant pins as arguments.