Starting an Arduino DIY incubator project

can you post your code? no sure what to tell you without going over the logic in your code.
 
I use a dht11 and I would also like to see the temperature in Celcius.I don't know wether the changes I made are the right ones






#include <LiquidCrystal.h>
#include "DHT.h"
#define DHTPIN 2 // Define the temp sensor data pin
#define DHTTYPE DHT11 // define the temp/hum sensor type
#define RELAY 0 // define the relay control pin
#include <Stepper.h>
#define STEPS_PER_MOTOR_REVOLUTION 32 //define the number of steps per motor revolution
// #define STEPS_PER_OUTPUT_REVOLUTION 32 * 64
#define STEPS_PER_OUTPUT_REVOLUTION 4 * 64 //define the number of steps to take each time the code loops
// 6 should give about 1 revolution per hour with a 2 second delay at the end of the loop
DHT dht(DHTPIN, DHTTYPE); //initialize the temp sensor
// LCD Connections:
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 1
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 1); //set up what port the LCD will use
int backLight = 13; // pin 13 will control the backlight
int is,im,ih,id,ida; // variables for time
float time,s1,m1,h1,d1; // Set up variables to calculate time
int ic,ip,ik;
int Steps2Take; // define the steper motor steps
byte thermo[8] ={B00100,B01010,B01010,B01110,B01110,B11111,B11111,B01110}; //thermometer icon
byte drop[8] ={B00100,B00100,B01010,B01010,B10001,B10001,B10001,B01110}; //drop icon
byte smile[8] = {B00000,B10001,B00000,B00000,B10001,B01110,B00000}; // smile icon
byte tim[8] = {B00000,B01110,B10101,B10101,B10011,B10001,B01110,}; // clock icon
//The pin connections need to be 4 pins connected
// to Motor Driver In1, In2, In3, In4 and then the pins entered
// here in the sequence 1-3-4-2 for proper sequencing (hook up driver bard pins to arduino 6789
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 7, 9, 8, 6);
void setup()
{
dht.begin(); //start the temp sensor
pinMode(RELAY, OUTPUT);
pinMode(backLight, OUTPUT);
digitalWrite(backLight, LOW); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.begin(20,4); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen
lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
lcd.print("Incubator 1.0"); // opening line
lcd.setCursor(0,1); // set cursor to column 0, row 1
lcd.print("Hatch Them!");
delay(2000);
// Uncomment if you want more text on the 4 line LCD (not used in 2 line LCDs)
lcd.setCursor(0,2); // set cursor to column 0, row 2
lcd.print("Row 3"); //Text for line 3
lcd.setCursor(0,3); // set cursor to column 0, row 3
lcd.print("Row 4"); // Text for line 4
lcd.createChar(0,thermo);
lcd.createChar(1,drop);
lcd.createChar(2,smile);
lcd.createChar(3,tim);
}
//loop to read the sensor and display
void loop(){
float h = dht.readHumidity(); // Read the humidity
float t = dht.readTemperature(true); // Read temperature in celsius
float f = dht.readTemperature(); // get the temperature in Fahreheit
// uncomment to compute heat index in Fahrenheit (the default)
//float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
time=millis(); // Get time in milliseconds since tunit turn on
s1=time/1000; // Convert time to seconds, minutes, hours, days
m1=s1/60;
h1=m1/60;
d1=h1/24;
id=int(d1); // Strip out remainder to leave Days:Hours:Minutes:Seconds
ih=int((d1-int(d1))*24);
im=int((h1-int(h1))*60);
is=int((m1-int(m1))*60);
// Calculate approximate days till hatch (assume 21 days to hatch)
ida=21-id;
if (isnan(h) || isnan(t) || isnan(f)){
// if sensor can't be read
lcd.clear();
lcd.setCursor(0,0);
lcd.print("failed to read sensor");
delay(50000);
return;
}
else {
//sensor was read succesfully so print values to LCD
lcd.clear(); // Clear the LCD
//Print temperature and humidity in first two lines
lcd.setCursor(0,0);
lcd.print("Temperature:");
lcd.print(" ");
lcd.write(byte(0)); // Write the Thhermometer icon
lcd.print(" ");
lcd.print(t,1);
lcd.print(" C ");
lcd.setCursor(0,1);
lcd.write(byte(1)); // Write the drop icon
lcd.print("Humidity:");
lcd.print(" ");
lcd.print(h,0);
lcd.print(" %");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.write(byte(3));
lcd.print(" ");
// Print time in format Time: xxd:xxh:xxm:xxs
lcd.print(id);
lcd.print("d:");
lcd.print(ih);
lcd.print("h:");
lcd.print(im);
lcd.print("m:");
lcd.print(is);
lcd.print("s");
lcd.setCursor(0,2);
lcd.print("_-_-_-_-_-_-_-_-_-_-");
lcd.setCursor(0,3);
// Print days left till hatch
lcd.print("Days left:");
lcd.print(21-id);
lcd.print(" ");
lcd.write(byte(2));
//Temperature controller
if(t < 36.0){ // Set the temperature for the relay to come on (somewhere around 90-101F to get eggs to hatch)
digitalWrite(RELAY,LOW); // Turns ON Relay
}
else{
digitalWrite(RELAY,HIGH); // Turns Relay Off
}
ic= im % 1;
ik=im-ip;
if(ic==0 && ik != 0){
ip=im;
lcd.setCursor(0,2);
lcd.print("Turning Eggs!_-_-_-_");
Steps2Take = STEPS_PER_OUTPUT_REVOLUTION ; // define stepper CW steps
small_stepper.setSpeed(50); // set stepper max speed
small_stepper.step(Steps2Take); // take the steps
//Steps2Take = - STEPS_PER_OUTPUT_REVOLUTION; // define stepper CCW 1 steps
//small_stepper.setSpeed(50); // set stepper to max speed
//small_stepper.step(Steps2Take); // take the steps
}
// Puase for 2 seconds
delay(500);
}
}
 
