garage opener single wire with multiple outputs

Hello everyone,

So I got a residential garage door opener and tried using it on my commercial doors at the office. The opener works fine, it runs through an app and has never failed, but only does one function. since the doors use a key relay to open and close, it is two separate relays that close the circuit to the motor when the key is turned to either open or close side. My problem is that the control i bought can only be connected to one relay at a time.
For wiring the positives on the relays are looped together and the negative has to go on one of the negatives on the relays. When I looped the negatives it would go up and down and like crazy and stop shortly after.

My solution was to use an arduino to connect the second wire from the controller going to the relay. From here I tried to code something to recognize all 4 of my doors for a pin on the board and have those 4 inputs and two outputs for each(the open and the close). At first I tried a counter that would increase whenever the input detected current and would ouput through the open or close pin assigned to the number and door input where current was coming through. Since I couldn't get that to work, I decided to try a simpler method.

What I am trying to do is infinitely read current through the 4 pins for the doors (loop digitalRead) and then when current is detected it will run open one time and continue with the loop for reading the input. When current goes in again, it will run the close pin and then continue the loop for reading. It seems straightforward, but I am barely learning how to code and cannot get it. This code should work perfectly and not mess with the door when it is opened or closed still using the key mechanism, by what I think.

Last code I wrote got deleted after it didn't work and it gave up, but here is the base that is was built on.

SA and TX are the street names for the doors and O and T are just One and Two for the doors on each street, O and C are Open and Close.

int SAO = 0;
int SAT = 1;
int TXO = 2;
int TXT = 3;
int SAOO = 4;
int SAOC = 5;
int SATO = 6;
int SATC = 7;
int TXOO = 8;
int TXOC = 9;
int TXTO = 10;
int TXTC = 11;

void setup(){
pinMode (SAO, INPUT);
pinMode (SAT, INPUT);
pinMode (TXO, INPUT);
pinMode (TXT, INPUT);
pinMode (SAOO, OUTPUT);
pinMode (SAOC, OUTPUT);
pinMode (SATO, OUTPUT);
pinMode (SATC, OUTPUT);
pinMode (TXOO, OUTPUT);
pinMode (TXOC, OUTPUT);
pinMode (TXTO, OUTPUT);
pinMode (TXTC, OUTPUT);

char r1 = digitalRead (SAO);
char r2 = digitalRead (SAT);
char r3 = digitalRead (TXO);
char r4 = digitalRead (TXT);

const int PCO = 0;
const int PCW = 0;
const int PCT = 0;
const int PCF = 0;
}
void loop(){

}

Sorry for the mess of information and the way I structured it, hopefully someone can see this and help me. Thank you

The variables that you declare inside of setup() are in scope only in setup(). They do not exist outide of setup().

Indeed those const int declarations probably should be global.
You're doing a digitalRead() on four pins in setup and then do nothing with it. these probably have to go in loop().
Instead of O and T for 1 and 2, why not use the numbers? It's simply clearer.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

What model Arduino are you using?

Thanks.. Tom... :slight_smile:

Thanks for the all the advice, I'm new to this stuff and "taught" myself in two days which is why my setup isn't the way it should be. I moved the digitalReads to the loop and put the pinModes in setup, still don't know if that's the way but I'll try a couple of things for now.

So I cleaned it up a bit from whatever it is I had before (partial messed up reference code I kept to copy from) now i just want to know how to have the open and close function alternate. After it digitalWrites to the open and finishes, how do I set it up to run the close the next time digitalRead = HIGH?
Also I'm using an Uno R3.

void setup(){
int SAO = 0;
int SAT = 1;
int TXO = 2;
int TXT = 3;
int SAOO = 4; 
int SAOC = 5;
int SATO = 6;
int SATC = 7;
int TXOO = 8;
int TXOC = 9;
int TXTO = 10;
int TXTC = 11;

 pinMode (SAO, INPUT);
 pinMode (SAT, INPUT);
 pinMode (TXO, INPUT);
 pinMode (TXT, INPUT);
 pinMode (SAOO, OUTPUT);
 pinMode (SAOC, OUTPUT);
 pinMode (SATO, OUTPUT);
 pinMode (SATC, OUTPUT);
 pinMode (TXOO, OUTPUT);
 pinMode (TXOC, OUTPUT);
 pinMode (TXTO, OUTPUT);
 pinMode (TXTC, OUTPUT);
}
void loop(){
char r1 = digitalRead (0);
 char r2 = digitalRead (1);
 char r3 = digitalRead (2);
 char r4 = digitalRead (3);

  
if (char r1 = HIGH);{
 digitalWrite (4,HIGH);
}

if (char r2 = HIGH);{
  digitalWrite (6,HIGH);
}

 if (char r3 = HIGH);{
  digitalWrite(8,HIGH);
}

 if (char r4 = HIGH);{
  digitalWrite(10,HIGH);
  }
 }

Hi,
Move all the int statements to before void setup() .
That will make the variables global, not just confined to void setup() use.

Tom.. :slight_smile:

Also no need to use a 2-byte int for that (on other platforms it's even 4 bytes for an int), better declare it as byte instead. Saves space. Or even better, const byte, as they're constants and never to be changed in code.

I normally declare pins using #define statements - no variable to be stored in memory, should save a bit more space, at least you should save some RAM (haven't tested this in detail & never found any reference on which way would be better and why).

const or #define.
I just use byte myself.