Starting an Arduino DIY incubator project

Pics

abqchicken

In the Brooder
Sep 26, 2015
64
11
44
I just started an Arduino based incubator project. I have got the basics done - I have a working set of hardware/program to measure temperature, humidity, and control a relay to turn a heat source (light bulb) on and off. The temp, humidity, and time are displayed on a 4 line LCD. I have had it running for several days and it is working great. Now I am thinking about the automatic egg turning. I have a second board with a working stepper motor that can push the eggs to "roll" the eggs once per hour (or whatever I program the interval to be). Not sure if the stepper motor will have enough torque to get the job done (it is a cheap one). I plan to use a Styrofoam cooler to hold the eggs and minimize the heat loss. Any suggestions on the auto egg turner? The relay can take almost any voltage (including 110 and 220 AC or most DC voltages). Happy to share the code and parts list.
 


Here is the stepper motor I an thinking about using for turning the eggs. It is a 28BJY-48 with a driver board. The idea is to make a set of arms that will sweep around (like clock hands on a table) and slowly roll the eggs (I figure about every hour or two). Again, precision in timing is probably not critical. I may have just enough port left to get the one board to control the motor, but if I don't I will just use another board. The egg turning does not have to be synchronized with the temperature controller! I got the code worked out for this, just need to put something together to see if the stepper motor has enough torque to turn 6-10 eggs.
 
Last edited:
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:
I decided I will try a manual turn incubation first so I will not implement the egg turning (yet). Here is the code I will use. I made some modifications to minimize power consumption. I added a temperature control section to hold the temperature between 99.2 and 99.9 F. The simple control switched the light too often. I also added a simple computer fan controlled by Pin 9.

// Incubator code
// ---------------------------------------------
#include <LiquidCrystal.h>
#include "DHT.h"
#define DHTPIN 1 // Define the temp sensor data pin
#define DHTTYPE DHT22 // define the temp/hum sensor type
#define RELAY 7 // define the relay control pin - Pin 7
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, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); //set up what port the LCD will use
int backLight = 13; // pin 13 will control the backlight
int fan = 9;
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);
pinMode(fan, 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() {

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;
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);
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(5000);
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, 2);
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 < 99.2) { // Set the temperature for the relay to come on (somewhere around 90-101F to get eggs to hatch)
digitalWrite(RELAY, LOW); // Turns ON Relay
digitalWrite(fan, HIGH);
}
else if (f > 99.9) {
digitalWrite(RELAY, HIGH); // Turns Relay Off
digitalWrite(fan, LOW);
}
// Puase for 2 seconds
delay(1700);
}
}
 
And that is the result . 14 chicks of 25eggs ,but i could say that was 100% sucess because the other eggs were not fertilized. not even a single dead before or after hatch. Its not the arduino the most versatile machine? :)

i found that the incubator with 2 fans its quite accurate , i check all the incubator positions with an precise thermometer and its quite good +-0.2ºc
IMPORTANTE NOTES:
-In the last 4 days before hatch i decreased temperature 0.2ºc every day until 37 - 37.2
it´s recommended for have a better hatch rate.
-I find this app usefull :http://homesteadapps.com/app/free/hatchchart/hatchturnsche.php


top left chic just born 10min before i take the picture:p
IMG_20170914_145207.jpg
IMG_20170914_145150.jpg
 
I don't have any suggestions but want to say that I am impressed. I've been wanting to get into Arduino so when my boys are old enough I can teach them programming. What an awesome project! Definitely would like codes/part list/pictures. Keep us updated.
 
Newer to soon to start learning so here is the information to get you going -
The Arduino site to get the main programming IDE - www.arduino.cc
In terms of the actual board I like to use the Arduino UNO, but any one of the Arduinos (or clones should work).
For the LCD, I bought a 20 character, 4 line lcd - hacktronics, amazon etc will have them I paid around $8
The temperature humidity sensor is a DHT22, you can buy them on a small breakout board, but I just got the sensor since I am going to place it inside the incubator and wire it myself.
The relay is a one channel relay. the one I have is made by Keyes Supply, but if you search for "Arduino relay" you will find them.

As far as the code, I am a hack so I started with an LCD driver code tutorial I found here: www.hacktronics.com/Tutorials/arduino-character-lcd-tutorial.html.

The driver and tutorial for the DHT22 I found here: github.com/adafruit/DHT-sensor-library

The main issue in getting started is that individual demos work, but when you start putting all of it together, you break the code and you can get frustratingly stuck if you are not good at coding and hardware. Next post with some pictures and detail.
 

This is the display showing temperature, humidity, time since the system was turned on and days left till the eggs hatch (assuming 21 days).
 

Here is the whole mess with the sensor on a bread-board. The sensor is the little white thing on lower left part of the breadboard. The blue thing towards the bottom of the picture is the relay and of course, the upper left of the picture is the Arduino board. The LCD is on the right.

A mess of wires right now, but will have to re-do them later anyway. I just wanted to get the hardware working and get the code hacked together to drive it all. All seems to be working well. next post is the code.
 

Forgot, this is the actual DHT22 sensor. This sensor will go inside the incubator.
 
Last edited:

New posts New threads Active threads

Back
Top Bottom