Variables as parameters in do/while loop

This is a very simple program, and it works fine except for one thing: The outputs from the sensor does not break the do/while loop even when they exceed the settings. The variable "minutes" will break the loop, but not "temp" or "humid".
I have tried re-ordering the parameters in the while statement, I have tried different number formats, I have not been able to find out anything about this on the forums.
The board is a Uno series R3. The sensor is an Adafruit DHT22 Wired.

I attached the sketch in a .txt file. The output from the Serial Monitor is below, and the loop should have failed at the beginning since Temperature is less than 75 F and the Humidity is greater than 20%.

Please show me what I am doing wrong, thank you.

10:17:57.681 -> minutes = 7
10:17:57.681 -> temperature = 66.74
10:17:57.717 -> humidity = 46.70
10:18:02.683 -> minutes = 6
10:18:02.683 -> temperature = 66.56
10:18:02.717 -> humidity = 44.70
10:18:07.694 -> minutes = 5
10:18:07.694 -> temperature = 66.56
10:18:07.728 -> humidity = 44.50
10:18:12.688 -> minutes = 4
10:18:12.723 -> temperature = 66.56
10:18:12.723 -> humidity = 44.30
10:18:17.690 -> minutes = 3
10:18:17.724 -> temperature = 66.56
10:18:17.724 -> humidity = 44.20
10:18:22.722 -> minutes = 2
10:18:22.722 -> temperature = 66.56
10:18:22.758 -> humidity = 44.10
10:18:27.726 -> minutes = 1
10:18:27.726 -> temperature = 66.56
10:18:27.762 -> humidity = 44.00
10:18:32.717 -> minutes = 0
10:18:32.751 -> temperature = 66.56
10:18:32.751 -> humidity = 43.90

do_while_sketch_20210105.txt (1.22 KB)

Look at your while statement:

while (minutes > 0 && temp < 75.00 && humid > 20.00);

It will continue looping WHILE the minutes are greater than 0 and the temp is less than 75.00 and the humidity is greater than 20.00.

Try this:

while (minutes > 0 && temp >= 75.00 && humid <= 20.00);

You also have another issue. You redefined 'humid' and 'temp' variables inside of the loop. Those are local to that loop and NOT the same as the global 'humid' and 'temp'! Remove the 'float' declaration for those as shown below:

  do
  {
    // here we start to sample the sensor.
    delay (5000);
    humid = dht.readHumidity();
    // Read temperature as Fahrenheit (isFahrenheit = true)
    temp = dht.readTemperature(true);
    minutes--;
    Serial.print("minutes = ");
    Serial.println(minutes);
    Serial.print("temperature = ");
    Serial.println(temp);
    Serial.print("humidity = ");
    Serial.println(humid);
  }
  while (minutes > 0 && temp < 75.00 && humid > 20.00);

ToddL, you are exactly right!

While I was QC-ing this, I set the > and < backwards, forgot to set them back.

But defining the variable twice was my mistake.

Thank you very much!

wminn:
ToddL, you are exactly right!

While I was QC-ing this, I set the > and < backwards, forgot to set them back.

But defining the variable twice was my mistake.

Thank you very much!

You're welcome. Glad it worked out!