dht.readTemperature(true) reads the temperature in degrees F. So you need to make it dht.readTemperature(). Then just use t instead of f in the print statement as you have it. The code will turn the stepper every minute. So it is normal that you see the stepper continue to turn every minute. The intent was to set that number to the interval to turn the eggs i.e. every eight hours. To do that you would set ic=ih %8; The variable im keeps track of the minutes with a max value of 59. The variable ih keeps track of the number of hours with a max value of 23.
 
#include <EEPROM.h>
#include <RTCx.h>
//library for comminication between ic2 rtc and lcd
#include <Wire.h>
// Lİbrary to reset Arduino if it lockss up
#include <avr/wdt.h>
// Library for comminication with LCD
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
// Library forDHT11 or DHT22
#include "DHT.h"

#define DHTPIN 3 // DHT22 PIN Digital 3
#define DHTTYPE DHT22 // We use DHT 22 Sensor

//LCD
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // 0x3F is the I2C bus address for an unmodified module

DHT dht(DHTPIN, DHTTYPE);


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

float at = 0; // Adjusted temperature (EEPROM)
float t; // Temperature
float t_calibre = 0; // temperature calibration (After factory Reset 0 ) (EEPROM) (-5.00 ... 0 .. +5.00 )
long tmesec = 0; // read tempreature every second
float t_max; // Maximum temprature
float h_max; // Maximum humidity
int ah = 0 ; // Adjusted value for humidity (EEPROM)
float h; // Humidity
float h_calibre = 0; // Humidity calibration
int motor_sec = 0; // How many seconds motor turns the eggs (EEPROM) (1 - 15 Seconds)
int motor_time = 0; // How often motor turns the eggs (EEPROM) (60 - 120 - 180 240 Minutes)
int rest_time = 0; // Daily resting for eggs (EEPROM) (0 - 60 - 120 Minutes)
int incub_time = 21; // Total incubation time (EEPROM) (1 - 45 Days)
long incub_time_start = 0; // Stating day of incubation Unixtimestamp (EEPROM)
long days_left = 0; // Days left for incubation
int beep = 11; // Alarm buzzer pin
int next_motor_time = -1; // Calculates the next turning time. (if it is 14:45:55 makes it 14 )
int last_motor_time = -1; // Not to let the motor turn more than one time in an hour keeps the track of last turning time (if it is 14:45:55 makes it 14 )
long motorMillis = 0; // Turning time as miliseconds. Current ms > turning ms + (turning_sec * 1000) turning stops.
char mode = 'S'; // Menu S = Setup R = Working W = Clock adjustment M = Main Menu
int menu = 0; // Main Menu 0 => Settings menu 1=> Clock adjustment 2=> Factory reset 3=>Tempereture calibarasyon 4=>Humidity calibarasyon 5=>New incubation 6=>Exit
char adjust_settings = 'H'; // Menu helper values H = Erases starting date E = Does not erase Date

//////////////////////////////////////////
// Buttons
int downPin = 8; // Down button digital pin 8
int upPin = 7; // Up button digital pin 7
int okPin = 9; // OK button digital pin 9
int menuPin = 10; // Menu Button digital pin 10
int down = 0;
int up = 0;
int ok = 0;

//////////////////////////////////////////
// Relays
#define RELAY_TEMP 4 // Heater digital pin 4
#define RELAY_HUM 5 // Humidifier digital pin 5
#define RELAY_MOTOR 6 // Motor digital pin 6

