Can't get it to hold max temp.

I’m pretty new about coding, I’ve read a lot of forum threads and tried for several days, but I can not get it to hold “maxtemp” until I press the reset button, max temp dropping with temp, and I need that continues to show what max temp has been

The button is connected to + 5V on one side and the other side has a 1k ohm resistor to 0V, and at the same legs as the button modstenden is connected to a wire to pin 13 on my Arduino uno.

#include <LiquidCrystal.h>
#include <max6675.h>

// setup termocupler
int thermoDO = 8;
int thermoCS_1 = 10;
int thermoCLK = 9;
MAX6675 thermocouple_1(thermoCLK, thermoCS_1, thermoDO);

float temp;
float maxtemp = 0;

// setup lcd
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

// setup button 

const int buttonPin = 13;
int buttonState = 0;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  lcd.begin(20, 4);
  // wait for MAX chip to stabilize
  delay(500);
  pinMode(buttonPin,INPUT_PULLUP);
}

void loop() {  
 
// Temp read

Serial.print("Sensor_1 temp = "); 
   Serial.println(thermocouple_1.readCelsius());
  temp = thermocouple_1.readCelsius();

// Read maxtemp

  if (temp > maxtemp) maxtemp = temp;

Serial.print("maxtemp       = ");
  Serial.println(maxtemp);



// Wright lcd   

   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("EGT Temp ");
   lcd.print(temp);

   lcd.setCursor(0,2);
   lcd.print("MAX Temp ");
   lcd.print(maxtemp);
   delay(500);


//Button

buttonState = digitalRead(buttonPin);

if (buttonState == LOW) {
    // reset maxtemp
    maxtemp = 0;
}  
}

Hope you guys can help me.

brunokc:
The button is connected to + 5V on one side and the other side has a 1k ohm resistor to 0V, and at the same legs as the button modstenden is connected to a wire to pin 13 on my Arduino uno.

Since you have the button connected to 5V, you should change the line:

if (buttonState == LOW) {

to

if (buttonState == HIGH) {

The problem is the button was constantly being read as pressed so maxtemp is set to 0 on every loop.

brunokc:

  pinMode(buttonPin,INPUT_PULLUP);

Not related to your problem but if you have a pull down resistor on pin 13(the 1k ohm resistor to 0V) then there's no point in setting the pin mode to INPUT_PULLUP, you should use INPUT instead. Alternately you could get rid of the 1K resistor and wire the button to ground instead of 5V and reverse your button logic(active LOW).

Thanks you many times ....

my head was about to explode :smiley:

Thanks thanks thanks thanks....