#define presetTimedelaytoStartGen 2500 // time delay in milliseconds for power failure
//#define presetTimedelaytoSMS 1000 // time delay in milliseconds to send SMS
#define presetTimedelaytoStopGen 1500 // time delay in milliseconds for power restore
unsigned long CEBPowerfailtimecheck;
unsigned long CEBPowerRestoretimecheck;
//unsigned long GeneratorONTimechack ;
bool CEBPowerOk; // relay on means CEB Power ok (no power failure) - Slide Switch right to Simulate power failure
bool GeneratorRelaySignal;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(3, INPUT_PULLUP); // CEB power
pinMode(4, INPUT); // Generator 230V relay
pinMode(9, OUTPUT); // Generator ON
//timecheck = millis(); //
}
void loop() {
// put your main code here, to run repeatedly:
CEBPowerOk = digitalRead(3);
GeneratorRelaySignal = digitalRead(4);
if(CEBPowerOk) // CEB power ok - slide Switch to Left side to simulate CEB power ok
{
CEBPowerfailtimecheck = millis(); // this is the important code part don't delete
}
else // slide Switch right to simulate power failure
{
CEBPowerRestoretimecheck = millis(); // this is the important code part don't delete
}
if(millis() - CEBPowerfailtimecheck > presetTimedelaytoStartGen ) // if CEB power down more than 2.5 sec
{
digitalWrite(9, HIGH);
}
if(millis() - CEBPowerRestoretimecheck > presetTimedelaytoStopGen ) // If CEB power restored more than 1.5 seconds
{
digitalWrite(9, LOW);
}
}