Egg Incubator with Arduino

Hello,

I am working on my new project “Egg Incubator with Arduino”.
My require is to control a specific temperature and humidity for 7 first days. Than to control another temperature from 7th day to 12th day and another specific temperature and humidity from 12th day to 21th day.

Here is the code. This code is working to control temperature and humidity. Al i want is to control temp. and hum. for specific days. i have started to do something about this but i need your help.

Thanks

==============================================================================


#include <DHT.h>;
#include <LiquidCrystal.h> 
#include <MyRealTimeClock.h>

#define DHTPIN 7           
#define DHTTYPE DHT21      
DHT dht(DHTPIN, DHTTYPE);   

int relay1 = 8;
int relay2 = 9;
int Contrast=75;

const byte seconds = 0;
const byte minutes = 0;
const byte hours = 16;
const byte days = 0;
const byte months = 0;
const byte years = 0;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  
MyRealTimeClock myRTC(6, 7, 8);

float hum;  
float temp; 

void setup()
{
  Serial.begin(9600);
  dht.begin();
  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  
  myRTC.setDS1302Time(50, 25, 00, 12 , 20, 07, 2020);

  analogWrite(6,Contrast);
  lcd.begin(16, 2);
}

void loop()
{
 
  hum  = dht.readHumidity();
  temp = dht.readTemperature();

  

////////////////////////////////////////

 if (days >= 10){

if (temp >= 30.0) {
  digitalWrite(relay1, HIGH); 
}
else if (temp <= 28.0) {
  digitalWrite(relay1, LOW); 
}

if (hum >= 60.0) {
  digitalWrite(relay2, LOW); 
}
else if (hum <= 50.0) {
  digitalWrite(relay2, HIGH); 
}
 }

////////////////////////////////////////



 else if (days = 15){

if (temp >= 30.0) {
  digitalWrite(relay1, HIGH); 
}
else if (temp <= 28.0) {
  digitalWrite(relay1, LOW); 
}

if (hum >= 60.0) {
  digitalWrite(relay2, LOW); 
}
else if (hum <= 50.0) {
  digitalWrite(relay2, HIGH); 
}
 }


//////////////////////////////////////



 else if (days = 18){

if (temp >= 30.0) {
  digitalWrite(relay1, HIGH); 
}
else if (temp <= 28.0) {
  digitalWrite(relay1, LOW); 
}

if (hum >= 60.0) {
  digitalWrite(relay2, LOW); 
}
else if (hum <= 50.0) {
  digitalWrite(relay2, HIGH); 
}
 }

///////////////////////////////////// 


 
  Serial.print("Lagështia e ajrit: ");
  Serial.print(hum);
  Serial.print("%,  Temperatura: ");
  Serial.print(temp);
  Serial.println(" Celsius");
  
  delay(2000);

  lcd.setCursor(0, 0);
  lcd.print("Temparatura: ");
  lcd.print (temp);
  lcd.print (" C");
   
  lcd.setCursor(0, 1);
  lcd.print("Lageshtia: ");
  lcd.print(hum);
  lcd.print(" %");

}

Once you set the date/time in the RTC, it should be commented out on the next code or else it will keep on setting the date/time.
You set the current date = 29 09 2021, set variable setDate = 29.
then get the current date from the rtc, store it in variable currentDate = myRTC.dayofmonth
so you can get days since the date was set by days = currentDate - setDate
Now check how many days are passed. You can use a while loop for checking days and have the temp and humidity check inside it.

Dear @shramik_salgaonkar is it possible just to count days using RTC. Its not important the date.
And based on the number of days to run the code.
For example:
From day 1 to 10 to run a specific code,
From day 11 to 16 to run another code and
From 17 to run another code.
And in the end to restart the loop with a button, if i press the button the code will start from the day 1 again.

Waiting for your reply.

This is what it is doing.

Dear @shramik_salgaonkar

I have used millis function on my code.
When i test the conditions with LED, its working. But its not working with my code.

Do you know why its not working it sir?

#include <DHT.h>;
#include <LiquidCrystal.h>

#define DHTPIN 7
#define DHTTYPE DHT21
DHT dht(DHTPIN, DHTTYPE);

int relay1 = 14;
int relay2 = 15;
int Contrast=75;
unsigned long myTime;
const int x = 120000;
const int y = 240000;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

float hum;
float temp;

void setup()
{
Serial.begin(9600);
dht.begin();
pinMode (14, OUTPUT);
pinMode (15, OUTPUT);

analogWrite(6,Contrast);
lcd.begin(16, 2);
}

