Go Down

Topic: Store the max and min value in thermometer (Read 140 times) previous topic - next topic

fsq90

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?

Code: [Select]
#include <math.h>
#include <LiquidCrystal.h>

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

double Thermistor(int RawADC) {
 double Temp;
 Temp = log(10000.0*((1024.0/RawADC-1)));
 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;           
  val=analogRead(0);     
  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);
}

UKHeliBob

Quote
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.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

fsq90

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 ?

Code: [Select]
#include <math.h>
#include <LiquidCrystal.h>

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

double Thermistor(int RawADC) {
 double Temp;
 Temp = log(10000.0*((1024.0/RawADC-1)));
 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;           
  val=analogRead(0);     
  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);}
}

MarkT

temphi must be a global variable, it persists for the duration of the sketch.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

fsq90


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy