Use digital pin,both as input and outpout,without always reconfiging the pinMode

hello forum. i am on a project, to create a moduele, that will allow me to control the car power windows, both from a pc, and from the normal power switches.
controlling the relays that will do this, with arduino is pretty straightforeward, but the catch is, i want to keep the power switch operation, as hardware as possible..

here is the schheamntic i am planing on using:
http://imgur.com/ISQNZk8
(with blue lines, is the part i am asking for :stuck_out_tongue: )

the thing is, that the two relays must NEVER be closed at the same time.. arduino can do this easy via software , but if the user presses the switch (roll down) at the same time as the arduino is rolling up the window, then there will be short-circuit between the two relays..

this is why i have set the power switches to give 5v directly to the transistor that the arduino oparates, and at the same time, give 5v to the arduino digital pins. , so in that way, the hardware buttons are always on top control, and on the arduino software i wil lhave something like this :

pinMode(1,OUTPOUT)

 IF  you want to roll up/down a window {
     IF  digitalread(1) and digitalread(2) are both low {
      roll up/down
      }
}

will this work? i suppose i should add a curreent limiting ressistor on the blue lines. but my main problem is this :can the arduino use pins configured as outpout, to read an input???
thanks!

As you suspect it creates a short circuit if the pin is an output and low when you press a button. The better method is to just wire the two switches to unused arduino input pins and do all your 'interlock logic' in your sketch software.

If you have 2 extra pins left I would use those as well.

Using OR-gates would be possible as well. OR-gates are available with 2 or more inputs and when one or more inputs is/are HIGH, so is the output. Most OR-chips house several OR gates.

In the lists below, you can find several types..

Hi, the solution is already in the normal window switches in a car, they use SPDT ROCKER switches.

Use one SPDT switch to do the job of both sw1 and sw2, then both switched outputs will never be on together.

Please check the normal power switches that you talk about and see what they do, if the basic system is already fitted, then it must have some way of interlocking all ready as part of the system.

Also use diodes on the arduino output, so that you can leave the arduino outputs as outputs and the diode stops the switch from feeding current into the arduino.

Sorry can't supply a diagram, its morning and I'm off to work, will check back tonight if you need a diagram.

Tom.... :slight_smile:

TomGeorge. i know what you are talking about. but my worry, is that there actally be TWO "rocker switches" for each window... one the normal hardware button, and the other, a digital button on my pc screen... so i want to make sure, that it will not short-circuit anything if the pc buttons, and the hardware ones, are both pressed at the same time!!

but i see now, that becouse the relays take some time to de-energize, even if the arduino uses some logic, to detect if the hardware buttons are pressed, then there will still be a short-circuit, for some mS, (as much time the relay takes to close...)

so i think the only possible solution would be something like this :
connect the relays in a way, that it is "hard-wired" impossible for the 2 relays to be energized at the same time.... any idea how i could do that??

Have you chosen the relay yet or is it already installed?
If not, then get relays with two sets of change over contacts and cross wire the coils through the extra set so when one is ON, current cannot be supplied to the coil of the other.

This is quite commonly done in situations where forward/reverse relays are used.

Tom...... :slight_smile:

i already have them... plus, they are already 2 channels, and both channels are used , (for +12v and gnd to window motor)...

I believe you have not studied the wiring and do not know how the window controls work.

There is actually no problem with both relays being activated; this problem is already solved in respect of having the passenger press "up" while the driver presses "down".

All push switches (which includes each end of the rocker) are SPDT. Each one acts to lift one side of the motor connections from ground to the supply (or possibly the other way round) and all switches are "chained" so that those nearer the motor disconnect those further by their "NC" contact. If both "up" and "down" are simultaneously pressed, then both sides of the motor are pulled to the supply and it simply does nothing.

This page is not a bad illustration (about the best I could find in fact), and should suggest how you extend the presently installed system. Note that all switches or relays must be "break-before-make" action.

I believe you have not studied the wiring and do not know how the window controls work.

again.... when i am talking about two switches, i AM NOT talking about the switches of the power window wiring. try to understand what i am asking, before jumping to assumptions...
forget the power window wiring, and the harnes that comes with it.
i am making the control unit, from scratch (cause i wanted to add controll from the pc) . that is why i posted the circuit... the two switches are not "passenger" and "driver" , they are "real switch next to gear knob" and "digital switch on the pc screen"

if you want, i can make a complete circuit, (With the motors and all ) to be more clear :wink:

Form your initial posting.

