Help with Led-thermometer


I want 2 LED’s (for a start) that shows the temperature.

I want LED1 (red) to turn on if the temperature is above 24 degrees.
I want LED1 to turn off if the temperature drops below 24 degrees.

I want LED2 (blue) to turn on if the temperatur drops below 20 degrees and to turn off if the temperature rises above 20 degrees.

But I can’t get it to work.
I get the temperature read, but my “if” statements doesn’t work.

What do I do wrong?

#include <math.h>
int ledPin = 13;
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;// Convert Kelvin to Celcius
return Temp;
void setup() {
pinMode(ledPin, OUTPUT);

void loop() {

if (Serial.print(Thermister(analogRead(0))) < 23.00)
    digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(ledPin, LOW);



The serial.print in the if statement returns the number of bytes written, not the value of

So it should be more like:

if (Serial.print() < 23.00)

I don’t really understand this, yet. =/

No. Don’t put the Serial.print in the if statement. Read the temperature into a variable then print it and then use the variable in the if statement. The reason for the variable is that you print the same data that you use in the if statement.

float temperature = Thermister(analogRead(0);
if (temperature < 23.00)
      // do stuff

Oh, so it's that easy.

Thank you! =D

In the IDE go to Files, Examples. There is example code for just about everything.