Go Down

Topic: chicken egg incubator control code (Read 3333 times) previous topic - next topic


Jul 28, 2017, 03:21 am Last Edit: Jul 31, 2017, 02:14 pm by gpop1
This is a simply complicated code that covers what most people would require in a fully automated incubator setup.

As with most controller that are using a 20x4 lcd most of the code is controlling the display or trying to save space. This should according to the compiler fit on a uno but was written on a mega.

The hardware:

4x20 display
keypad 4 button
1307 rtc
dht22 temp/humidity sensor
8 ohm speaker (optional)
5 relays arduino type (optional depending on settings)
micro switchs (optional depending on turner design)
uno or meg

so what does it do:

controls temp, humidity, turner, alarms and more (about 40 options)

link to library for rtc


main project write up including pictures will be posted on backyard chickens web site and linked back to here.
I will add the link when I have added all of the pictures and wiring diagrams there.

updated program please use incmaincode5.ino posted further down


link to byc with the pics and wiring explained



There are some small problems in the code posted

I used a pin that was reserved in case you wanted to use a uno instead of a mega. Also there was a typo on one screen so I will be double checking my work and posting a update in the next few days. If you are using a mega then it shouldn't make much difference


update to fix pin usage for a uno: moved humidity relay to pin 10 to free up A4

added code to make the unit safe while in edit mode.

still looking for a hot spot probe that is plug and play as the DS18B20 requires some programming knowledge. I may just post a second code with this option for more advanced users


gpopl Thanks.

Your code are very good.
Will try to do in prototype "missing the display", if succeed next step are to do an standalone board.


gpopl im working on device, thanks again for you job.
bugs found so far:

Clock can set false data as 30/2/2018  next day 00/3/2018 this preaphes are whit the rtc library.
good also are when set the clock by definition show the current data
set_minute constrain(set_minute159); let say we are at minute 50 and want to set 52 already start in 50, i didnt find an solution.

missing some function to check the alarms values high lower temp; ex. set alarm high temp = 32Ç and lower 38 and the set_point are 37
i did this to set temp alarm
     case 26:
      if (
highTempSetPoint <= temp_setpoint)
highTempSetPoint = (temp_setpoint 2); 
highTempSetPoint highTempSetPoint 0.1;
      if (
highTempSetPoint <= lowTempAlarmPoint)
highTempSetPoint = (lowTempAlarmPoint 5);
highTempSetPoint highTempSetPoint 0.1;
highTempSetPoint highTempSetPoint 0.1;


Thanks again, anything else i will post i love this code


not sure why I added


in the min edit code

should have been

 lcd.print (F("set minute"));

That may be causing confusion as the first line would be what the rtc is set to and its not updated until you leave the menu.

not sure what the problem is with high and low temp set points as the code looks ok

void alarmcheck () {

  alarm_active = 0;
  if (adj_temp >= highTempSetPoint ) {
    alarm_active = 1;
    if (tempalarm == 1) {
      soundalarm = 1;
    } else {
      soundalarm = 0;
  if (adj_temp <= lowTempAlarmPoint) {
    alarm_active = 2;
    if (tempalarm == 1) {
      soundalarm = 1;
    } else {
      soundalarm = 0;

Your code looks like you are checking set points rather than adj_temp ( temp reading + or - calibration )

If the tempalarm is set to on then it should set of the alarm.


ok I see what you are saying. I thought than when you changed from F to C it should load the defaults as

temp_setpoint = 37.5;
highTempSetPoint = 39;
lowTempAlarmPoint = 33;

I never added no code to prevent the user from setting a point where it would be in alarm


Hello. I want to start this chicken egg incubator project but i could not get the library working. I am novice on programming and i understand nothing on c++. Someone can help to have all this ds1307 library as .zip file then i can include it to my library folder. Or someone can help me how to have this working? Thanks in advance

Go Up