Starting an Arduino DIY incubator project

Discussion in 'Incubating & Hatching Eggs' started by abqchicken, Oct 23, 2015.

  1. abqchicken

    abqchicken Out Of The Brooder

    64
    9
    31
    Sep 26, 2015
    [​IMG]

    Figured out that I can make my own characters so I modified the code to draw a thermometer for the temperature reading, drop for humidity and an odd looking clock for the time.
     
  2. abqchicken

    abqchicken Out Of The Brooder

    64
    9
    31
    Sep 26, 2015
    This is the updated code including the stepper motor drive. It is set to about 1/4 revolution every 15 min
    Temperature is set to 98F

    // Incubator code
    // ---------------------------------------------
    #include <LiquidCrystal.h>
    #include "DHT.h"
    #define DHTPIN 2 // Define the temp sensor data pin
    #define DHTTYPE DHT22 // 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 8 * 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(); // Read temperature in celsius
    float f = dht.readTemperature(true); // 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(f,1);
    lcd.print(" F ");
    //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(f < 98.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 % 15;
    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(700); // set stepper to max speed
    // small_stepper.step(Steps2Take); // take the steps
    }
    // Puase for 2 seconds
    delay(2000);
    }
    }
     
    Last edited: Oct 25, 2015
  3. Metolious

    Metolious Out Of The Brooder

    15
    2
    24
    Oct 17, 2015
    Thanks for sharing. I love it because it provides a meaningful project for me to learn coding. Definitely going to use this to help me get into it.
     
  4. crank

    crank Out Of The Brooder

    45
    9
    24
    Mar 4, 2014
    Utah
  5. abqchicken

    abqchicken Out Of The Brooder

    64
    9
    31
    Sep 26, 2015
    Update - I have had the system working for a while and all seems to be stable with the setup and code I posted. I now need to figure out a reliable egg-turning scheme without making it too complicated. As an alternative to the stepper motor I have been thinking about is a servo. I have a few from a couple of deceased RC helicopters. The two options I am thinking about are:

    1) rotating arns to push the eggs around in a circle
    2) servo rocking mechanism to move the eggs from side to side.

    I will probably prototype each to see which one works best. I really do not want to buy fertile eggs before I am sure things will work.
     
  6. abqchicken

    abqchicken Out Of The Brooder

    64
    9
    31
    Sep 26, 2015
    Changed the code to work with a servo instead of a stepper - this will "rock" the eggs by raising one end up and down. Servo control wire is set to Pin 9 and other two wire go to ground and +5V (on my servos yellow is control, red is +5V, black is ground).

    // Servo version of
    // Incubator code
    // ---------------------------------------------
    #include <LiquidCrystal.h>
    #include "DHT.h"
    #include <Servo.h>
    #define DHTPIN 2 // Define the temp sensor data pin
    #define DHTTYPE DHT22 // define the temp/hum sensor type
    #define RELAY 0 // define the relay control pin
    #define STEPS_PER_MOTOR_REVOLUTION 32 //define the number of steps per motor revolution
    Servo myservo; // create servo object to control a servo
    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 pos = 0; // variable to store the servo position
    int istate = 0;
    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;
    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
    // done with initial parameters
    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);
    myservo.attach(9); // servo control is set to pin 9 (usually yellow wire is control, black goes to ground red goes to +5V)
    myservo.write(16); //put the servo at intitial posistion of 16 degrees
    }
    //loop to read the sensor and display
    void loop() {
    float h = dht.readHumidity(); // Read the humidity
    float t = dht.readTemperature(); // Read temperature in celsius
    float f = dht.readTemperature(true); // 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(f, 1);
    lcd.print(" F ");
    //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 (f < 98.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 % 15; // set the interval of turning to 15 min
    ik = im - ip; // (change the vatiasblr "im" to "is" in the next three lines to turn in hour intervals
    if (ic == 0 && ik != 0) {
    ip = im;
    // this section is to rock the eggs
    if(istate == 0){
    for (pos = 16; pos <= 80; pos += 1) { // goes from 16 degrees to 80 degrees in steps of 1 degree
    myservo.write(pos);
    istate=1;
    delay(50);
    }
    }
    else if( istate == 1){
    for (pos = 80; pos >=16; pos -= 1) { // goes from 80 degrees to 0 degrees
    myservo.write(pos);
    istate = 0;
    delay(50); // slow the servo down a bit to turn the eggs
    }
    }
    }
    // Puase for 2 seconds
    delay(2000);
    }
    }



    /* ------------------------------------------------------------------------------- */
     
    Last edited: Nov 20, 2015
  7. gpop1

    gpop1 Chillin' With My Peeps

    542
    47
    94
    May 2, 2015
    I built my incubator about 6 months ago using a arduino mega and dht22 and that's still running good. I used a rtc (real time clock) that cost about $2.

    For the turner I used a geared motor as a servo has to hold the load where a angle drive holds it by the nature of its design. I did go a little over board with the code as you can control every aspect of the incubator but I figured it was better to have to many options then not enoght. Im collecting and testing all the parts for my next incubator at the moment. .

    If you need a hand im more than willing to help

    https://www.backyardchickens.com/t/976303/building-a-incubator-from-a-wine-cooler link to the first arduino one I built.
     
  8. abqchicken

    abqchicken Out Of The Brooder

    64
    9
    31
    Sep 26, 2015
    Impressive machine! Well done! That is way too many eggs for me to hatch!

    I am shooting for a bit smaller machine to hatch maybe 12 eggs and keep it inexpensive. I don't have enough room in my back yard and city ordinance will not allow for more than 15 chickens (already have 7). I am mostly doing it as a challenge and to see if I can hatch some breeds I cannot get locally. I really like the different colored eggs.

    Right now the challenge is to build a small egg turner. I was simply going to do use a stepper to sweep around an arm (I may go back to that). The small cheap stepper I have does not have enough torque. I am now trying a servo to "rock" the eggs somewhat like you have done, but much smaller. I have a feeling I will have to get a new servo since the one I have is a "micro" one from a long crashed RC helicopter. I may just have to go to a large stepper.
     
  9. gpop1

    gpop1 Chillin' With My Peeps

    542
    47
    94
    May 2, 2015
    how about any small dc motor that's gear reduced and a few prox sensors or ir beam sensors (few bucks each for arduino) then turn the whole incubator like brimasea does.
     
  10. abqchicken

    abqchicken Out Of The Brooder

    64
    9
    31
    Sep 26, 2015
    That might be worth thinking about. I have the prox sensors. would need to figure out the gearing. Not sure where to buy the gears. I have a few Helicopter motors that should be strong enough.
     

BackYard Chickens is proudly sponsored by