Hi I am trying to make a minimum maximum temperature sensor using an LM35 sensor for temperature and an LCD.I am having problems with the minimum temperature.It works perfectly until i unplug it from the computer.When i plug it in again it reads "ovfMn" instead of eg "24.41Mn". Even if i press the reset button on the Arduino Uno it doesn't help but if I modify the the code to print something else then upload it and then upload the old code again I can get it to work again.Help would be much appreciated.Thanks.
here is my code.
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, 12, 2, 3, 4, 5); //Digital pins to which you connect the LCD
const int inPin = A0; // A0 is the temperature sensor
void setup()
{
lcd.begin(16,2);
}
void loop()
{
int value = analogRead(inPin); // read the value from the sensor
lcd.setCursor(0,1);
float millivolts = (value / 1024.0) * 5000;
float temp = millivolts / 10;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(temp); lcd.print("C");
float tmax ;
if (temp >= tmax){tmax = temp;};
lcd.setCursor(0,1);
lcd.print(tmax); //print the maximum temperature
lcd.print("Mx");
float tmin ;
if (temp <= tmin){tmin = temp;}; //if temperature is below previous min value reset it
lcd.setCursor(8,1);
lcd.print(tmin); //print the minimum temperature
lcd.print("Mn");
delay(1000);
}
I also would like to add a reset button and i cant figure out how to code it.
When I compile that I see:
warning: 'tmax' is used uninitialized in this function
Same thing for tmin. You may need to increase the level of compiler warnings in preferences to see this.
To fix this, make those variables global and set them to a temperature read in the setup function.
wildbill:
When I compile that I see:
warning: 'tmax' is used uninitialized in this function
Same thing for tmin. You may need to increase the level of compiler warnings in preferences to see this.
To fix this, make those variables global and set them to a temperature read in the setup function.
I'm sorry I don't understand how do I set them as a temperature read.I have changed the variables to global and uploaded and i get a minimum temperature of 0.00.
Thanks.
Personally I would make them global and give them initial impossible values such as 999 for tmin and 0 for tmax so that from the very first reading they are adjusted to the current reading
Just stick this in setup:
int value = analogRead(inPin); // read the value from the sensor
float millivolts = (value / 1024.0) * 5000;
tmax=tmin = millivolts / 10;
Thank you for your help i have got it working nicely now although i am curious as to the best way to reset it.Do i just use the reset button on the Arduino or is there another better way?
is there another better way?
Read the state of a pin that is normally held HIGH
Arrange that the pin is taken LOW when a button is pressed
When the pin goes LOW set the values of tmin and tmax as I suggested in reply #3
You could put those three lines in a function, call it from Setup and also check for a button press and call it when you detect one.
Not a big advantage over pressing reset, unless you've put the arduino in some kind of enclosure and can't reach it.
Jordan54:
I also would like to add a reset button and i cant figure out how to code it.
What is the purpose of this user Reset Button (not RST Button of UNO)? What kind of response you expect from your under-execution program when you press this user Reset Button?