void loop()
{

hum = dht.readHumidity();
temp = dht.readTemperature();

myTime = millis();

////////////////////////////////////////
if (temp >= 30.0) {
digitalWrite(relay1, HIGH);
}
else if (temp <= 28.0) {
digitalWrite(relay1, LOW);
}

if (hum >= 60.0) {
digitalWrite(relay2, LOW);
}
else if (hum <= 50.0) {
digitalWrite(relay2, HIGH);
}
////////////////////////////////////////

if (myTime >= x){ //…ITS NOT WORKING…//

if (temp >= 27.0) {
digitalWrite(relay1, HIGH);
}
else if (temp <= 25.0) {
digitalWrite(relay1, LOW);
//}

if (hum >= 60.0) {
digitalWrite(relay2, LOW);
}
else if (hum <= 50.0) {
digitalWrite(relay2, HIGH);
}
}
}

//////////////////////////////////////

else if (myTime >= y){ //…ITS NOT WORKING…//

if (temp >= 24.0) {
digitalWrite(relay1, HIGH);
}
else if (temp <= 22.0) {
digitalWrite(relay1, LOW);
}

if (hum >= 60.0) {
digitalWrite(relay2, LOW);
}
else if (hum <= 50.0) {
digitalWrite(relay2, HIGH);
}
}

/////////////////////////////////////

Serial.print(“Lagështia e ajrit: “);
Serial.print(hum);
Serial.print(”%, Temperatura: “);
Serial.print(temp);
Serial.println(” Celsius”);
Serial.print(myTime);

delay(2000);

lcd.setCursor(0, 0);
lcd.print(“Temparatura: “);
lcd.print (temp);
lcd.print (” C”);

lcd.setCursor(0, 1);
lcd.print(“Lagështia: “);
lcd.print(hum);
lcd.print(” %”);

}

If it’s working with an LED then it must be the relay. How do you have it connected?

I have wired relay correctly, because relays with another code are working.

@shramik_salgaonkar can you help me about this problem ?

Can you take a picture and share it? I can’t see how an LED will blink but a relay won’t turn on/off. It’s the same pin going high/low right?

@adam

This code is not working

#include <DHT.h>;
#include <LiquidCrystal.h>

#define DHTPIN 7
#define DHTTYPE DHT21
DHT dht(DHTPIN, DHTTYPE);

int relay1 = 14;
int relay2 = 15;
int Contrast=75;
unsigned long myTime;
const int x = 120000;
const int y = 240000;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

float hum;
float temp;

void setup()
{
Serial.begin(9600);
dht.begin();
pinMode (14, OUTPUT);
pinMode (15, OUTPUT);

analogWrite(6,Contrast);
lcd.begin(16, 2);
}

void loop()
{

hum = dht.readHumidity();
temp = dht.readTemperature();

myTime = millis();

////////////////////////////////////////
if (myTime < x ){

if (temp >= 30.0) {
digitalWrite(relay1, HIGH);
}
else if (temp <= 28.0) {
digitalWrite(relay1, LOW);
}

if (hum >= 60.0) {
digitalWrite(relay2, LOW);
}
else if (hum <= 50.0) {
digitalWrite(relay2, HIGH);
}
}
////////////////////////////////////////

if (myTime >= x){

if (temp >= 32.0) {
digitalWrite(relay1, HIGH);
}
else if (temp <= 25.0) {
digitalWrite(relay1, LOW);
//}

if (hum >= 60.0) {
digitalWrite(relay2, LOW);
}
else if (hum <= 50.0) {
digitalWrite(relay2, HIGH);
}
}
}

//////////////////////////////////////

if (myTime >= y){

if (temp >= 24.0) {
digitalWrite(relay1, HIGH);
}
else if (temp <= 22.0) {
digitalWrite(relay1, LOW);
}

if (hum >= 60.0) {
digitalWrite(relay2, LOW);
}
else if (hum <= 50.0) {
digitalWrite(relay2, HIGH);
}
}

/////////////////////////////////////

Serial.print(" Lagështia e ajrit: “);
Serial.print(hum);
Serial.print(”%, Temperatura: “);
Serial.print(temp);
Serial.println(” Celsius");
Serial.print(“Koha: “);
Serial.print(myTime/1000);
Serial.print(” Sekonda”);

delay(2000);

lcd.setCursor(0, 0);
lcd.print(“Temparatura: “);
lcd.print (temp);
lcd.print (” C”);

lcd.setCursor(0, 1);
lcd.print(“Lagështia: “);
lcd.print(hum);
lcd.print(” %”);

}

When i use the same code to turn on and turn off the LED is working

This code is working

unsigned long myTime;

int relay1 = 13;

const int x = 10000;
const int y = 30000;

void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("Time: ");
myTime = millis();

digitalWrite(relay1, HIGH);

if (myTime >= x) {
digitalWrite(relay1, LOW);
}

else if (myTime >= y) {
digitalWrite(relay1, HIGH);
}

Serial.println(myTime/1000); // prints time since program started

delay(1000); // wait a second so as not to send massive amounts of data
}

Can you help me to solve this problem ?

You’re using pin 13 in the one that works and pins 14 and 15 in the one that does not. Have you tried using pin 13? Also as I said pictures would be helpful.