# Egg Incubator version 2

**URL:** <https://forum.arduino.cc/t/egg-incubator-version-2/652369>\
**Category:** Programming\
**Created:** [May 1, 2020, 4:54pm UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369 "2020-05-01T16:54:46Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![Anita\_Bath](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Anita\_Bath](https://forum.arduino.cc/u/Anita_Bath)\
**Post date:** [May 12, 2020, 12:19am UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/41 "2020-05-12T00:19:28Z")

</div>

Having it set to turn for 5 seconds every 20 min seems to work good. The problem was either having the length of time to long and it froze up the memory or having the RTC module that wasn't needed with this sketch still plugged in and causing havoc. Hopefully it makes it through the night okay. Fingers crossed :).

Now to think of how to add features like a door light and a rack centering when the door is open. I also want to add info on the lcd screen to show the turner count down and when its turning.

---

<div class="post-metadata">

**Author:** ![Anita\_Bath](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Anita\_Bath](https://forum.arduino.cc/u/Anita_Bath)\
**Post date:** [May 12, 2020, 10:13am UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/42 "2020-05-12T10:13:59Z")

</div>

I guess I spoke to soon. This morning the LCD was dim and the temp was froze so I reset the arduino and it came back bright again at around 34 degrees and quickly heated up to the 37.5. After a big sigh I reprogrammed the arduino nano with the clean macro F version I made that only controls temp and humidity. Now to wait 24 hours and see what it does.....

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [May 12, 2020, 11:09am UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/43 "2020-05-12T11:09:07Z")

</div>

Could you please post a schematic or even a hand drawing showing how everything is connected to the arduino?

Do you have anything that runs at night that might be causing surges or interference on the power line - any large equipment in the same building?

---

<div class="post-metadata">

**Author:** ![wildbill](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wildbill/32/1126438_2.png) [@wildbill](https://forum.arduino.cc/u/wildbill)\
**Post date:** [May 12, 2020, 11:32am UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/44 "2020-05-12T11:32:04Z")

</div>

> Anita\_Bath:  
> I guess I spoke to soon. This morning the LCD was dim and the temp was froze so I reset the arduino and it came back bright again at around 34 degrees and quickly heated up to the 37.5. After a big sigh I reprogrammed the arduino nano with the clean macro F version I made that only controls temp and humidity. Now to wait 24 hours and see what it does.....

Another worthwhile test would be to run the broken version again, either removing the wire controlling the motor so it doesn't turn or removing this line:

```arduino
  digitalWrite(turner, Turner_State);

```

As to David\_2018's question, I recall another incubator thread some years ago where the cause of the locking up was a nearby old refrigerator. A strategically placed cap solved the issue.

That said, if it was working without the turning enabled, I don't think it's so likely to be an external cause. Time will tell.

I would also be inclined to increase the frequency of turning a lot, so you can get it tested faster.

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [May 12, 2020, 11:46am UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/45 "2020-05-12T11:46:58Z")

</div>

why don't you replace the call to millis() (presumably just one) with a routine that returns an unsigned long incremented by 100 ( or some other large) number. A 24 hour test should complete in ~15 minutes

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [May 12, 2020, 11:48am UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/46 "2020-05-12T11:48:47Z")

</div>

> gcjr:  
> why don't you replace the call to millis() (presumably just one) with a routine that returns an unsigned long incremented by 100 ( or some other large) number. A 24 hour test should complete in ~15 minutes

Did you mean "multiplied by 100"?

---

<div class="post-metadata">

**Author:** ![Anita\_Bath](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Anita\_Bath](https://forum.arduino.cc/u/Anita_Bath)\
**Post date:** [May 12, 2020, 4:29pm UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/47 "2020-05-12T16:29:54Z")

</div>

> gcjr:  
> why don't you replace the call to millis() (presumably just one) with a routine that returns an unsigned long incremented by 100 ( or some other large) number. A 24 hour test should complete in ~15 minutes

Could you please show me how to do this? Would save me a lot of time 🙂

The version I made with Macro F from the code I found online that only used 16 percent of the memory failed after 5 hours. The screen stayed bright but was blank and after resetting it the temp was down to 34 again.... these poor eggs haha. I am as lost as a midget in a corn field on this now.

I think it is time I write the most simplistic code I can for just temp and humidity and have no lcd.

---

<div class="post-metadata">

**Author:** ![wildbill](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wildbill/32/1126438_2.png) [@wildbill](https://forum.arduino.cc/u/wildbill)\
**Post date:** [May 12, 2020, 5:27pm UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/48 "2020-05-12T17:27:25Z")

</div>

I approve of an approach that starts small and adds functionality as what you have proves out in testing.

However, looking at the problems you have had with your wiring already (LCD getting scrambled for example), I'm not convinced that you have code issues.

It might be worth replacing your outputs with leds and your inputs with pots and see if it still crashes. I will be mildly surprised if it does.

---

<div class="post-metadata">

**Author:** ![wildbill](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wildbill/32/1126438_2.png) [@wildbill](https://forum.arduino.cc/u/wildbill)\
**Post date:** [May 12, 2020, 5:29pm UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/49 "2020-05-12T17:29:02Z")

</div>

I approve of an approach that starts small and adds functionality as what you have proves out in testing.

However, looking at the problems you have had with your wiring already (LCD getting scrambled for example), I'm not convinced that you have code issues.

It might be worth replacing your outputs with leds and your inputs with pots and see if it still crashes. I will be mildly surprised if it does.

And run it far from any refrigerators.

---

<div class="post-metadata">

**Author:** ![Anita\_Bath](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Anita\_Bath](https://forum.arduino.cc/u/Anita_Bath)\
**Post date:** [May 12, 2020, 5:32pm UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/50 "2020-05-12T17:32:56Z")

</div>

I just wrote this up and uploaded it to the arduino and its working. Lets see if it stops after a while.

```cpp
//Simple egg incubator temp and humidity control

#include "Adafruit_Si7021.h"
Adafruit_Si7021 sensor = Adafruit_Si7021();

const int heater = A0;
const int humidifier = 10;

float heaterOffThreshold = 37.6;
float heaterOnThreshold = 37;
float humidifierOnThreshold = 45;
float humidifierOffThreshold = 48;

float Temperature;
float humidity;

void setup() {
  
 sensor.begin();
 
 pinMode(LED_BUILTIN, OUTPUT);
 pinMode(heater, OUTPUT);
 digitalWrite(heater, HIGH);
 pinMode(humidifier, OUTPUT);
 digitalWrite(humidifier, HIGH);

}

void loop() 

   { 
    BlinkLED();
    GetTandH();
    TempControl();
    HumidityControl();
   }

void BlinkLED()
   {
    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(1000);                       // wait for a second
    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
    delay(1000);                       // wait for a second
   }

void GetTandH()
   {
    humidity = sensor.readHumidity();
    Temperature = sensor.readTemperature(); 
   }

void TempControl()
   {  
     // If heater is currently off, and temperature is low, turn on the heater.
      if(Temperature < heaterOnThreshold)
      {
       digitalWrite(heater, LOW);
      }
     // If heater is currently on, and temperature is high, turn off the heater.
     if(Temperature > heaterOffThreshold)
     {
      digitalWrite(heater, HIGH);
     }
   }

void HumidityControl()
   {
     // If humidifier is currently off, and humidity is low, turn on the humidifier.
     if(humidity < humidifierOnThreshold)
     {
      digitalWrite(humidifier, LOW);
     }
 
     // If humidifier is currently on, and humidity is high, turn off the humidifier.
     if(humidity > humidifierOffThreshold)
     {
      digitalWrite(humidifier, HIGH);
     }
   }
   
 
  

 // THE END

```

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [May 12, 2020, 6:44pm UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/51 "2020-05-12T18:44:42Z")

</div>

> Anita\_Bath:  
> Could you please show me how to do this? Would save me a lot of time 🙂

would you mind posting your code? (or send it to me in a PM)

i don't think it's a matter of how many times you toggle an LED. I think it's a matter of how you keep track of time and schedule events

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [May 12, 2020, 8:07pm UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/52 "2020-05-12T20:07:19Z")

</div>

Delay can be such a DELAY when searching for errors in your code  
Delay makes the CPU count-up as fast a the CPU can. This occupies ALL calculating-power of the CPU there is zero left for other things. You should use the function millis() to initiate code-execution in intervals.

something similar to this

```cpp
    if (currentMillis - previousBlink_Millis >= 1000) 
    {
       previousBlink_Millis += 1000;
       if (digitalRead((LED_BUILTIN) == HIGH)
       { digitalWrite(LED_BUILTIN, LOW); }
       else
       {digitalWrite(LED_BUILTIN, HIGH); }
    }

```

best regards

Stefan

---

<div class="post-metadata">

**Author:** ![Anita\_Bath](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Anita\_Bath](https://forum.arduino.cc/u/Anita_Bath)\
**Post date:** [May 12, 2020, 10:52pm UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/53 "2020-05-12T22:52:29Z")

</div>

Hows this look?

```cpp
//Simple egg incubator temp, humidity and turner control

  // Sensor library
#include "Adafruit_Si7021.h"
Adafruit_Si7021 sensor = Adafruit_Si7021();

  // LCD Library
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);

  // Outputs
const int heater = A0;
const int humidifier = 10;
const int turner = A1;

  // Set points for temp and humidity
float heaterOffThreshold = 37.6;
float heaterOnThreshold = 37;
float humidifierOnThreshold = 45;
float humidifierOffThreshold = 48;

  // Temp and humidity varibles
float Temperature;
float humidity;

  // Blinking LED varibles
unsigned long previousBlink_Millis = 0;
unsigned long currentMillis = 0;

  // Turner varibles
int TurnerONOFF = 1;  // use this to turn the egg turner system on or off 0 is off 1 is on
const int turnerInterval = 2; // hours
const int turnerDuration = 25;  // seconds
unsigned long rotationtime;
unsigned long durationB4spin;
unsigned long durationONspin;
byte Turner_State = HIGH; 
unsigned long previousTurner_Millis = 0;

// variables to keep track of the status of 
// the system (0=off,1=on)
int heaterStatus;
int humidifierStatus;
int turnerStatus;

void setup() {
  
  sensor.begin();

 // Set up the LCD
 lcd.begin ();
 // Switch on the backlight.
 // lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
 lcd.setBacklight(HIGH);
 // Clear the display.
 lcd.clear();
 delay(200);
}

 pinMode(LED_BUILTIN, OUTPUT);
 
 pinMode(heater, OUTPUT);
 digitalWrite(heater, HIGH);
 
 pinMode(humidifier, OUTPUT);
 digitalWrite(humidifier, HIGH);
 
 pinMode(turner, OUTPUT);
 digitalWrite(turner, HIGH);

}

void loop() 

  { 
    BlinkLED();
    GetTandH();
    TempControl();
    HumidityControl();
    updateTurnerState();
    SwitchTurnerMotorState();
    PrintToLCD();
    displaySystemStatus();
  }

void BlinkLED()
    

  {
    currentMillis = millis();
    
    if (currentMillis - previousBlink_Millis >= 1000)
    {
      previousBlink_Millis += 1000;
       
      if (digitalRead((LED_BUILTIN) == HIGH))
      { 
        digitalWrite(LED_BUILTIN, LOW);
      }
      else
      {
        digitalWrite(LED_BUILTIN, HIGH); 
      }
    }
    
  }

void GetTandH()
  {
    humidity = sensor.readHumidity();
    Temperature = sensor.readTemperature(); 
  }

void TempControl()
  {  
    // If heater is currently off, and temperature is low, turn on the heater.
      if(Temperature < heaterOnThreshold)
      {
      digitalWrite(heater, LOW);
      heaterStatus = 1;
      }
    // If heater is currently on, and temperature is high, turn off the heater.
    if(Temperature > heaterOffThreshold)
    {
      digitalWrite(heater, HIGH);
      heaterStatus = 0;
    }
  }

void HumidityControl()
  {
    // If humidifier is currently off, and humidity is low, turn on the humidifier.
    if(humidity < humidifierOnThreshold)
    {
      digitalWrite(humidifier, LOW);
      humidifierStatus = 1;
    }
 
    // If humidifier is currently on, and humidity is high, turn off the humidifier.
    if(humidity > humidifierOffThreshold)
    {
      digitalWrite(humidifier, HIGH);
      humidifierStatus = 0;
    }
  }

void updateTurnerState()
  {
  durationB4spin = (turnerInterval*3600000); 
  durationONspin = (turnerDuration*1000);    
    if ((Turner_State == HIGH) && (TurnerONOFF >= 1)) 
    {
    if (currentMillis - previousTurner_Millis >= durationB4spin) 
    {
      Turner_State = LOW;
      turnerStatus = 1;
      previousTurner_Millis += durationB4spin;
    }
  }
  else 
  {
    if (currentMillis - previousTurner_Millis >= durationONspin) 
    {
      Turner_State = HIGH;
      turnerStatus = 0;
      previousTurner_Millis += durationONspin;
    } 
  }    
 }

void SwitchTurnerMotorState(){
  digitalWrite(turner, Turner_State);
}

void PrintToLCD()
 {
  int dp; //number of decimal places to show
  // Show the temperature on the screen
  lcd.setCursor(0,0);
  dp = 2; //by default
  if (Temperature > 99.9) dp = 0; 
  if (Temperature < 0) dp = 0;
  lcd.print("T=");
  lcd.print(Temperature,dp);
  lcd.print((char)223);
  lcd.print("C");
  lcd.print(" ");
  
  // Show the humidity on the screen
  lcd.print("H=");
  lcd.print(humidity,0);
  lcd.print("% ");
 }

void displaySystemStatus(){
 lcd.setCursor(0,1);
 // We need to display the status of the heater, fan,
 // and humidifier which can be ON or OFF. If status is
 // ON, fill in character in front of device name.
 if(heaterStatus == 1) 
 lcd.write(255);
 else lcd.print(" ");
 lcd.print("Heat ");
 if(humidifierStatus == 1)
 lcd.write(255);
 else lcd.print(" ");
 lcd.print("Hum ");
 if(turnerStatus == 1)
 lcd.write(255);
 else lcd.print(" ");
 lcd.print("Turn ");
}
   
 // THE END

```

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [May 12, 2020, 10:56pm UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/54 "2020-05-12T22:56:47Z")

</div>

> Hows this look?

It looks like you haven't found the auto-format tool yet.

---

<div class="post-metadata">

**Author:** ![Anita\_Bath](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Anita\_Bath](https://forum.arduino.cc/u/Anita_Bath)\
**Post date:** [May 12, 2020, 11:28pm UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/55 "2020-05-12T23:28:42Z")

</div>

> TheMemberFormerlyKnownAsAWOL:  
> It looks like you haven't found the auto-format tool yet.

haha I have heard about it but I have no idea where it is yet. I had to change a few things to get the led to blink.

```arduino
//Simple egg incubator temp and humidity and turner control

  // Sensor library
#include "Adafruit_Si7021.h"
Adafruit_Si7021 sensor = Adafruit_Si7021();

  // LCD Library
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);

  // Outputs
const int heater = A0;
const int humidifier = 10;
const int turner = A1;

  // Set points for temp and humidity
float heaterOffThreshold = 37.6;
float heaterOnThreshold = 37;
float humidifierOnThreshold = 45;
float humidifierOffThreshold = 48;

  // Temp and humidity varibles
float Temperature;
float humidity;

  // Blinking LED varibles
  // These variables store the flash pattern
  // and the current state of the LED
 
int ledState = LOW;            // ledState used to set the LED
unsigned long previousLEDMillis = 0;        // will store last time LED was updated
long OnTime = 250;          // milliseconds of on-time
long OffTime = 750;          // milliseconds of off-time
unsigned long currentMillis;

  // Turner varibles
int TurnerONOFF = 1;  // use this to turn the egg turner system on or off 0 is off 1 is on
const int turnerInterval = 2; // hours
const int turnerDuration = 25;  // seconds
unsigned long rotationtime;
unsigned long durationB4spin;
unsigned long durationONspin;
byte Turner_State = HIGH; 
unsigned long previousTurner_Millis = 0;

// variables to keep track of the status of 
// the system (0=off,1=on)
int heaterStatus;
int humidifierStatus;
int turnerStatus;

void setup() {
  
 // Set up the sensor
  sensor.begin();

 // Set up the LCD
 lcd.begin ();
 // Switch on the backlight.
 // lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
 lcd.setBacklight(HIGH);
 // Clear the display.
 lcd.clear();
 delay(200);

 pinMode(LED_BUILTIN, OUTPUT);
 
 pinMode(heater, OUTPUT);
 digitalWrite(heater, HIGH);
 
 pinMode(humidifier, OUTPUT);
 digitalWrite(humidifier, HIGH);
 
 pinMode(turner, OUTPUT);
 digitalWrite(turner, HIGH);

}

void loop() 

  {
    currentMillis = millis(); 
    BlinkLED();
    GetTandH();
    displaySystemStatus();
    TempControl();
    HumidityControl();
    updateTurnerState();
    SwitchTurnerMotorState();
    PrintToLCD();
  }

void BlinkLED()
 {
  if((ledState == HIGH) && (currentMillis - previousLEDMillis >= OnTime))
  {
    ledState = LOW;  // Turn it off
    previousLEDMillis = currentMillis;  // Remember the time
    digitalWrite(LED_BUILTIN, ledState);  // Update the actual LED
  }
  else if ((ledState == LOW) && (currentMillis - previousLEDMillis >= OffTime))
  {
    ledState = HIGH;  // turn it on
    previousLEDMillis = currentMillis;  // Remember the time
    digitalWrite(LED_BUILTIN, ledState);  // Update the actual LED
  }
 }

void GetTandH()
  {
    humidity = sensor.readHumidity();
    Temperature = sensor.readTemperature();
  }

void displaySystemStatus()
 {
  lcd.setCursor(0,1);
  // We need to display the status of the heater, fan,
  // and humidifier which can be ON or OFF. If status is
  // ON, fill in character in front of device name.
  if(heaterStatus == 1) 
  lcd.write(255);
  else lcd.print(" ");
  lcd.print("Heat ");
  if(humidifierStatus == 1)
  lcd.write(255);
  else lcd.print(" ");
  lcd.print("Hum ");
  if(turnerStatus == 1)
  lcd.write(255);
  else lcd.print(" ");
  lcd.print("Turn ");
 }

void TempControl()
  {  
    // If heater is currently off, and temperature is low, turn on the heater.
      if(Temperature < heaterOnThreshold)
      {
      digitalWrite(heater, LOW);
      heaterStatus = 1;
      }
    // If heater is currently on, and temperature is high, turn off the heater.
    if(Temperature > heaterOffThreshold)
    {
      digitalWrite(heater, HIGH);
      heaterStatus = 0;
    }
  }

void HumidityControl()
  {
    // If humidifier is currently off, and humidity is low, turn on the humidifier.
    if(humidity < humidifierOnThreshold)
    {
      digitalWrite(humidifier, LOW);
      humidifierStatus = 1;
    }
 
    // If humidifier is currently on, and humidity is high, turn off the humidifier.
    if(humidity > humidifierOffThreshold)
    {
      digitalWrite(humidifier, HIGH);
      humidifierStatus = 0;
    }
  }

void updateTurnerState()
  {
  durationB4spin = (turnerInterval*3600000); 
  durationONspin = (turnerDuration*1000);    
    if ((Turner_State == HIGH) && (TurnerONOFF >= 1)) 
    {
    if (currentMillis - previousTurner_Millis >= durationB4spin) 
    {
      Turner_State = LOW;
      turnerStatus = 1;
      previousTurner_Millis += durationB4spin;
    }
  }
  else 
  {
    if (currentMillis - previousTurner_Millis >= durationONspin) 
    {
      Turner_State = HIGH;
      turnerStatus = 0;
      previousTurner_Millis += durationONspin;
    } 
  }    
 }

void SwitchTurnerMotorState()
 {
  digitalWrite(turner, Turner_State);
 }

void PrintToLCD()
 {
  int dp; //number of decimal places to show
  // Show the temperature on the screen
  lcd.setCursor(0,0);
  dp = 2; //by default
  if (Temperature > 99.9) dp = 0; 
  if (Temperature < 0) dp = 0;
  lcd.print("T=");
  lcd.print(Temperature,dp);
  lcd.print((char)223);
  lcd.print("C");
  lcd.print(" ");
  
  // Show the humidity on the screen
  lcd.print("H=");
  lcd.print(humidity,0);
  lcd.print("% ");
 }

   
 // THE END

```

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [May 12, 2020, 11:34pm UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/56 "2020-05-12T23:34:11Z")

</div>

turnerInterval\*3600000 \<———\<\<\<\< 3600000ul

---

<div class="post-metadata">

**Author:** ![Anita\_Bath](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Anita\_Bath](https://forum.arduino.cc/u/Anita_Bath)\
**Post date:** [May 12, 2020, 11:49pm UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/57 "2020-05-12T23:49:28Z")

</div>

> larryd:  
> turnerInterval\*3600000 \<———\<\<\<\< 3600000ul

Please explain. Couldn't the 3600000 be an "l" and the 1000 a "u"

---

<div class="post-metadata">

**Author:** ![Anita\_Bath](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Anita\_Bath](https://forum.arduino.cc/u/Anita_Bath)\
**Post date:** [May 13, 2020, 12:38am UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/58 "2020-05-13T00:38:39Z")

</div>

Even with the simple sketch it still got hung up after a few hours and the heater was stuck on so it hit 60 degrees :s. gonna have hard boiled eggs soon lol. Ill set up a breadboard and see if it crashes with leds hooked up to it.

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [May 13, 2020, 12:41am UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/59 "2020-05-13T00:41:10Z")

</div>

unsigned long durationB4spin;  
. . .  
ul tells the compiler to use unsigned long math, the default is integer math.

- integer (16 bit) - unsigned number from 0 to 65535
- unsigned long (32 bit) - unsigned number from 0 to 4,294,967,295

Suggest you get into the habit of adding ul when dealing with unsigned numbers/constants.

durationB4spin = (turnerInterval_3600000ul);  
durationONspin = (turnerDuration_1000ul);

---

<div class="post-metadata">

**Author:** ![Anita\_Bath](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Anita\_Bath](https://forum.arduino.cc/u/Anita_Bath)\
**Post date:** [May 13, 2020, 1:39am UTC](https://forum.arduino.cc/t/egg-incubator-version-2/652369/60 "2020-05-13T01:39:08Z")

</div>

> larryd:  
> unsigned long durationB4spin;  
> . . .  
> ul tells the compiler to use unsigned long math, the default is integer math.
> 
> - integer (16 bit) - unsigned number from 0 to 65535
> - unsigned long (32 bit) - unsigned number from 0 to 4,294,967,295
> 
> Suggest you get into the habit of adding ul when dealing with unsigned numbers/constants.
> 
> durationB4spin = (turnerInterval_3600000ul);  
> durationONspin = (turnerDuration_1000ul);

Is it possible that not having the "ul" would make it get hung up / freeze the loop? If not then what's the consequence since it still ran without it. I did add it though.

[Previous page](https://forum.arduino.cc/t/egg-incubator-version-2/652369.md?page=2)

[Next page](https://forum.arduino.cc/t/egg-incubator-version-2/652369.md?page=4)
