Is if statement correct?
No, the first lines should be:

if(temperature &lt; baselineTemp) {
  digitalWrite(2, LOW);


Thus the else should be removed; after the first if and later else or else if conditions, statements can be placed.

Next time align your code by selecting it and select ctrl-K.

Also, your code can be much more simplified.

Hence the following (reverse engineered) requirements:


pin 2 is HIGH when temperature >= baselineTemp + 2, else LOW
pin 3 is HIGH when temperature >= baselineTemp + 4, else LOW
pin 4 is HIGH when temperature >= baselineTemp + 4, else LOW


So your entire code can be written as:

digitalWrite(2, temperature &gt;= baselineTemp + 2 ? HIGH : LOW);
digitalWrite(3, temperature &gt;= baselineTemp + 4 ? HIGH : LOW);
digitalWrite(4, temperature &gt;= baselineTemp + 6 ? HIGH : LOW);