//////////////////////////////////////////
// LED ler
int LED0 = 14; // TEMP Led Pin 14
int LED1 = 15; // Humidifier Led Pin 15
int LED2 = 16; // Motor Led Pin 16
const int buzzerPin = 11;
void setup() {
lcd.begin(20, 4);
lcd.setBacklight(HIGH);
lcd.home (); // go home
lcd.setCursor(1,0); //Start at character 3 on line 0
lcd.print("INCUBATOR PROGRAM");
delay(1000);
lcd.setCursor(2,1);
lcd.print(" By Levent Tore");
delay(1000);
lcd.setCursor(4,2);
lcd.print("GOOD LUCK");
delay(1000);
lcd.setCursor(2,3);
lcd.print("www.kulucka.ga");
delay(2000);
lcd.setBacklight(0x1);
lcd.clear();
// Locking up
wdt_enable(WDTO_4S); // Call the functions for lockup. İf it does not come to this line in 4 seconds Arduino resets itself
dht.begin(); // Start DHT22
delay(2000);
// Leds are output
pinMode(LED0, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
// Buzzer
pinMode(3, OUTPUT);
pinMode(buzzerPin, OUTPUT);

// Relays
pinMode(RELAY_TEMP, OUTPUT);
pinMode(RELAY_HUM, OUTPUT);
pinMode(RELAY_MOTOR, OUTPUT);
digitalWrite(RELAY_TEMP,HIGH);
digitalWrite(RELAY_HUM,HIGH);
digitalWrite(RELAY_MOTOR,HIGH);


// When connected to Pc for DEBUG mode
// Serial.begin(9600);

// Starting Wire protocol for I2C communication
Wire.begin();
////////////////////////////////////
//Starting clock
uint8_t addressList[] = {RTCx::MCP7941xAddress, RTCx::DS1307Address};
if (rtc.autoprobe(addressList, sizeof(addressList))) {
// Serial.print("Autoprobe found ");
switch (rtc.getDevice()) {
case RTCx::DS1307:
// Serial.print("DS1307");
break;
case RTCx::MCP7941x:
// Serial.print("MCP7941x");
break;
default:
// Ooops. Must update this example!
// Serial.print("unknown device");
break;
}
// Serial.print(" at 0x");
// Serial.println(rtc.getAddress(), HEX);
}
else {
// Nothing found at any of the addresses listed.
// Serial.println("No RTCx found");
return;
}

// Enable the battery backup. This happens by default on the DS1307
// but needs to be enabled on the MCP7941x.
rtc.enableBatteryBackup();

// Ensure the oscillator is running.
rtc.startClock();

if (rtc.getDevice() == RTCx::MCP7941x) {
// Serial.print("Calibration: ");
// Serial.println(rtc.getCalibration(), DEC);
// rtc.setCalibration(-127);
}

rtc.setSQW(RTCx::freq4096Hz);
////////////////////////////////////////////////////////////


mode = EEPROM.read(16); // Reading working mode from EEPROM
if(mode == 0)
{
// İf there is no mode going directly to General Settings Menu.
mode = 'S';
EEPROM.write(16, mode);
}

// İf the mode is working mode reading necessery data from EEPROM only one time.
if(mode == 'R')
{
//at = EEPROM.read(20);
EEPROM_readAnything(20, at);
ah = EEPROM.read(24);
motor_sec = EEPROM.read(28);
motor_time = EEPROM.read(32);
rest_time = EEPROM.read(36);
incub_time = EEPROM.read(40);
// Reading timestamp
EEPROM_readAnything(44, incub_time_start);
// Calibration
EEPROM_readAnything(54, t_calibre);
}

// Opening screen and clearing it
lcd.setBacklightPin(3,POSITIVE);
lcd.setBacklight(HIGH);
lcd.begin(20, 4);
lcd.clear();


// Buttons are input.
pinMode(downPin, INPUT_PULLUP);
pinMode(upPin, INPUT_PULLUP);
pinMode(okPin, INPUT_PULLUP);
pinMode(menuPin, INPUT_PULLUP);
}

// values to understand if holding the buutons pressed
long onTime = 0;
int lastReadingOk = LOW;
int hold = 0;
// values for time adjustment
int clock_menu = 1;
int temp_date = 0;
int temp_day = 0;
int temp_month = 0;
int temp_year = 0;
int temp_hour = 0;
int temp_minute = 0;

// Main Program Starts here

void loop() {


wdt_reset(); // Call the functions for lockup. İf it does not come to this line in 4 seconds Arduino resets itself
//For clock
struct RTCx::tm tm;
///////////////////////
// Adjusting Time
if(mode == 'W')
{
down = digitalRead(downPin);
up = digitalRead(upPin);
ok = digitalRead(okPin);

lcd.setBacklight(HIGH);

lcd.setCursor(0, 0);
lcd.print("Adjust Date ");

if(temp_date == 0)
{
rtc.readClock(tm);
temp_day = tm.tm_mday;
temp_month = tm.tm_mon+1;
temp_year = tm.tm_year+1900;
temp_hour = tm.tm_hour;
temp_minute = tm.tm_min;
temp_date = 1;
}

lcd.setCursor(1, 2);
if(temp_day < 10){lcd.print(" ");}
lcd.print(temp_day);
lcd.print("/");
if(temp_month < 10){lcd.print(" ");}
lcd.print(temp_month);
lcd.print("/");
lcd.print(temp_year);
lcd.print("-");
if(temp_hour < 10){lcd.print("0");}
lcd.print(temp_hour);
lcd.print(":");
if(temp_minute < 10){lcd.print("0");}
lcd.print(temp_minute);


lcd.setCursor(0, 3);
lcd.print("Accept OK");

if(clock_menu == 1)
{
//Adjust Day
lcd.setCursor(2, 2);
lcd.blink();
if(down == HIGH)
{
temp_day = temp_day - 1;
}
if(up == HIGH)
{
temp_day = temp_day + 1;
}
if(temp_day < 1)
{
temp_day = 1;
}
if(temp_day > 31)
{
temp_day = 31;
}
}
if(clock_menu == 2)
{
//Set the month
lcd.setCursor(5, 2);
lcd.blink();
if(down == HIGH)
{
temp_month = temp_month - 1;
}
if(up == HIGH)
{
temp_month = temp_month + 1;
}
if(temp_month < 1)
{
temp_month = 1;
}
if(temp_month > 12)
{
temp_month = 12;
}
}
if(clock_menu == 3)
{
//Adjust year
lcd.setCursor(10, 2);
lcd.blink();
if(down == HIGH)
{
temp_year = temp_year - 1;
}
if(up == HIGH)
{
temp_year = temp_year + 1;
}
if(temp_year < 2017)
{
temp_year = 2017;
}
if(temp_year > 2020)
{
temp_year = 2020;
}
}
if(clock_menu == 4)
{
//Saat Ayarla
lcd.setCursor(13, 2);
lcd.blink();
if(down == HIGH)
{
temp_hour = temp_hour - 1;
}
if(up == HIGH)
{
temp_hour = temp_hour + 1;
}
if(temp_hour < 0)
{
temp_hour = 0;
}
if(temp_hour > 23)
{
temp_hour = 23;
}
}
if(clock_menu == 5)
{
//Adjust minutes
lcd.setCursor(16, 2);
lcd.blink();
if(down == HIGH)
{
temp_minute = temp_minute - 1;
}
if(up == HIGH)
{
temp_minute = temp_minute + 1;
}
if(temp_minute < 0)
{
temp_minute = 59;
}
if(temp_minute > 59)
{
temp_minute = 0;
}
}

if(ok != HIGH)
{

clock_menu ++;
if(clock_menu > 5)
{
if(ok != HIGH)
{
// Clock adustment

tm.tm_min = temp_minute;
tm.tm_hour = temp_hour;
tm.tm_wday = 0;
tm.tm_mday = temp_day;
tm.tm_mon = temp_month-1;
tm.tm_year = temp_year-2017;

rtc.setClock(&tm);
clock_menu = 1;
temp_date = 0;
mode = 'R';
lcd.clear();
lcd.noBlink();
}
}
}
delay(100);
}

////////////////////////////
// Main Menu
if(mode == 'A')
{
// İf Menu is selected Turn off heater and humidifier
if(digitalRead(RELAY_TEMP)!=HIGH)
{
digitalWrite(RELAY_TEMP,HIGH);
delay(50);
digitalWrite(LED0,LOW);
}
if(digitalRead(RELAY_HUM)!=HIGH)
{
digitalWrite(RELAY_HUM,HIGH);
delay(50);
digitalWrite(LED1,LOW);
}

// Menu 0 -> Settings
// Menu 1 -> Clock
// Menu 2 -> Reset
// Menu 3 -> Temperature Calibration
// Menu 4 -> Humidity Calibration
// Menu 5 -> New incubation
// Menu 6 -> Exit
down = digitalRead(downPin);
up = digitalRead(upPin);
ok = digitalRead(okPin);
lcd.setCursor(0, 0);
lcd.print("SELECT MENU ");
if(down == HIGH)
{
menu = menu - 1;
}
if(up == HIGH)
{
menu = menu + 1;
}
if(menu < 0){menu = 6;}
if(menu > 6){menu = 0;}

if(menu == 0)
{
lcd.setCursor(0, 1);
lcd.print("Settings ");
}
if(menu == 1)
{
lcd.setCursor(0, 1);
lcd.print("Adjust Date Time");
}
if(menu == 2)
{
lcd.setCursor(0, 1);
lcd.print("Factory Settings ");
}
if(menu == 3)
{
lcd.setCursor(0, 1);
lcd.print("Tempreture Calibration ");
}
if(menu == 4)
{
lcd.setCursor(0, 1);
lcd.print("Humidity Calibration ");
}
if(menu == 5)
{
lcd.setCursor(0, 1);
lcd.print("New Incubation");
}
if(menu == 6)
{
lcd.setCursor(0, 1);
lcd.print("Exit ");
}
if(ok == LOW)
{
lcd.clear();
if(menu == 0)
{
adjust_settings = 'E';
mode = 'S';
}
if(menu == 1)
{mode = 'W';}
if(menu == 2)
{
/////////////
// Eppromu sil
mode = 'S';
for (int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0);
}
}
if(menu == 3)
{
// Temperature Calibration
mode = 'H';
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temperature Calibration");

}
if(menu == 4)
{
// Humidity Calibration
mode = 'G';
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Humidity Calibration");

}
if(menu == 5)
{
// Enter New İncubation
mode = 'S';
adjust_settings = 'H';
}

if(menu == 6)
{
// Continue to work
mode = 'R';
}
menu = 0;
}
delay(150);
}

///////////////////////////////
// Temperature Sensor Calibration + -
if(mode == 'H')
{
down = digitalRead(downPin);
up = digitalRead(upPin);
ok = digitalRead(okPin);

Serial.println(down);
if(down == LOW)
{
t_calibre = t_calibre + 0.1;
}
if(up == LOW)
{
t_calibre = t_calibre - 0.1;
}
if(t_calibre > 5) {t_calibre = +5;}
if(t_calibre < -5) {t_calibre = -5;}
lcd.setCursor(0, 1);
lcd.print(t_calibre);
lcd.print(" ");
if(ok == LOW)
{
// Temperature Calibration
EEPROM_writeAnything(54, t_calibre);
mode = 'A';
menu = 3;
delay(150);
}
delay(100);
}

// Humidity Sensor Calibration + -
if(mode == 'G')
{
down = digitalRead(downPin);
up = digitalRead(upPin);
ok = digitalRead(okPin);

Serial.println(down);
if(down == LOW)
{
h_calibre = h_calibre + 0.1;
}
if(up == LOW)
{
h_calibre = h_calibre - 0.1;
}
if(h_calibre > 10) {h_calibre = +10;}
if(h_calibre < -10) {h_calibre = -10;}
lcd.setCursor(0, 1);
lcd.print(h_calibre);
lcd.print(" ");
if(ok == LOW)
{
// Humidity calibration
EEPROM_writeAnything(64, h_calibre);
mode = 'A';
menu = 4;
delay(150);
}
delay(100);
}


// General Settings Menu
if(mode == 'S')
{
lcd.setCursor(0, 0);
lcd.print("GENERAL SETTINGS");
down = digitalRead(downPin);
up = digitalRead(upPin);
ok = digitalRead(okPin);
/////////////////
// Temperature Settings
if(menu == 0)
{
if(at == 0) { at = 37,5;};
lcd.setCursor(0, 1);
lcd.print("TEMPERATURE: ");
if(down == HIGH)
{
at = at - 0.1;
}
if(up == HIGH)
{
at = at + 0.1;
}
if(at <= 25)
{
at = 25;
}
if(at > 41)
{
at = 41;
}
if(ok != HIGH)
{
while(ok != HIGH)
{
ok = digitalRead(okPin);
}
menu = 1;
lcd.clear();
}
lcd.print(at);
lcd.print(" C");
lcd.setCursor(0, 4);
lcd.print("OK for Next");
}
// Humidity Settings
if(menu == 1)
{
lcd.setCursor(0, 1);
lcd.print("HUMIDITY : ");
if(ah == 0) { ah = 50;};

if(down == HIGH)
{
ah = ah - 1;
}
if(up == HIGH)
{
ah = ah + 1;
}
if(h <= 40)
{
ah = 40;
}
if(ah > 85)
{
ah = 85;
}
lcd.print(ah);
lcd.print(" %");
lcd.setCursor(0, 4);
lcd.print("OK for NEXT");
if(ok != HIGH)
{
while(ok != HIGH)
{
ok = digitalRead(okPin);
}
menu = 2;
lcd.clear();
}
}
// Motor Settings
if(menu == 2)
{
if(motor_sec == 0) {motor_sec = 10;};
lcd.setCursor(0, 1);
lcd.print("Motor turning seconds : ");
lcd.setCursor(0, 2);
lcd.print("Turninig time: ");
lcd.setCursor(0, 4);
lcd.print("OK for NEXT");
lcd.setCursor(17, 1);
lcd.print(motor_sec);
lcd.print(" ");
lcd.setCursor(14, 1);
lcd.blink();

if(down == HIGH)
{
motor_sec = motor_sec - 1;
}
if(up == HIGH)
{
motor_sec = motor_sec + 1;
}
if(motor_sec <= 1)
{
motor_sec = 1;
}
if(motor_sec > 15)
{
motor_sec = 15;
}

if(ok != HIGH)
{
while(ok != HIGH)
{
ok = digitalRead(okPin);
lcd.noBlink();
}
menu = 3;
lcd.clear();
}
}
// MOTOR TIME
if(menu == 3)
{
if(motor_time == 0) {motor_time = 60;};
lcd.setCursor(0, 1);
lcd.print("Turning Time Sec : ");
lcd.setCursor(0, 2);
lcd.print("Motor Time: ");
lcd.setCursor(17, 1);
lcd.print(motor_sec);
lcd.print(" ");
lcd.setCursor(16, 2);
if(motor_time == 60) {lcd.setCursor(17, 2);};
lcd.print(motor_time);
lcd.setCursor(0, 4);
lcd.print("OK for NEXT");

lcd.setCursor(15, 2);
lcd.blink();

if(down == HIGH)
{
motor_time = motor_time - 60;
}
if(up == HIGH)
{
motor_time = motor_time + 60;
}
if(motor_time <= 60)
{
motor_time = 60;
}
if(motor_time > 240)
{
motor_time = 240;
}
if(ok != HIGH)
{
while(ok != HIGH)
{
ok = digitalRead(okPin);
lcd.noBlink();
}
menu = 4;
// Adjust settings for egg turning
next_motor_time = -1;
last_motor_time = -1;
lcd.clear();
}

}
// Eggs Resting Time
if(menu == 4)
{
lcd.setCursor(0, 1);
lcd.print("Resting Time minute.: ");

lcd.setCursor(10, 2);
if(rest_time < 70) {lcd.print(" "); lcd.setCursor(11, 2);};

lcd.print(rest_time);

if(down == HIGH)
{
rest_time = rest_time - 60;
}
if(up == HIGH)
{
rest_time = rest_time + 60;
}
if(rest_time <= 0)
{
rest_time = 0;
}
if(rest_time > 120)
{
rest_time = 120;
}

if(ok != HIGH)
{
while(ok != HIGH)
{
ok = digitalRead(okPin);
lcd.noBlink();
}
menu = 5;
lcd.clear();
}

}
if(menu == 5)
{
lcd.setCursor(0, 1);
lcd.print("İncubation Time days: ");

lcd.setCursor(10, 2);
if(incub_time < 10) {lcd.print(" "); lcd.setCursor(11, 2);};

lcd.print(incub_time);

lcd.setCursor(0, 3);
lcd.print("OK for NEXT");

if(down == HIGH)
{
incub_time = incub_time - 1;
}
if(up == HIGH)
{
incub_time = incub_time + 1;
}
if(incub_time <= 1)
{
incub_time = 1;
}
if(incub_time > 45)
{
incub_time = 45;
}
if(ok != HIGH)
{
if(ok != HIGH)
{
while(ok != HIGH)
{
ok = digitalRead(okPin);
lcd.noBlink();
}
mode = 'R';
menu = 0;
lcd.clear();

EEPROM.write(16, mode);
//Temperature
EEPROM_writeAnything(20, t);
// Humidity
EEPROM.write(24, h);
// Motor turning
EEPROM.write(28, motor_sec);
// Motor turning time
EEPROM.write(32, motor_time);
// Eggs resting
EEPROM.write(36, rest_time);
// İncubation Period
EEPROM.write(40, incub_time);
// İncubataion ending Time
rtc.readClock(tm);
RTCx::time_t t = RTCx::mktime(&tm);

if(adjust_settings == 'E')
{

}
if(adjust_settings == 'H')
{
// Writing current time as starting time. Unixtimestamp

EEPROM_writeAnything(44, t);
}
}
}
}
delay(100);
}
//////////////////
// Working Menu
if(mode == 'R')
{


up = digitalRead(upPin);
// İf up button is pressed turns the eggs
while(up != HIGH)
{
if(digitalRead(RELAY_MOTOR)!=LOW)
{
digitalWrite(RELAY_MOTOR,LOW);
digitalWrite(LED2,HIGH);
}
up = digitalRead(upPin);
// Locking up
wdt_reset(); // Call the functions for lock up. İf it does not come to this line in 4 seconds Arduino resets itself
}

// Button
ok = digitalRead(okPin);

// Heater Control
lcd.setCursor(0, 0);
lcd.print("A");
lcd.setCursor(1, 0);
lcd.print(at);
lcd.setCursor(0, 1);
lcd.print("A");
lcd.print(ah);
lcd.setCursor(0, 2);
lcd.print("D:");
lcd.setCursor(2, 2);
lcd.print(incub_time);
/////////////////
// Check temperature and humidity every 2 seconds
//
if(tmesec != tm.tm_sec)
{
t = dht.readTemperature();
t = t + t_calibre;
h = dht.readHumidity();
h = h + h_calibre;
tmesec = tm.tm_sec;
}
/////////////////////////
//buzzer alarm
if (h >= 85 <= 35) {

tone(buzzerPin, 100);


delay(100);

noTone(buzzerPin);


delay(100);


}

else {

noTone(buzzerPin);


}
/////////////////////////
if (t >= 43 <= 30) {

tone(buzzerPin, 100);


delay(100);

noTone(buzzerPin);


delay(100);


}

else {

noTone(buzzerPin);


}
// Turn Off Humidifier
if(ah < h)
{
// Turn Off Humidifier
digitalWrite(RELAY_HUM,HIGH);
delay(20);
digitalWrite(LED1,LOW);
// Fark cok ise nem alma icin bir relay ayarlanabilir.
lcd.setCursor(19, 1);
lcd.print(" ");
}
// Turn Off Heater
if(at < t)
{
// Turn Off Heater
digitalWrite(RELAY_TEMP,HIGH);
delay(50);
digitalWrite(LED0,LOW);
lcd.setCursor(19, 0);
lcd.print(" ");
}
/////////////////////////////////////////////
// Checking DHT22
if (isnan(h) || isnan(t))
{
// Humidity Sensor not working
lcd.clear();
lcd.setCursor(5, 3);
lcd.print("ERROR");

if (isnan(h))
{
lcd.print(" HUMIDITY");
}
if (isnan(t))
{
lcd.print(" TEMPERATURE");
}
// İf it gives error tun off the heater and humidifier
if(digitalRead(RELAY_TEMP)!=HIGH)
{
digitalWrite(RELAY_TEMP,HIGH);
delay(50);
}
if(digitalRead(RELAY_HUM)!=HIGH)
{
digitalWrite(RELAY_HUM,HIGH);
delay(50);
}
// Isı sensoru hatalı oldugu icin Reset atsin diye 5 SN delay veriyoruz
delay(5000);
}
else
{
lcd.setCursor(12, 3);
lcd.print(" ");

lcd.setCursor(7, 0);
lcd.print(t, 2);

if(t > t_max)
{
t_max = t;
}
// Maximum Tempereture
lcd.setCursor(13, 0);
lcd.print("M");
lcd.setCursor(14, 0);
lcd.print(t_max, 2);
if(h > h_max)
{
h_max = h;
}
// Write Maximum humidity
lcd.setCursor(13, 1);
lcd.print("M");
lcd.setCursor(14, 1);
lcd.print(h_max, 2);


lcd.setCursor(4, 1);
lcd.print("Hum");
lcd.print(h);


// Calculate days left
rtc.readClock(tm);
RTCx::time_t t = RTCx::mktime(&tm);
///////////////////////////////////////
// Subtract todays date from last day
days_left = t - incub_time_start;
// Calculating days left
days_left = days_left / 60 / 60 / 24;
days_left = incub_time - days_left;

//Serial.println(incub_time_start);

lcd.setCursor(5, 2);
lcd.print(days_left);
lcd.setCursor(7, 2);
lcd.print(" Day");

rtc.readClock(tm);
lcd.setCursor(1, 3);
printTm(Serial, &tm);


lcd.setCursor(12, 2);
lcd.print("Turn:");
if(next_motor_time < 10 && next_motor_time > 0){lcd.print("0"); }
if(next_motor_time > -1)
{
lcd.print(next_motor_time);
}
delay(100);
}
/////////////////
// Turn off the motor

if (millis() - motorMillis >= motor_sec*1000 && motorMillis>0)
{
digitalWrite(RELAY_MOTOR,HIGH);
delay(50);
digitalWrite(LED2,LOW);
motorMillis = 0;
}
if(tm.tm_sec == 30)
{
////////////////////////////////////////
// EGG TURNİNG
// motor_time 60->1 120->2 180->3 240->4

//İf turnıng the eggs is not setup
if(next_motor_time == -1)
{
// Turn the eggs after machine starts up
next_motor_time = tm.tm_hour;
}

if(tm.tm_hour == next_motor_time && last_motor_time != next_motor_time or ok != HIGH)
{
// Turn the eggs
//Serial.print(digitalRead(RELAY_MOTOR));

digitalWrite(RELAY_MOTOR,LOW);
delay(50);
digitalWrite(LED2,HIGH);
motorMillis = millis();
if(motor_time == 60)
{next_motor_time = tm.tm_hour+1;}
if(motor_time == 120)
{next_motor_time = tm.tm_hour+2;}
if(motor_time == 180)
{next_motor_time = tm.tm_hour+3;}
if(motor_time == 240)
{next_motor_time = tm.tm_hour+4;}
// Bir Daha Bu saatte Donmesin
last_motor_time = tm.tm_hour;
if(next_motor_time > 23) {next_motor_time = next_motor_time-24;}
}
}

if(tm.tm_sec == 15 or tm.tm_sec == 45)
{
///////////////
// Eggs Resting
if((tm.tm_hour == 12 && rest_time > 0) or (tm.tm_hour == 13 && rest_time > 60))
{
// TURN OFF HEATER and HUMIDIFIER
if(digitalRead(RELAY_TEMP)!=HIGH)
{
digitalWrite(RELAY_TEMP,HIGH);
delay(50);
}
if(digitalRead(RELAY_HUM)!=HIGH)
{
digitalWrite(RELAY_HUM,HIGH);
delay(50);
}
lcd.setCursor(19, 0);
lcd.print("S");
}
else
{
// Heater Control
if(at > t)
{
// Turn on the Heater
digitalWrite(RELAY_TEMP,LOW);
delay(50);
digitalWrite(LED0,HIGH);
delay(50);
lcd.setCursor(19, 0);
lcd.print("W");
}
//////////////////////////////////////////
// Humidity Control
// Humidity is Low
if(ah > h)
{
// Turn On the Humidifier
digitalWrite(RELAY_HUM,LOW);
digitalWrite(LED1,HIGH);
lcd.setCursor(19, 1);
lcd.print("W");
}
}
}



// to go back to setup
// to go to main menu
menu = digitalRead(menuPin);
if (menu == LOW && lastReadingOk == HIGH) {
// Serial.println("bas 1");
onTime = millis();
}
//held
if (menu == LOW && lastReadingOk == LOW) {
if ((millis() - onTime) > 500) {
hold = 1;
if ((millis() - onTime) > 500) {
hold = 2;
}
}
}
if (menu == HIGH && lastReadingOk == LOW)
{
onTime = 0;
if (hold == 1) {
hold = 0;
mode = 'A';
lcd.clear();
}
if (hold == 2) {
hold = 0;
mode = 'A';
lcd.clear();
}
}
lastReadingOk = menu;
delay(20);
}
}

