Hi Everyone. I saw the code on the link attached and couldn't reply on the post because it is already closed. I am developing similar project but for me it is irrigation system and I need to turn the pump on once every after 2 days for 2min. The code that I found on the forum works perfect but because in my country I experience lots of loadshadding (Power cut) almost everyday, this defeats the purpose of the code. I think I need a memory for that to happen (EEPROM maybe) :
#include <DS3231.h>
const byte RelayPin = 4;
DS3231 rtc(SDA, SCL);
Time t;
static int lastMinute = 0;
const int OnHour = 22; //SET TIME TO ON RELAY (24 HOUR FORMAT)
const int OnMin = 33;
// const int OffHour = 22; //SET TIME TO OFF RELAY
// const int OffMin = 34;
void setup()
{
Serial.begin(115200);
rtc.begin();
pinMode(RelayPin, OUTPUT);
digitalWrite(RelayPin, LOW);
lastMinute = EEPROM.read(0);
}
void loop()
{
static int dayCounter = 0;
t = rtc.getTime();
// Once per minute...
if (t.min != lastMinute)
{
lastMinute = t.min;
// ...Display the time...
Serial.print(t.hour);
Serial.print(" hour(s) , ");
Serial.print(t.min);
Serial.println(" minute(s) ");
// ...And check for ON time...
if (t.hour == OnHour && t.min == OnMin)
{
// ...But only act every 2nd day
dayCounter++;
if (dayCounter == 2)
{
dayCounter = 0;
digitalWrite(RelayPin, HIGH);
Serial.println("Pump ON");
delay(120000UL); // Keep the pump ON (?) for two minute
digitalWrite(RelayPin, LOW);
Serial.println("Pump OFF");
}
}
EEPROM.update(0, lastMinute);
}
}
I have only added EEPROM syntax to store the lastMinute updated and to remember it when the Arduino switch on after power cut.
Firstly i am not sure if that's a good way of doing it, secondly the problem is, what would happen if the power cut happens at 22:00?