Just want to point out that if you are going to use the code with an active-low relay, you’ll need to change both the setup() and toggleRelay() functions.
In setup, change:
pinMode(door1_openPin, OUTPUT);
digitalWrite(door1_openPin, LOW);
pinMode(door1_closePin, OUTPUT);
digitalWrite(door1_closePin, LOW);
pinMode(door1_statusPin, INPUT_PULLUP);
door1_lastStatusValue = digitalRead(door1_statusPin);
if (door2_enabled) {
pinMode(door2_openPin, OUTPUT);
digitalWrite(door2_openPin, LOW);
pinMode(door2_closePin, OUTPUT);
digitalWrite(door2_closePin, LOW);
pinMode(door2_statusPin, INPUT_PULLUP);
door2_lastStatusValue = digitalRead(door2_statusPin);
}
To:
pinMode(door1_openPin, OUTPUT);
digitalWrite(door1_openPin, HIGH);
pinMode(door1_closePin, OUTPUT);
digitalWrite(door1_closePin, HIGH);
pinMode(door1_statusPin, INPUT_PULLUP);
door1_lastStatusValue = digitalRead(door1_statusPin);
if (door2_enabled) {
pinMode(door2_openPin, OUTPUT);
digitalWrite(door2_openPin, HIGH);
pinMode(door2_closePin, OUTPUT);
digitalWrite(door2_closePin, HIGH);
pinMode(door2_statusPin, INPUT_PULLUP);
door2_lastStatusValue = digitalRead(door2_statusPin);
}
And change toggleRelay() from:
void toggleRelay(int pin) {
digitalWrite(pin, LOW);
delay(relayActiveTime);
digitalWrite(pin, HIGH);
}
To:
void toggleRelay(int pin) {
digitalWrite(pin, LOW);
delay(relayActiveTime);
digitalWrite(pin, HIGH);
}
I think that should do it, but I haven’t really thought through the implications. Do let me know how it works, I may decide to implement this after all with a simple schematic if people want to do active-low. I know the Sainsmarts are popular.