// print date and time on LCD screen
void printTm(Stream &str, struct RTCx::tm *tm)
{
lcd.setCursor(0, 3);

if(tm->tm_mday<10){lcd.print('0');}
lcd.print(tm->tm_mday);
lcd.print('/');
if(tm->tm_mon<10){lcd.print('0');}
lcd.print(tm->tm_mon + 1);
lcd.print('/');
lcd.print(tm->tm_year + 1900);

lcd.print(' ');
lcd.setCursor(15, 3);
if(tm->tm_hour<10){lcd.print('0');}
lcd.print(tm->tm_hour);
lcd.print(':');
if(tm->tm_min<10){lcd.print('0');}
lcd.print(tm->tm_min);

}

// To write or read long values from EEPROM
template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
const byte* p = (const byte*)(const void*)&value;
unsigned int i;
for (i = 0; i < sizeof(value); i++)
EEPROM.write(ee++, *p++);
return i;
}

template <class T> int EEPROM_readAnything(int ee, T& value)
{
byte* p = (byte*)(void*)&value;
unsigned int i;
for (i = 0; i < sizeof(value); i++)
*p++ = EEPROM.read(ee++);
return i;
}
 
Last edited:
the above is my code
METERAILS
Arduino uno
4 push
incubator-schema.jpg
buttons
3 leds
DHT22 sensor
dc motor 12V
2 light bulbs 75w and 25w
rtc DS1307
4 channel relay
2 fans 5v
humidifier 24 v but works with 19v notebook adapter
small commercial beer frigerator
IIC/I2C 2004 LCD screen
pc power supply
 
