problem in control temperatur air conditioning

i have problem when controlling start/stop air conditioning using DHT11 (temperatur sensor). could anyone help me to solve my problem.

this my scipt of program i made :

#include "DHT.h"
#include <Wire.h> // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>

#define DHTPIN 2 // what pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
// #define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);

// set the LCD address to 0x20 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address

void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
dht.begin();
// initialize the digital pins as an output.
pinMode(3, OUTPUT); // Tombol ON AC
digitalWrite(3, LOW); // set the pin to OFF

}

void loop() {

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
int h = dht.readHumidity();
int t = dht.readTemperature();

// set the cursor to (0,0):
lcd.setCursor(0, 0);
// print from 0 to 9:

lcd.print("Temp: ");
lcd.print(t);
lcd.print("C");
// set the cursor to (16,1):
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print("%");
delay(200);
// perintah on AC
if (t >= 28)
{
digitalWrite(3, HIGH); // press button AC ON
delay (1000);
digitalWrite(3, LOW); // press button AC ON
delay (100);
}
else if (16 <t && t <27)
{
digitalWrite(3, LOW); // release button
delay (1000);
}

}

What is the problem?

my problem is i want to control temperature but when i test using the hardware i installed it was looping on and off. and i don't get the status of ac running. how to define ac running without any hardware (using arduino function) ?

it was looping on and off.

If you are saying the air conditioner is cycling normally then all you have to do is print "on" or "off" as needed.
If it is cycling abnormally then you have noise interference and you will have to add some circuit filtering and or look at your power supplies for a solution.

  if (t >= 28)
  {
  digitalWrite(3, HIGH);   // press button AC ON
  delay (1000);
  digitalWrite(3, LOW);   // press button AC ON
  delay (100);
  }
    else if (16 <t && t <27)
  {
  digitalWrite(3, LOW);    // release button
   delay (1000);
  }

Assuming the A/C is switched via pin 3?
the above will 'turn on the a/c) for 1000miliseconds or 1 second and then turn it off, to leave the a/c on until the next test cycle remove or comment out the digitalwrite(3,LOW) line. try this

  if (t >= 28)
  {
  digitalWrite(3, HIGH);   // press button AC ON
  delay (1300);
  }
    else if (16 <t && t <27)
    {
     digitalWrite(3, LOW);   // press button AC ON
    delay (1300);
  {
     
  }

ok i have solved the problem. thanks