# Egg Turner doesnt stop

I have an egg incubator that I have been trying to make code for. I have it controlling the temp and humidity good now but I want to make it turn the eggs for a certain amount of time every couple hours. It counts down and starts turning but never stops. What am I missing in this code?

Also instead of showing "Turning EGG'S for" It shows "urning EGG'S for" on the LCD. Not sure why it is missing a "T".

``````// Spins part (turning eggs)
while (((millis() - rotationtime) > durationB4spin) && (rotate == 0))
{
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("  Turning EGG'S for");
lcd.setCursor(6, 2);
lcd.print(motorspinduration);
lcd.print(" seconds");
digitalWrite(motorpin, LOW);
delay(durationONspin);
digitalWrite(motorpin, HIGH);
rotate = 1;
}

if (rotate == 1)
{
rotationtime = millis();
rotate = 0;
lcd.clear();
}
``````

I have attached the INO for reference.

EGGS has no apostrophe

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
`[code]Paste your sketch here[/code]`

“It counts down and starts turning but never stops. ”

What’s wrong with scrambled eggs ?

Do people in these forums take anything seriously lol. Everyone here just wants to judge and pick apart things that don't currently matter. Focus on the main issue please and thank you :s

OK, let's focus on this condition:

``````((millis() - rotationtime) > durationB4spin)
``````

The value of millis() keeps getting bigger and bigger, the other two are constants. Suppose for the sake of argument when it is first encountered millis() is 1,000, rotationtime is 100 and durationB4spin is 500, so 1000 - 100 > 500 is true. Since the value on the left is growing it will never be less than or equal to the value on the right.

You want help but you refuse to give volunteers enough information to help us help you.

Did you remove the apostrophe?

Also instead of showing “Turning EGG’S for” It shows “urning EGG’S for” on the LCD. Not sure why it is missing a “T”.

I remember that problem from one of your previous posts, something you are printing on line 2 of the display is too long for the display line. When that happens, the display prints the excess characters (spaces in your case) at the beginning of line 1, overwriting the “T”.

“ I remember that problem from one of your previous posts, ”

That’s a big problem, why should we have to check a person’s previous post(s) to answer a current post question.

Everyone here just wants to judge and pick apart things that don’t currently matter

You’re new to software, aren’t you?

The motto “The Devil is in the detail” could’ve be written about software.
Quite often (here too, it seems), the Devil is in the detail you didn’t post.

Why is this question in a new thread anyway? It's the same program, with essentially the same problems. The replies are on the glib side because everyone has visited the other thread is tired of the hand waving.

This is actually the third thread, the previous are:

I'm not saying this is necessarily a duplicate thread. It just would have been courteous to provide at least one of these links to provide some context.

Now we are told that we aren't solving the real problem. I guess that means the OP knows what the problem is, and should be able to fix it themselves.

I looked at the code from here - it’s HUGE!

Line 260` memory_update == 1;`
Just 'cos it compiles, doesn’t mean it isn’t going to bite you on the ass.

Everything you put in EEPROM would probably be better as part of a single settings struct.
Probably even a settings class.

It’s too late (for me) to go through all that code, but my advice is to put it aside and look at factoring it.

You can guess the luck someone other than the original author would have in trying to modify the sketch, just by looking at the global variables:

``````char* menu1[8] = { "set temp/humidity", "set time/date", "set turner",
"set hatch date", "alarm points", "hardware setup", "factory reset", "return"
};
char* menu10[9] = { "current set points", "current cal offset", "set point temp", "set point humidity", "calibrate temp",
"calibrate hum", "set temp swing", "set humidity swing", "return"
};
char* menu20[6] = { "set minute", "set hour", "set day",
"set month", "set year", "return"
};
char* menu30[3] = { "disable/enable", "return", " "
};

