# Store the max and min value in thermometer

Hi, I made a simple thermometer with LCD using this tutorial http://www.circuitbasics.com/arduino-thermistor-temperature-sensor-tutorial/ . Works fine, but i want to show max and min temperature in the second line of the LCD. I guess I should read the last temp. value, and compare this with new reading from thermistor using function if. I wrote some code, but it doesn’t work properly. Could somebody help me?

``````#include <math.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(2, 3, 4, 6, 7, 8);

double Temp;
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;
//Temp = (Temp * 9.0)/ 5.0 + 32.0;
return Temp;
}

void setup() {
lcd.begin(16, 2);
}

void loop() {
int val;
double temp;
double lasttemp = 0;
double temphi;
temp=Thermistor(val);
lcd.setCursor(0,0);
lcd.print("Temp = ");
lcd.print(temp);
lcd.print(" C");
delay(1000);
lcd.clear();
//My part of code is below
lasttemp = temp;
if (lasttemp >= temp)
{temp = lasttemp;}
lcd.setCursor(0,1);
lcd.print("HI= ");
lcd.print(temp);
}
``````

I guess I should read the last temp. value, and compare this with new reading from thermistor using function if.

No

You need 2 variables. Let's name them highestTemp and lowestTemp. Set them initially to impossibly low and impossibly high values respectively. When you have read the current temperature compare it with highestTemp. If the current temp is greater than highestTemp then set highestTemp to the current temp, Similarly compare lowestTemp to the current temp. If the current temp is lower than lowestTemp then set lowestTemp to the current temp.

Now display the values. For extra efficiency only display the values if they have changed.

For now, I am just trying to read max value. I think I’m doing exactly what you said, but it still isn’t working. Second line on the lcd shows last reading from the first line (for example 21.20 > 21.12/21.20 > 21.40/21.12…). Could you look at the sketch ?

``````#include <math.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(2, 3, 4, 6, 7, 8);

double Temp;
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;
//Temp = (Temp * 9.0)/ 5.0 + 32.0;
return Temp;
}

void setup() {
lcd.begin(16, 2);
}

void loop() {
int val;
double temp;
double temphi = -100;
temp=Thermistor(val);
lcd.setCursor(0,0);
lcd.print("Temp = ");
lcd.print(temp);
lcd.print(" C");
delay(1000);
lcd.clear();
if (temp > temphi)
{temphi = temp;
lcd.setCursor(0,1);
lcd.print("HI= ");
lcd.print(temphi);}
}
``````

temphi must be a global variable, it persists for the duration of the sketch.

Thanks. Works great now.