help. display problem

i’ve been working on this project to control temperature in a box using temperature and humidity sensor SHT10, and rtc ds3231.

when the temperature reach certain level it should make either the lamp or the fan to work. The temperature and time will be displayed on a 16x2 LCD. I’m using HDD44780 lcd and PCF8574T I2C.

everything work fine, then the display stopped but the other part work just fine. There’s a “?” and “_” mark there. The display won’t change unless I reset the Arduino. I’ve tried adding a 10K pull-up resistor and 100uF capacitor but that didn’t change anything.

can someone tell me what’s wrong?. I’ve attached the picture of the LCD and I’m using this library LiquidCrystal_I2C

here is the code

#include <DS3231.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SHT1x.h>

#define dataPin 10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);
DS3231  clock;
RTCDateTime dt;

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

int lampu = 3; //lamp
int motor = 4;
int kipas = 5; //fan

void setup()
{
   clock.begin();
   lcd.begin(16,2);
  
   lcd.println("Temp Control");
   delay(2000);
   lcd.clear();
     
   pinMode(lampu, OUTPUT);
   pinMode(motor, OUTPUT);
   pinMode(kipas, OUTPUT);
}

void loop()
{
{
  dt = clock.getDateTime();
  int dataJam = dt.hour;     
  int dataMenit = dt.minute;
  int dataDetik = dt.second;

  float temp_c;
  float humidity;

  temp_c = sht1x.readTemperatureC();
  humidity = sht1x.readHumidity();
  
  lcd.setCursor(0,0);
  lcd.print("T:");
  lcd.print(temp_c);
  lcd.setCursor(8,0);
  lcd.print(dataJam);
  lcd.print(':');
  lcd.print(dataMenit);
  delay(1000);

   {
if (dt.second >= 10 && dt.second <=15){
digitalWrite(4, HIGH);
}
else {
  digitalWrite(4, LOW);
}
  }
      
if (temp_c >= 37 && temp_c <= 38) {
  digitalWrite(lampu, HIGH);
  analogWrite(kipas, LOW); 
  
  lcd.setCursor(0,1);
  lcd.print("Suhu Normal");
}

else if (temp_c > 38 ) {
  digitalWrite(lampu, LOW);
  analogWrite(kipas, HIGH);

  lcd.setCursor(0,1);
  lcd.print("Suhu Tinggi");
 }

else {
  digitalWrite(lampu, HIGH);
  digitalWrite(kipas, LOW); 
  
  lcd.setCursor(0,1);
  lcd.print("Suhu Rendah");
}
}
}

Oh, and another question is it possible to use if inside another if?
something like this

  if (days count > 21 && <23){
digitalWrite(4, LOW);
    
if (certain temperature) {
  do something;
}

else if (another certain temperature) {
  do something;
 }
 
else {
  do something;
}
}

if (days count => 23){
digitalWrite(4, LOW);
    
if (certain temperature) {
  do something;
}

else if (another certain temperature) {
  do something;
 }
 
else {
  do something;
}
}

and so on. . .

Yes, nested IF's work, so long as the enclosing curly braces are correctly placed, which appear incorrect in your program.

With your program open in the IDE, press cntrl-t to auto format your code. This will show the nesting errors of the braces.

@avr_fred
I see, thankyou. i’ll try making that multiple if code today.
and do you know what happen to my LCD display?

I don't see anything obviously wrong with the code but indeed your indentation is a mess, so there can very well be a hidden issue there.