char* menu40[4] = { "set days to hatch", "start countdown", "alarm on/off",
"return"
};
char* menu50[5] = { "turner hardware", "temp in F or C",
"audio alarm", "hot spot probe", "return"
};
char* menu60[3] = { "reset now ", "return", " " };
char* menu80[8] = { "temp alarm", "humidity alarm", "display set points", "high temp sp",
"low temp sp", "high hum sp", "low hum alarm", "return"
};

char* menu100[5] = { "disable/enable", "time turner runs", "time between turns",
"test turner", "return"
};
char* menu110[5] = { "disable/enable", "time between turns",
"cam time", "test turner", "return"
};
char* menu120[6] = { "disable/enable", "time between turns", "turner manual",
"tuner alarm", "test turner", "return"
};

char* standardText[4] = { "use up and down", "press enter to apply", "set_point : ", "press enter to exit" };
int subsublevel = 0;
float temp;
float humidity;
float humidity_setpoint = 0;
float temp_setpoint = 0;
int alarm_active = 0;
float tempC = 0;
float tempF = 0;
float highTempSetPoint = 0;
float lowTempAlarmPoint = 0;
float highHumidAlarmPoint = 0;
float lowHumidAlarmPoint = 0;
unsigned long secondTurnercounter = 0; // turner second timer rewite to 60 then reset
unsigned long previousMillis5 = 0;
unsigned long timeBetweenTurnsSeconds = 0;
long previousMillis = 0;//one second counter
long interval = 1000; //one second
float tempSwing = 0;
float humiditySwing = 0;
float cal_temp = 0;
float cal_humidity = 0;
long turn_timer; // used on display
int display_stat_turn = 1;
int t1_hatch_days = 15;
int time_to_turn_mins;
int time_to_turn_hr;
int set_minute = 1; //used to set rtc
int set_hour = 1; //used to set rtc
int set_day = 7; //used to set rtc
int set_month = 9; //used to set rtc
long set_year = 2018; //used to set rtc
int tunerDisable = 0;
int clock_update = 0; //used to set rtc
byte reboot = 1;
int prev_clock_day = 0;
int hour_counter = 0;
int memory_update;
unsigned int temp_timer = 0; // stop sensor for one second on boot and slow reads
byte lightButton = 0;
byte editButton = 0;
byte plusButton = 0;
byte noSave = 0;
byte  minusButton = 0;
int editMode = 0;
byte preveditButton = 0;
byte prevplusButton = 0;
byte prevMinusButton = 0;
unsigned long prevMillis = 0;
byte prevlightButton = 0;
int prevmn = 0;
int screenmax = 7;
int prevmn2 = 0;
int escape = 0;
int hatchDays = 0;
int hatchCountUp = 0;
int hatchAlarm = 0;
int turnerType = 1;
int TimeBetweenTurns = 1;
int TimeTurnerTurns = 1;
int turnerAlarm = 0;
unsigned long  turnerRunCounter = 0;
int testTurner = 0;
unsigned long countdown = 0;
byte tilt = 0;
byte onetime = 0;
byte turnerstop = 0;
byte turnerEstop = 0;
byte prevturnerstop = 0;
byte audioalarm = 0;
byte tempalarm = 1;
byte humalarm = 1;
byte facReset = 0;
byte soundalarm = 0;
byte setlightrelay = 1;
byte heaterdisplay = 0;
byte humidityfandisplay = 0;
byte tempinF = 0;
byte prevtempinF = 0;
byte temp_char[8] = { B01110, B01010, B01010, B01110, B01110, B11111, B11111, B01110 };
byte hum_char[8] = { B00100, B01110, B11111, B00100, B10001, B00100, B10001, B00100 };
byte bell_Char[8] = { B00100, B01110, B01110, B01110, B11111, B11111, B00100, B00000 };
byte arrow_Char[8] = { B00000, B00000, B10000, B10000, B10111, B10011, B10101, B01000 };
byte pointer[8] = { B10000, B01000, B00100, B00010, B00010, B00100, B01000, B10000 };
byte showC[8] = { B11000, B11000, B00000, B00111, B00100, B00100, B00100, B00111 };
byte showF[8] = { B11000, B11000, B00000, B00111, B00100, B00111, B00100, B00100 };
``````

