Counting does not happen correctly

Hello,

I want my waterpump to turn on max 5 times but when I set the counter to a maximum value of 5 the maximum times the waterpump will be on is 6.

When I put it to 4 it will be correct (5).

Why is this?

      if(Sproei_Teller <= 4)// Als ik deze op 5 zet dan wordt het maximum sproei keren 6
       {
        if(meting_vsensor >= Sproei_Laagste_Waarde)
        {
         if(digitalRead(relais_water) == LOW)
         {
          Serial.println("Sproei Teller + 1");
          Serial.println("Waterpomp: AAN");
       
          Sproei_Teller++;
          digitalWrite(relais_water, HIGH);  
         }
        }

There are five values in the range 0-4. All of them are less than or equal to four, hence the if() condition is met.

dougp:
There are five values in the range 0-4. All of them are less than or equal to four, hence the if() condition is met.

oooh okay, I get it now thanks! :smiley:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.