Min/Max thermometer on LCD won't show minimum temperature

Hello all,

Having troubles here.
I’m trying to make a min/max thermometer, with output on LCD

Got the current temp working, got the max. temperature showing up, but the minimum won’t work…
Hope you could help me out?

I think I’m close, but kind of frustrated now, XD

Here is my code:

#include <LiquidCrystal.h>

/* Sensor test sketch
  for more information see http://www.ladyada.net/make/logshield/lighttemp.html
  */
 
#define aref_voltage 3.3         // we tie 3.3V to ARef and measure it with a multimeter!
 
 
 
 
//TMP36 Pin Variables
int tempPin = 0;        //the analog pin the TMP36's Vout (sense) pin is connected to
                        //the resolution is 10 mV / degree centigrade with a
                        //500 mV offset to allow for negative temperatures
int tempReading;        // the analog reading from the sensor
int tempMaxA = 0;       //store Maximum Temperature level
int tempMin = 0;        //Store old Minimum level
int tempMinA = 0;       //store Maximum temperature level


 
 LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

byte newChar[8] = {
	B01100,
	B10010,
	B10010,
	B01100,
	B00000,
	B00000,
	B00000,
	B00000
};

void setup(void) {
 
 
  // If you want to set the aref to something other than 5v
  analogReference(EXTERNAL);
  
  lcd.begin(21, 4);
}
 
 
void loop(void) {
 
  tempReading = analogRead(tempPin);  
 
  // converting that reading to voltage, which is based off the reference voltage
  float voltage = tempReading * aref_voltage;
  voltage /= 1024.0; 
 
  // now print out the temperature
  float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
  



  if (tempMin < tempMinA) {    // here is the problem... minimum won't store
    tempMinA = temperatureC;   //compare old temperature with old minimum
  }
   if (temperatureC >= tempMaxA) {    //if higher then current temperature, store current temperatute as MAX Temperature
   tempMaxA =temperatureC;
  } 
                                              
  lcd.createChar(0, newChar);
	
	lcd.setCursor(0, 0);
        lcd.print("Het is "); lcd.print(temperatureC); //show currebnt temerature
        lcd.write(0);
        lcd.print("C");
        lcd.setCursor(0, 2);
        lcd.print("MIN Temp "); lcd.print(tempMinA);   //show lowest temperature
        lcd.write(0);
        lcd.print("C");
        lcd.setCursor(0, 3);
        lcd.print("MAX Temp "); lcd.print(tempMaxA);   //show highest temperature
        lcd.write(0);
        lcd.print("C"); 


  delay(1000);           //wait for one second
  
  tempMin = temperatureC;    //write current temperatute as old minimum
}

You initialize tempMinA to zero so your later checks to see if your reading is less than that won't work unless you're somewhere cold. Try initializing it to 100.

wildbill: You initialize tempMinA to zero so your later checks to see if your reading is less than that won't work unless you're somewhere cold. Try initializing it to 100.

Why are some things sooooooooo simple....

Thanx, It works now. I've tried it on 20, but 100 is better of course!

Or you can use an initial reading in setup() to set the minimum and maximum. That way it never has a "unrealistic value".

basicly something like this... (not tested)

setup()
{
  min = max = current = getTemp();
  displayTemp();
}

loop()
{
  current = getTemp();
  min = min(min, current);
  max = max(max, current);
  displayTemp();
}

I agree with Rob. Use the initial temperature reading as both min and max.

Maybe add two alarms too, over temperature and under temperature.