It's not for me to tell someone how to finish a project (although I may too often succumb to temptation), but I'm definitely done with helping... in all sincerity, I think the best solution is to throw this code in the garbage can and start from scratch.

Damn! How long is the manual that comes with that thing? (As if there actually is one

``````// testMenu(menuNumber, screenmax, menuLevel);
void testMenu(int x, int y, int z) {
``````

That’s scary-level obtuse.

Why have a comment that tells you what x, y and z are, when you could’ve used menuNumber, screenmax and menuLevel in the code instead?

aarg:
You can guess the luck someone other than the original author would have in trying to modify the sketch, just by looking at the global variables:

``````char* menu1[8] = { "set temp/humidity", "set time/date", "set turner",
``````

"set hatch date", "alarm points", "hardware setup", "factory reset", "return"
};
char* menu10[9] = { "current set points", "current cal offset", "set point temp", "set point humidity", "calibrate temp",
"calibrate hum", "set temp swing", "set humidity swing", "return"
};
char* menu20[6] = { "set minute", "set hour", "set day",
"set month", "set year", "return"
};
char* menu30[3] = { "disable/enable", "return", " "
};

char* menu40[4] = { "set days to hatch", "start countdown", "alarm on/off",
"return"
};
char* menu50[5] = { "turner hardware", "temp in F or C",
"audio alarm", "hot spot probe", "return"
};
char* menu60[3] = { "reset now ", "return", " " };
char* menu80[8] = { "temp alarm", "humidity alarm", "display set points", "high temp sp",
"low temp sp", "high hum sp", "low hum alarm", "return"
};

char* menu100[5] = { "disable/enable", "time turner runs", "time between turns",
"test turner", "return"
};
char* menu110[5] = { "disable/enable", "time between turns",
"cam time", "test turner", "return"
};
char* menu120[6] = { "disable/enable", "time between turns", "turner manual",
"tuner alarm", "test turner", "return"
};

char* standardText[4] = { "use up and down", "press enter to apply", "set_point : ", "press enter to exit" };
int subsublevel = 0;
float temp;
float humidity;
float humidity_setpoint = 0;
float temp_setpoint = 0;
int alarm_active = 0;
float tempC = 0;
float tempF = 0;
float highTempSetPoint = 0;
float lowTempAlarmPoint = 0;
float highHumidAlarmPoint = 0;
float lowHumidAlarmPoint = 0;
unsigned long secondTurnercounter = 0; // turner second timer rewite to 60 then reset
unsigned long previousMillis5 = 0;
unsigned long timeBetweenTurnsSeconds = 0;
long previousMillis = 0;//one second counter
long interval = 1000; //one second
float tempSwing = 0;
float humiditySwing = 0;
float cal_temp = 0;
float cal_humidity = 0;
long turn_timer; // used on display
int display_stat_turn = 1;
int t1_hatch_days = 15;
int time_to_turn_mins;
int time_to_turn_hr;
int set_minute = 1; //used to set rtc
int set_hour = 1; //used to set rtc
int set_day = 7; //used to set rtc
int set_month = 9; //used to set rtc
long set_year = 2018; //used to set rtc
int tunerDisable = 0;
int clock_update = 0; //used to set rtc
byte reboot = 1;
int prev_clock_day = 0;
int hour_counter = 0;
int memory_update;
unsigned int temp_timer = 0; // stop sensor for one second on boot and slow reads
byte lightButton = 0;
byte editButton = 0;
byte plusButton = 0;
byte noSave = 0;
byte  minusButton = 0;
int editMode = 0;
byte preveditButton = 0;
byte prevplusButton = 0;
byte prevMinusButton = 0;
unsigned long prevMillis = 0;
byte prevlightButton = 0;
int prevmn = 0;
int screenmax = 7;
int prevmn2 = 0;
int escape = 0;
int hatchDays = 0;
int hatchCountUp = 0;
int hatchAlarm = 0;
int turnerType = 1;
int TimeBetweenTurns = 1;
int TimeTurnerTurns = 1;
int turnerAlarm = 0;
unsigned long  turnerRunCounter = 0;
int testTurner = 0;
unsigned long countdown = 0;
byte tilt = 0;
byte onetime = 0;
byte turnerstop = 0;
byte turnerEstop = 0;
byte prevturnerstop = 0;
byte audioalarm = 0;
byte tempalarm = 1;
byte humalarm = 1;
byte facReset = 0;
byte soundalarm = 0;
byte setlightrelay = 1;
byte heaterdisplay = 0;
byte humidityfandisplay = 0;
byte tempinF = 0;
byte prevtempinF = 0;
byte temp_char[8] = { B01110, B01010, B01010, B01110, B01110, B11111, B11111, B01110 };
byte hum_char[8] = { B00100, B01110, B11111, B00100, B10001, B00100, B10001, B00100 };
byte bell_Char[8] = { B00100, B01110, B01110, B01110, B11111, B11111, B00100, B00000 };
byte arrow_Char[8] = { B00000, B00000, B10000, B10000, B10111, B10011, B10101, B01000 };
byte pointer[8] = { B10000, B01000, B00100, B00010, B00010, B00100, B01000, B10000 };
byte showC[8] = { B11000, B11000, B00000, B00111, B00100, B00100, B00100, B00111 };
byte showF[8] = { B11000, B11000, B00000, B00111, B00100, B00111, B00100, B00100 };

``````

It's not for me to tell someone how to finish a project (although I may too often succumb to temptation), but I'm definitely done with helping... in all sincerity, I think the best solution is to throw this code in the garbage can and start from scratch.
``````

I looked at that a bit when the OP first posted it, the menu structure in the code is quite cryptic, and I didn't really want to spend any time on it, since they had originally started with a completely different sketch that I'd already spent a considerable amount of time looking over. Incidentally, the byte arrays with the binary data at the end of the variables are definitions of custom characters for the LCD display.

HAHA you guys are brutal.

I uploaded the entire sketch, what more info can I give then that. I know the wiring is correct i've tested it all. I am a hardware guy not a software one. The code was from a youtube video and It may not be pretty but I was hoping it would get the job done. Instead of calling it garbage why not show me how it should be.

I am a visual learner and at the end of the day all I really want to see is this egg incubator I built work lol.

Yes I removed the apostrophe the guy had on eggs lol

david_2018:
I looked at that a bit when the OP first posted it, the menu structure in the code is quite cryptic, and I didn’t really want to spend any time on it, since they had originally started with a completely different sketch that I’d already spent a considerable amount of time looking over. Incidentally, the byte arrays with the binary data at the end of the variables are definitions of custom characters for the LCD display.

That is different code. I have two sketches I have been playing with on my egg incubator one is incmaincode_Hogen and the second one is a sketch I found from a youtube video. Please don’t get them mixed up.

incmaincode was very complicated and would get hung up after an hour.

The slimfarmer one is much more simple but never stops turning the eggs once it starts and is apparently written like garbage lol.

I have attached the two different sketches

EGG_INCUBATOR_By_SLIMFARMER.ino (23.7 KB)

incmaincode_Hogen.ino (48 KB)

If you want someone to write code for you, please post in the Gigs and Collaborations sub forum, and state how much you are willing to pay. Modifying code of the size and style of the samples you have there, amounts to substantial work. You have amply demonstrated that there is no way to teach you how to do it, in a forum thread.

aarg:
If you want someone to write code for you, please post in the Gigs and Collaborations sub forum, and state how much you are willing to pay. Modifying code of the size and style of the samples you have there, amounts to substantial work. You have amply demonstrated that there is no way to teach you how to do it, in a forum thread.

Ill figure it out myself then. cheers,