I want to use DHT11+LCD+relay+Motor

I want build a Egg incubator
This is my code
write 1 week this code
input this code and doing well
but after few hour later

  1. relay off
  2. nothing or only "T" word on a lcd screen

I'm guessing,
the dht11 sensor keeps reading the value in 1ms
and the relay doesn't follow, so it looks like an error.

What I want is to retrieve the temperature and humidity values from DHT11,
display them on the LCD,
and adjust the heater and humidifier connected to the relay according to those values.
And I want to run the motor for 5 seconds every 6 hours

i have only one arduino, so i cant use daley();

#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define DHTPIN 2
#define DHTTYPE DHT11
#include <SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
DHT dht(DHTPIN, DHTTYPE);
int servo = 3;
int bulb = 4;
int Humidity = 5;
int led = 6;
int buzzer = 7;
int flame = 8;
int state = 0; 
long time = millis() ;
unsigned long previousMillis = 0;
const long delayTime = 5000;

void setup()
{
  lcd.init();
  lcd.backlight();
  Serial.begin(9600);
  dht.begin();
  pinMode(servo, OUTPUT);
  pinMode(bulb, OUTPUT);
  pinMode(Humidity, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(flame, INPUT);
}

void loop()
{
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  h = dht.readHumidity();
  
  unsigned long currentMillis = millis(); 
  
  lcd.setCursor(0, 0);
  lcd.print("TEMP: ");
  lcd.print(t);
  lcd.print("C");
  lcd.setCursor(0, 1);
  lcd.print("HUMIDITY: ");
  lcd.print(h);
  lcd.print("%");
  
  if(currentMillis - previousMillis >= delayTime)
  {
    previousMillis = currentMillis;
    lcd.clear();  
  }
  if (time + 21600000 < millis()) 
  {
    digitalWrite(servo, HIGH) ;
  }
  if (time + 21605000 < millis()) 
  {
    time = millis() ;
    digitalWrite(servo, LOW) ;
  }

  if ((5<=t) && (t<=38))
  {
    digitalWrite(bulb, HIGH) ;
  }
  else
  {
    digitalWrite(bulb, LOW) ; 
  }

  if ((5<=h) && (h<=80))
  {
    digitalWrite(Humidity, HIGH) ;
  }
  else
  {
    digitalWrite(Humidity, LOW) ;
  }
  state = digitalRead(flame);  

  digitalWrite(led, LOW);       
  noTone(buzzer);             
  
  if (state == 0)               
  {             
    Serial.println("ON");     
    digitalWrite(led, HIGH); 
    tone(buzzer, 500, 100);                
  }
  else                              
  {   
    Serial.println("OFF");  
    digitalWrite(led, LOW);   
    noTone(buzzer);           
  }
    Serial.print("humidity:");         
    Serial.println(h);                  
    Serial.print("temperature:");      
    Serial.println(t);  

}

{Please use the code tags, the </> button on the menu, in your future posts. Thanks, Moderator}

hi.ino (2.53 KB)

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile: