NodeMCU not following conditional statement.

I have been developing a automated temperature chamber using dht11 and relay to on/off heat source. I upgraded to NodeMCU from UNO for IOT. My code was working perfectly in UNO but ESP is not following IF statement and put the relay in always ON state.

NodeMCU_bug.ino (2.34 KB)

What temperature is your program reporting?

More than 28C.
If I cool dht below 21 still no response.
Just show me correct way for using IF statement in this situation.
My Uno was doing everything right for more than 6 months.

I don't see anything wrong with the code. Maybe the NodeMCU can't switch the relay, or perhaps you have a wiring issue.

I'd put some serial prints in those if statements to see whether the execution is acting as you suspect.

I'd also try to write a really simple program (blink basically) that turns the relay on and off every five seconds or so.

Thank you

It means no problem with coding but the problem is that I am using NC relay which is always ON but never turn OFF which means nodemcu is switching it.

NodeMCU pins have to be referred to a bit differently than Arduino.
In Arduino it’s just as you’ve done – int thermal = 4
the IDE will allow that even though there’s a problem.
The NodeMCU needs you to use the names (designators) as marked on the board
for instance D4, i.e., e.g., to wit – int thermal = D4;

Write a test program that does nothing but click the relay (activate, delay, deactivate, delay, . . .)
or an LED
to prove this out.

wildbill:
I don’t see anything wrong with the code. Maybe the NodeMCU can’t switch the relay, or perhaps you have a wiring issue.

I’d put some serial prints in those if statements to see whether the execution is acting as you suspect.

I’d also try to write a really simple program (blink basically) that turns the relay on and off every five seconds or so.

Finally inner peace
I want someone to verify my code.
So thank you very much and thanks a lot to me that I figure it out.
I was using 5v power supply for relay and nodemcu was giving 3v signal which means that there was 2v potential difference that was putting the relay at ALWAYS ON state.