settra:
the thing is, that the two relays must NEVER be closed at the same time… arduino can do this easy via software , but if the user presses the switch (roll down) at the same time as the arduino is rolling up the window, then there will be short-circuit between the two relays…

This is simply wrong. That is my point. Understanding that removes your concerns about interaction between the switches.

paul_B. did you not tried to understand my problem at all, or did you tried and just failed??
let me explain it to you , to as a base level as it can get...

the motor needs 12v to operate, and has 2 terminalas(A,b) . depending on how you wire the 12v, it rolls the window up or down. so in order to do this, you have two relays, with 2 channel each.
one relay gives 12v to terminal a, and GND to b. the other gives 12v to terminal b and GND to a.

in my current build, the relays are operated in that way :
constant 5v to the coil, and the GND path is interupted by an NPN transistor. so, when you bias the base of the transistor, the relay gets energized. you can do that on 2 ways :

  1. using the rocker switch (ilustrated with the two pushbuttons on my schemantic)
    2)the Adrduino gives 5v to the base. (When you press enother button, on my pc screen, which comunicates with the arduino via serial) ..

SO if arduino biases the one NPN transistor, and the driver biases the other via the power window switch, terminal a and b of the motor , will short circuit. this why i am looking for a way, to make it impossible for the one relay to energize, if the other is energized. all that for one window. another 2 relays etc for the other window.
now do you understand?

settra:
this why i am looking for a way, to make it impossible for the one relay to energize, if the other is energized. all that for one window. another 2 relays etc for the other window.
now do you understand?

And that is precisely my point. I see now that you simply do not understand how to wire up the circuit. Please study the circuit - and the explanations - on the link I provided in order to understand how to do it.

It then does not matter if both relays - or both window switches - are simultaneously pressed. when you wire the circuit correctly; the "problem" you are attempting to create has been solved long ago and it is particularly easy to do.

The motor in this circuit is always shorted out until a switch is operated. The only effect of shorting out the motor itself is to cause it to stop turning very quickly (which may sometimes be very useful). The circuit is wired so that it will not short out the supply form the car battery - that is what is important.

SO if arduino biases the one NPN transistor, and the driver biases the other via the power window switch, terminal a and b of the motor , will short circuit. this why i am looking for a way, to make it impossible for the one relay to energize, if the other is energized. all that for one window. another 2 relays etc for the other window.
now do you understand?

In the electrical word this is accomplished by 'interlocking' the relays in questions using multipole relays (typically DPDT) where a set of contacts of one relay breaks the coil circuit of the other relay and visa versa. So on any given relay one set of contacts control supplying voltage to the load, a motor in your case, and the other set of contacts opens the coil circuit of the opposite relay, thus preventing the possibility of having to relay coils powered at the same time.

yes the only problem is, you are adressing a DIFFERENT problem. i will not spend any more time in trying to show you this, so unless you actually try to understand the situation, dont post things that might confuse someone , that already had it right.

settra:
yes the only problem is, you are adressing a DIFFERENT problem. i will not spend any more time in trying to show you this, so unless you actually try to understand the situation, dont post things that might confuse someone , that already had it right.

Helpful if you would state who you are addressing specifically?

paull_b. sorry retrolefty, i answered at the same time as you where posting :D.
yes. what you are talking about, is what i had in my mind !

retrolefty:
In the electrical word this is accomplished by ‘interlocking’ the relays in question … and the other set of contacts opens the coil circuit of the opposite relay, thus preventing the possibility of having to relay coils powered at the same time.

Fair enough, but totally unnecessary in this case as the SPDT contacts simply switch the motor correctly in all cases.

If only people would read the link which explains this.

Hmm, let me see what I can do …
http://static.howstuffworks.com/flash/power-window-schematic.swf

yes, i have seen that link. but you completely ignore the fact that i also want control of the windows via the arduino!! this is why you have to resort to relays. (not to mention how dangerous it is to run unnecessary long power cables throught the car carpets )

It’s perfectly normal for electric windows to be controlled by multiple switches, and I don’t see how it makes any difference if one of those switches is operated by an Arduino rather than a person. The answer that Paul__B keeps giving, which you keep dismissing, is surely the right answer.

the right answer, according to other forums as well, is what retrolefty suggested. interlocked relays.
what you guys suggest,which is hardly even a solution, (And i really hope that when you say that the arduino can operate switches, you mean relays), requires tha each window needs 4 relays instead of two.I am searching for the most straightforward solution, not the hardest and most ancient one. imagine if a modern car had to have 16 BEEF relays, JUST for the power windows.
microcontrollers are supposed to make life easier, not create problems...