coding problem please help !!

Hi All !!

I've written a code for my room thermostat and that works fine. But now I have a problem that whe the temperature rises and the led was HIGH before it won't change to LOW when it fall's below temperature trigger. But if the previous button state was LOW everything works fine and the led turns LOW. So I need to change the button state to LOW. but how ??
here is the code:

#include <LiquidCrystal.h> 

const int  button  = A3;
const int  button1 = A4;
const int  ledPin1 = 8;
const int  ledPin  = 9;
const int  TEMPTRIGGER = 22.00;
const int  TEMPTRIGGER1 = 25.00;

int state1 = LOW;
int state2  = LOW;
int read1  = 0;    
int read2  = 0;    
int previous = LOW;
long time = 0;        
long debounce = 200;

float temperature = 0; // this stores the value for
LiquidCrystal lcd(10, 11, 12, 13, 14, 15, 16);

void setup() 
{
  pinMode(button, INPUT);
  pinMode(button1, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin1, OUTPUT);
  
  lcd.begin(16, 2); // tells Arduino the LCD dimensions
  lcd.setCursor(0,0);
  lcd.print("Made By Elvis K."); 
// print text and move cursor to start of next line
  lcd.setCursor(0,1);
  lcd.print("Prosim pocakaj...");
  delay(2000);
  lcd.clear(); // clear LCD screen
  lcd.setCursor(0,0);
  lcd.print("Temp je:");
  lcd.setCursor(0,1);
  lcd.print("Pump:1");
  lcd.setCursor(11,1);
  lcd.print("2");
}

void loop() 
{
  read1 = digitalRead(button);
  read2 = digitalRead(button1);
  
    if (read1 == HIGH && previous == LOW && millis() - time > debounce) {
    if (state1 == HIGH)
      state1 = LOW;
    else
      state1 = HIGH;

    time = millis();    
  }

  digitalWrite(ledPin, state1);
 
  

  previous = read1;
  
  if (read2 == HIGH && previous == LOW && millis() - time > debounce) {
    if (state2 == HIGH)
      state2 = LOW;
    else
      state2 = HIGH;

    time = millis();    
  }

  digitalWrite(ledPin1, state2);

  previous = read2;

  
  
  if(temperature >= TEMPTRIGGER || state1 == HIGH) {
     digitalWrite( ledPin, HIGH);
    lcd.setCursor(7,1);
    lcd.print("ON ");
  
  }
  else if (temperature <= TEMPTRIGGER){
    digitalWrite( ledPin, LOW);
    digitalWrite(state1, LOW);//Here is the problem <<<<<<<<<<<< i dont know wich command to use
      lcd.setCursor(7,1);
      lcd.print("OFF");
  }

      
  
    if(temperature >= TEMPTRIGGER1 || state2 == HIGH  ) {
    digitalWrite(ledPin1, HIGH);
    lcd.setCursor(13,1);
    lcd.print("ON");
  }

  else if (temperature <= TEMPTRIGGER1 || state2 == LOW || state2 == HIGH ){
    digitalWrite( ledPin1, LOW);
      lcd.setCursor(13,1);
      lcd.print("OFF");
  }
  
  temperature = analogRead(5); // store value from temp brick
  temperature = temperature +252-500;
  temperature = temperature / 10;
// maths to convert reading to temperature in Celsius. 
// may need calibrating, by comparing with real thermometer
// and adjusting value of -500
  delay (100); // wait for 100 milliseconds
  lcd.print(" Temperature is   ");
  lcd.setCursor(9,0); 
// move cursor to first character of second line
  lcd.print(temperature);
  lcd.println("C.   ");
  delay(500); // wait half a second
}

Thanks

digitalWrite(state1, LOW);//

"state1" is either 0 or 1, so you'd be writing LOW to pin zero or pin one.
These pins are part of the serial interface - I can't believe that is what you want.

And how do I change it from 1 to 0 ? becouse it doesnt turno off

Are you confusing "state1" with "ledPin1"?

No it think not. i think that the problem is that when the previous state was 1 and now the temperature is smaller than the temperaturetriger it wants to set the LED LOW but the button is stil 1 and in the next cycle it turns on. Or am I missing something?

I think it so.
Look carefully here:

digitalWrite(state1, LOW);//

The first parameter is a variable that has the value zero or one.
"digitalWrite" expects this to be a pin number to which it is going to write the value LOW.
So, this statement ALWAYS writes LOW to either pin zero or pin one.

I don't understand...
That is the same that I wrote...

That is the same that I wrote...

And that's why it doesn't work.

You SHOULD NOT write to the serial interface pins.

oh ok I misunderstood you. but what else should I write ??

I'm not sure what you're asking now.
Are you asking "How do I write
state1 = LOW;
or
state1 = false;"

?

very rough said I want the LED tu turn OFF When the temperature is lower than the temperaturetriger. And that is working as long the button state is LOW but when it's HIGH the led wont turn OFF when the temperature drops below temperaturetriger.

I hope you know what the problem is, it's hard to understand though if it's not clear i can upload a video.
And maybe I do want to know how to write state1 = LOW or state = false but that's what im trying to find out.

thanks for the help.

here is the link the led doesn't turn OFF when the temperature drops and the button is HIGH.

Setting a variable to HIGH or LOW, or true or false, or 0 or 1, and setting a pin to HIGH or LOW, or true or false, or 0 or 1, are two very different things that you seem to think are the same thing.

The first argument to digitalWrite() is the pin number. What you are putting in that position is NOT the pin number. It is the state that you want the pin to take on.

The second argument to digitalWrite() IS the state that the pin should take on - HIGH, LOW, or the value in state1.

And how am I going to fix this ?

And how am I going to fix this ?

Start by posting your current code.

It's in the first post

digitalWrite( ledPin, LOW);
    digitalWrite(state1, LOW);//Here is the problem <<<<<<<<<<<< i dont know wich command to use

I'm struggling coming to terms with you writing this sketch and having difficulty with the above two lines.......

I's not that hard and i've copied the reading part but I don't Know why it doesn't turn the LED OFF !!!

Ask yourself this: "What is the purpose of the button?"