temp min value 0

where is mistake? my min value is 0
+22.46 C MAX TEMP +22.95 C MIN TEMP +0.00 C
p.s its LM35 sensor

float tempC;
float maxtempC;
float mintempC;
int tempPin = 0;

void setup()
{
Serial.begin(9600);
}
void loop()
{
tempC =(5.0*analogRead(tempPin)*100.0)/1024.0;
maxtempC = max(maxtempC, tempC);
mintempC = min(mintempC, tempC);
Serial.print("+");
Serial.print(tempC);
Serial.print(" C ");
Serial.print("MAX TEMP +");
Serial.print(maxtempC);
Serial.print(" C ");
Serial.print("MIN TEMP +");
Serial.print(mintempC);
Serial.println(" C ");
delay(5000);
}

What is the initial value of tempMinC? When you compare that to the current temperature, which is less? Zero IS the correct answer.

i cant answer your questions because i don't know. how need to white code what it show for me min temperature same as max temp?

i cant answer your questions because i don't know

Use Serial.print() in setup() to learn.

how need to white code what it show for me min temperature same as max temp?

minTempC = maxTempC;

But that hardly seems like that you want to do.

You might try actually assigning values to minTempC and maxTempC when you declare them. Try setting both to 149.0, to see what happens. Then, try setting both to -238.4 to see what happens. I'm sure that sooner or later, you'll stub your toe on a clue.

PaulS:
You might try actually assigning values to minTempC and maxTempC when you declare them. Try setting both to 149.0, to see what happens. Then, try setting both to -238.4 to see what happens. I'm sure that sooner or later, you'll stub your toe on a clue.

Absolutely :slight_smile:

OK thx u a lot it now seems working, but why tempCmax was working in first place?
i change:

float mintempC = 149.0;
float maxtempC = -149.0;

but why tempCmax was working in first place?

It only worked because your values were all greater than 0, which is the default value when you do not supply one.

You could have defined a boolean, firstReadingTaken, initially set to false. Then, when the first reading was taken, you could have set minTempC and maxTempC to that reading, and set firstReadingTaken to true. When firstReadingTaken is false, assign the value, as mentioned. When it is true, compare it to minTempC and maxTempC as you are doing.

PaulS:
You could have defined a boolean, firstReadingTaken, initially set to false. Then, when the first reading was taken, you could have set minTempC and maxTempC to that reading, and set firstReadingTaken to true. When firstReadingTaken is false, assign the value, as mentioned. When it is true, compare it to minTempC and maxTempC as you are doing.

can i provide this great think in code?

boolean readFirstTemp = false;

void loop()
{
   tempC =(5.0*analogRead(tempPin)*100.0)/1024.0;
   if(readFirstTemp)
   {
      maxtempC = max(maxtempC, tempC);
      mintempC = min(mintempC, tempC);
   }
   else
   {
       readFirstTemp = true;
       maxTempC = tempC;
       minTempC = tempC;
   }
}