why my function is not working?

Hi. I need a little help! I want to know my function isn't working.

#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"

#define DHTPIN 5
#define DHTTYPE DHT22

SoftwareSerial Btserial(3,2);
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,20,4);

const int s1 = 6;
const int s2 = 7;
int ctrl = 5;

int mode;

void setup() {
  Btserial.begin(9600);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(ctrl, OUTPUT);
  dht.begin();
  lcd.init();
  lcd.backlight();
}

void loop() {
  // put your main code here, to run repeatedly:
  float h = dht.readHumidity(); // ดึงค่าความชื้น
  float t = dht.readTemperature(); // ดึงค่าอุณหภูมิ
  
  if (Btserial.available()) {
    char ch = Btserial.read();

    if (ch == 'c')
    {
      lcd.setCursor(0,0);
      lcd.print("M");
      mode = 0;
    } else if (ch == 'a') {
      lcd.setCursor(0,0);
      lcd.print("A");
      mode = 1;
    }
    
    if (mode == 0)
    {
      if (ch == '0') {
      digitalWrite(s1,HIGH);
      digitalWrite(s2,LOW);
    } else if (ch == '1') {
      digitalWrite(s1,LOW);
      digitalWrite(s2,LOW);
    }
   }

   if (mode == 1)
   {
      float t = dht.readTemperature();
      
        if (t >= 27) {
        digitalWrite(s1,HIGH);
        digitalWrite(s2,LOW);
      } else {
        digitalWrite(s1,LOW);
        digitalWrite(s2,LOW);
      }
      
   }
}

  lcd.setCursor(0,1);
  lcd.print("temp : ");
  lcd.print(t);
}

in this part

if (mode == 1)
   {
      float t = dht.readTemperature();
      
        if (t >= 27) {
        digitalWrite(s1,HIGH);
        digitalWrite(s2,LOW);
      } else {
        digitalWrite(s1,LOW);
        digitalWrite(s2,LOW);
      }

every time when i switched to a (auto mode) while the temperature is more than 27, it's working. but when i start the program and the temperature is less than 27 and later i heated up my sensor to 27 celsius, it's not working, why?

your test is embedded in the if you switch mode / BT connexion --> so it's not executed all the time, only when you send a BT command. (indenting the code with ctrl-T will show you this)

you should separate the BT listening from the monitoring.

  if (Btserial.available()) {
    char ch = Btserial.read();

    if (ch == 'c') {
      lcd.setCursor(0, 0);
      lcd.print("M");
      mode = 0;
    } else if (ch == 'a') {
      lcd.setCursor(0, 0);
      lcd.print("A");
      mode = 1;
    }
  } // end BT listening

  if (mode == 0) { // may be you don't want to do this at every loop, in which case OK to embed in the BT connexion since it's stuff done only once
    if (ch == '0') {
      digitalWrite(s1, HIGH);
      digitalWrite(s2, LOW);
    } else if (ch == '1') {
      digitalWrite(s1, LOW);
      digitalWrite(s2, LOW);
    }
  } else if (mode == 1) {
    float t = dht.readTemperature();

    if (t >= 27) {
      digitalWrite(s1, HIGH);
      digitalWrite(s2, LOW);
    } else {
      digitalWrite(s1, LOW);
      digitalWrite(s2, LOW);
    }
  }

You don't have an initial value for the mode variable either - set it in setup().

MarkT:
You don't have an initial value for the mode variable either - set it in setup().

It is zero.

MarkT:
You don't have an initial value for the mode variable either - set it in setup().

as a global variable it will be zero initialized by the compiler. It's part of the standard, so you can count on it. (but agree that it's better to write it down)