Multiple conditions for if statement

Hello,
I built a programmable thermostat for my radiators, it works well but i have a programmation problem: in one if statement I have multiple conditions but Arduino doesn't recognize one of it, in particulare my ifs are:

if((vett[num_hh] == 1 && temp < temp_set) || (onoff == 1)){ 
 close relay
}

else if ( (vett[num_hh] == 1 && temp > temp_set + 0.50) || (vett[num_hh] == 0)  || (onoff == 0) ){
open relay
}

the thing that happens is that when temp is greater than temp_set (and vett[num_hh] == 1) arduino opens the relay, why doesn't it consider the "+0.50" gap?

thanks to everybody who will answer...

Made a subtle change.

code snippets suck. What is the type declaration of temp and temp_set?

Nope. Adding redundant parenthesis does nothing. C++ operator precedence means those two statements are equivalent.

Add serial prints before the if statement printing out the state of the variables so you may see what's going on.

are two floats

I tried to remove the OR conditions (vett[num_hh] == 0, onoff == 0) leaving only

if (vett[num_hh] == 1 && temp >= temp_setf+0.50){
      
      open relay;
    }
    
    
    else if(vett[num_hh] == 1 && temp < temp_setf){
      close relay
    }

and it works, so there is a problem with syntax of OR (||) mixed with AND (&&) sub-condition, but i cannot understand what it is...

Ok, I figured out which was the condition which messed up things, this:

|| (onoff == 0)

This was in conflict with the others so the program didn't know what to do when onoff==0 and vett[num_hh] == 1 && temp < temp_setf, now it seems it works fine...

Yes, the program knew what to do. You had the logic wrong :slight_smile:

Hi,
Is temp_set, temp all float or int?
If int then 0.50 will possibly be read as 0.

Complete code would be nice.

Tom.. :grinning: :+1: :coffee: :australia:

all temp variables are floats

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