Trouble comparing a float variable in an If statement

I am using one of the Thermistor codes from this website that basically measures temperature and prints that to the serial monitor.
If the temperature comes to freezing point, I want the program to take some action. For testing I want to switch on 'Led13'
The code in question is below.
However, it does not work. The serial monitor prints "Celsius: 0.0", but whatever value I try, I do not get the Led to go on, wether I use: "temp <=0", "temp<= 0.0", "temp <1", it just won't work and I have no idea what I am doing wrong

void loop() {
float temp;
temp=Thermistor(analogRead(ThermistorPIN)); // read ADC and convert it to Celsius
Serial.print("Celsius: ");
Serial.print(temp,1); // display Celsius
Serial.println("");
if (temp <= 0) {
digitalWrite(outPin, HIGH); // I added this but it does not work
}

delay(5000); // Delay a bit...
}

ed1000:
I am using one of the Thermistor codes from this website that basically measures temperature and prints that to the serial monitor.
If the temperature comes to freezing point, I want the program to take some action. For testing I want to switch on 'Led13'
The code in question is below.
However, it does not work. The serial monitor prints "Celsius: 0.0", but whatever value I try, I do not get the Led to go on, wether I use: "temp <=0", "temp<= 0.0", "temp <1", it just won't work and I have no idea what I am doing wrong

void loop() {
float temp;
temp=Thermistor(analogRead(ThermistorPIN)); // read ADC and convert it to Celsius
Serial.print("Celsius: ");
Serial.print(temp,1); // display Celsius
Serial.println("");
if (temp <= 0) {
digitalWrite(outPin, HIGH); // I added this but it does not work
}

delay(5000); // Delay a bit...
}

In if (temp <= 0) { , 0 is type integer unless typcast to a float

Where is your setup() code? You have to open serial communication before making serial calls eg Serial.begin(9600);

Have you initialized outPin properly in your setup() code?

Pete

where is outPin defined? Remember C is case sensitive.

You used Less Than Equal to <=
you want >=. temp will never be negative.

Thanks all for your quick input. Yes I did all these things you suggest, but I already found the culprit (ofcourse immediately after I placed my help request). The thermistor had come loose, The print out kept giving me a steady 0.0 celsius which seemed OK as i had it in icewater, but after reconnecting the thermistor, it all worked as it shld.
Still a bit odd as the "o.o" value that was printed was the 'temp variable' but who cares, it got fixed.

Nevertheless thank you all for yr quick response

Thanks ajofscott, but I really want <= :slight_smile:
It is a float variable and that will definitely become negative. I am looking at negative values now :slight_smile:

Nevertheless thnaks for your swift input

This is good to know, seems the ADC is center biased at 1/2Vref, typically and ADC is 0 to Vref in nRes bits. I have not fully read the mpu spec sheets from Amtel yet.

The ADC returns 0-1023 but his Thermistor function gives the values he is looking at.