the code you posted can not be compiled it seems to have skipped parts like

lcd.print("Adjust
and
lcd.print("0

also if you can post where you downloaded the rtc library that would be helpful
 
There it is my chicken eggs encubator .
Made from a 25 liters plastic storage box and some foam outside to prevent heat loss.
i used 2 X 18w halogen g9 bulbs and a 230v dimmer to decrease light brightness.

There is a diagram above from fritzing. I uses an main arduino that controls a SSR relay for controls halogen light bulbs. this light bulbs are dimmed to half(in my case)
for hold temperature much time as possible without decrease temperature.That makes SSR stay on for some minutes before goes off again. if halogen light are to powerfull makes the SSR goes on and off many times in short period. the ideal situation is having the dimmer controlled by arduino and hold temperature without turn ligh off ,but i didn't got this dimmer yet(is there any one ready for try it?
stuck_out_tongue_winking_eye.png
).

this is the 3rd version i build and all the other version hatch almost all eggs(+/-80%) even with some issues on controlling temperature.i only had 1 fan and that caused some zones that overheated (more on coners).
Now i have 2x120mm(0.10A) pc fans that can spread hot air the same way in all this box.

Then i have a secondary arduino that it's for safe features. it controls an alarm buzzer(pc speaker) ,its connected to an temperature sensor (ds18b20) and send temperature to emoncms.com through an nrf24 wireless board
If temperatures goes over 39ºC or below 30ºC it sound an noisy alarm.Just in case main arduino or DHT22 fail.

Egg roller its made os aluminium and plastic egg racks cutted and glued with hot glue(screws were better but this is enought to hold eggs).it makes 45º each side.
An High torque servo roll every 60 minutes. Note that an regular servo does not have enough torque should be an high toque version.


eggs ready to start hatching! note the ds18b20 sensor in the back of the DHT22 sensor.they will stay same height than egg rack.




2x18w halogen lighs


lcd screen is configured for simplicity . code have hours and days passed and remaining ,but i decide use just passed days, temperature manual offset and time for next egg roll(minutes),and of course temperature and humidity on first line.






its a mess of cables ...i know. It's what happening when we always improve our project until it be a final version :p
I used usb cables from computer cases for wire sensors, it work really well .
There's 2 solid state relays on picture but we only need one.

Parts:
2x 12v 120mm pc fan(0.10A -slow speed/low noise)
1x LM2596
1x High torque servo or step motor(need additional controller).
1x 5v Arduino pro mini (or equivalent )
1x DHT22
1x 5v relay Or SSR G3MB-202P Solid State
1x 2 lines I2C 1602 LCD (i2c ,not serial) or 4 lines if you what more info on screen like time left and time spent clock.
2x monetary switch
2x 10k resistors
2x 18w halogen light bulbs
2x G9 Ceramic Sockets
1x AC 220V 2000W SCR Voltage Regulator (overkill for 36W i know, but it cost 1.50€ on ebay)

Optional parts
1x 3.3v pro mini (or equivalent)
1x computer speaker(buzzer)
1x DS18b20
1x NRF24L01
1x 4.7K Resistor
1x 3.7v litio battery (cellphone or 18650 cell)
1x Battery Protection Board(just for charge battery before start hatching)
note: this battery just hold main arduino in case of power failure. During normal work it never charge or discharge due 5v on line from LM2526

FRITZING PROJECT:
0_1504458462680_eggencubator v2.fzz



CODE: one zip file with main and auxiliar arduino code
eggEncobator.zip
NOTE: English it's not my language. i'm sorry some errors that can happens
stuck_out_tongue_winking_eye.png
 

Attachments

  • eggEncobator.zip
    3.8 KB · Views: 453
Last edited:

New posts New threads Active threads

Back
Top Bottom