Store a date and time to Eeprom.

Hello everyone.

I'm busy building an off-grid 12V egg incubator. My setup is:

Arduino Uno
DHT11 Temperature & humidity sensor
RTC Ds3231 Real time clock mudule
Servo motor modified to do 360 degrees
3x Magnetic switches
2x 12V PC Fans
4x 12V automotive flasher lights as heaters
Tilting unit with 4 tilting trays.
2x Solar panels
1x 12V Automotive battery
1 times Charge controller.

Opperation:

Temperature and humidity is checked constantly. The RTC module keep track of time. The trays must tilt every two hours for a period of 18 days after which an alarm must sound to remove the eggs after which they are placed in a hatching unit for 3 days untill they hatch.

I’m somewhat rusted with the programming. I think is may be best to set a future date 18 days later using a push-button.

Here is the code I’ve been playing with.

// DS3231_Serial_Easy
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// A quick demo of how to use my DS3231-library to 
// quickly send time and date information over a serial link
//
// To use the hardware I2C (TWI) interface of the Arduino you must connect
// the pins as follows:
//
// Arduino Uno/2009:
// ----------------------
// DS3231:  SDA pin   -> Arduino Analog 4 or the dedicated SDA pin
//          SCL pin   -> Arduino Analog 5 or the dedicated SCL pin
//
// The internal pull-up resistors will be activated when using the 
// hardware I2C interfaces.
//
// You can connect the DS3231 to any available pin but if you use any
// other than what is described above the library will fall back to
// a software-based, TWI-like protocol which will require exclusive access 
// to the pins used, and you will also have to use appropriate, external
// pull-up resistors on the data and clock signals.
//

#include <DS3231.h>

// Init the DS3231 using the hardware interface
DS3231  rtc(SDA, SCL);
int ledPin = 13; // Sets LED 13 as output
int servo = 8;   // Sets servo control to pin 8

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
  pinMode(servo, OUTPUT);
  // Setup Serial connection
  Serial.begin(9600);
    
  // Initialize the rtc object
  rtc.begin();
  
  // The following lines can be uncommented to set the date and time
  //rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014
}

void loop()
{
  // Send Day-of-Week
//  Serial.print(rtc.getDOWStr());
//  Serial.print(" ");
  
  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());
  
  // Get the Seconds as it rols over to the next Min
  if (rtc.getTime().sec <= 30) {
  // Temp and Humidity must be checked once/min.
  // The fan must cycle the air
  digitalWrite(ledPin,HIGH);
  Serial.println("Increase Temperature");
  } else {
  digitalWrite(ledPin,LOW);
  Serial.println("Temp is still OK");
  }

  // Get the minutes as it rols over to the next hour
  if (rtc.getTime().min <= 30) {  // Sets when to read the minute counter
    // The trays must tilt forwards or backwords here.
  digitalWrite(servo,HIGH); // Tilt servo Forward
  Serial.println("Tilt Forward");
  } else {
  digitalWrite(servo,LOW); // // Tilt servo Backward
  Serial.println("Tilt Backward");
  }
  
  // Wait X second/s before repeating :)
  delay (10000);
}

For the sake of your eggs: use reliable temperature (DS18B20, thermistor, BME280) and humidity (BME280) sensors.