//Slide switch closed is garage doors closed and loop closed; slide switch open is loop open;
//Doors open relay energizes and garage loop shunted
//1st LED indicates module is in standby mode; garage loop will trigger alarm if either or both doors opened.
//2nd LED indicates garage loop is shunted - Locked out
//3rd LED indicates shunt relay is in delay mode
int relay = 2; //garage loop shunt relay
int button = 3; //activate module; pin 3 is pulled up with 1k resistor.
int drsense = 4; //simulates garage loop opening and closing. Actual loop leads connect to pin 4 and ground.
int ledLO = 6; //LOCKOUT MODE - garage loop will be shunted even if doors are open; allows unlimited time to exit and secure
//garage doors.
int ledD = 7; //DELAY MODE - the garage loop will be shunted and for the set time, then the garage door loop will be enabled.
int ledN = 8; //NORMAL/STANDBY MODE
int relayDr = 9; //When doors closed relay is OFF and alarm loop is closed via NC and COM contacts; when doors open, relay is ON
//and alarm loop is opened.
unsigned long prevTime = millis();
void setup() {
pinMode(relay, OUTPUT);
pinMode(button, INPUT);
pinMode(drsense, INPUT);
pinMode(ledLO, OUTPUT);
pinMode(ledD, OUTPUT);
pinMode(ledN, OUTPUT);
pinMode(relayDr, OUTPUT);
}
void loop() {
unsigned long currentTime = millis();
//If shunt relay is off, energize door relay when door loop is open
if(digitalRead(relay) == LOW) {if(digitalRead(drsense) != LOW) {digitalWrite(relayDr, HIGH);} else {digitalWrite(relayDr, LOW);}}
//If shunt relay is off, ledN is ON
if (digitalRead(relay) == LOW) {digitalWrite(ledN, HIGH);}
else {digitalWrite(ledN, LOW);}
//Press button, energize shunt relay, start timer
if(digitalRead(button) == LOW) {digitalWrite(relay, HIGH);prevTime = currentTime;digitalWrite(ledD, HIGH);}
//If button pressed while doors are open, then door open relay is turned OFF causing the alarm loop to be closed. Otherwise, when
// the shunt relay is turned OFF after the timed delay there might be a false alarm.
if(digitalRead(button) == LOW && digitalRead(drsense) != LOW) {digitalWrite(relayDr, LOW);}
//If shunt relay is ON and garage loop is open, reset timer, ledLO ON, ledD, OFF; if not, ledLO OFF
if (digitalRead(relay) == HIGH && digitalRead(drsense) != LOW) {prevTime = currentTime;digitalWrite(ledLO, HIGH);digitalWrite(ledD, LOW);}
else {digitalWrite(ledLO, LOW);} //if shunt relay (relay) is energized and door loop is open then, reset timer, turn off ledLO
//If shunt relay is ON and garage loop is closed (doors closed) ledD ON and ledLO OFF
if (digitalRead(relay) == HIGH && digitalRead(drsense) == LOW) {digitalWrite(ledD, HIGH);digitalWrite(ledLO, LOW);}
//If shunt relay is ON and if timer has timed out, reset timer, turn OFF shunt relay, ledD OFF
if(digitalRead(relay) == HIGH) {if (currentTime - prevTime >8000) {prevTime = currentTime;digitalWrite(relay, LOW);digitalWrite(ledD, LOW);}}
}
//The shunt relay NO and COM terminals are conntected to the alarm delay loop. The garage door loop is connected to pin 4 and ground.