Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Applying 5V to Pin set as Output?

Status
Not open for further replies.

jessicabrenner

New Member
Hello,

I would like to control a relay using two possible inputs. The first method of control will be an I/O pin of an arduino (configured as an output pin). The second method of control would be any other 5V signal (for instance from another microcontroller output pin, or another pin on the same arduino).

If I connect both to the relay signal pin directly, then when I send 5V from one pin to the relay, the 5V will also be applied to the other output pin. Will applying 5V from one pin to another output pin destroy either pin or microcontroller?

Thanks!
 
I guess if one is set to high (5V), and the other to low (0V), then of course this will draw too much current, and it will destroy the pins or microcontroller. So is the solution to simply place a high enough resistor after each output? Or a diode after each output?
 
Will applying 5V from one pin to another output pin destroy either pin or microcontroller?
Yes, it may do, it is certainly a bad idea.

However, all that you need to do is to put a diode in series with each 5v output before they are connected together to drive the relay, and it will work OK.

But, does the output pin of the arduino have enough current to drive a relay?

JimB
 
Safer to use a transistor to switch the relay, and have the micro and other source drive the transistor via the diode-or arrangement Jim mentions. And don't forget the freewheel diode across the relay coil!
 
The arduino output pin won't drive the relay directly. I am using a relay board which contains a transistor and other stuff which will allow the arduino to turn on the relay. This is the relay board/module: https://www.dfrobot.com/index.php?route=product/product&product_id=64

The diode will cause a slight drop of voltage, right? If its a small drop, then I guess it can still work. Would using a large resistor work instead? I'm thinking not because it will just decrease the voltage too much. Here is the relay board schematic by the way:
https://www.dfrobot.com/image/data/DFR0017/Relay Module V3 SCH.pdf
 
If it is two Arduino pins then instead of switching the pin to 0V you can switch it to input and prevent any contention. If both are set to input then the relay will be off - either/both set to output and high will turn the relay on.

Mike.
 
Mike, great suggestion! The relay is meant to be able to also be activated by an optional user-supplied external device at any time with no delay and whose input/output pin configuration is not user-adjustable. So when the arduino output pin goes high, it may be connected to the external device's output pin which is set to low (if the user forgets to remove the connection). So your suggestion would work if I had control over both pin configurations, but unfortunately I don't. :(

By the way, is there any delay from switching an input pin to output pin?
 
Use a diode on the external input. Switching to input/output is as fast as low to high - for pics anyway, I don't know Arduino..

Edit in the time it takes your relay to move, your micro will have executed thousands of instructions. I don't think you need to worry about software delays.

Mike.
 
The diode will cause a slight drop of voltage, right?
Insignificant if connected between J1 and R2 of the relay board. Connect the second diode from the external device to R2 also. The cathodes of both diodes go to R2.
All this assumes that neither the Arduino nor external device has priority so as to force the relay off when the other wants it on.
 
Thanks for the suggestions guys. I'll just use a diode or two. Just for the sake of exploring other options, would using an appropriate OR gate be another solution? Both the arduino output pin and the external device's output pin can go to the OR gate's input. Preferably, the output voltage would be 5V (instead of 5V minus the voltage drop from a diode or transistor). Is that possible with an OR gate that is supplied only with 5V Vcc?
 
The diodes already perform an OR function, of course, but a 74HCxx gate would do the job. I don't know why you're concerned about the 0.7V drop; the relay board would tolerate quite a wide range of input voltage.
 
Thanks I'll take a look at the 74HCxx's. I will use the diodes, but was just asking in case I did not want any voltage drop in some hypothetical future case.

Thanks everyone!

(Reading the datasheet for the 74HC32, it looks like if I limit the current to less than -20 microamps, the output voltage should match Vcc.)
 
Last edited:
Here's another solution that is all in the software (no diodes or gates!). I'm not sure if it would be wise though.

I will use 4 pins (pins 8 through 11, but 1 to 4 for this discussion). All will be configured as inputs initially.

Pin 1 will monitor a button press. Upon button press, Pin 2 will be configured to be an output and then will be set HIGH to activate the relay. After an amount of time specified in software, the pin will be set to LOW and configured back to an input.

Meanwhile, Pin 3 will monitor the external signal. As soon as an external 5V signal is detected, Pin 4 will be configured to be an output, and will be set HIGH to activate the relay. As soon as Pin 3 detects that the 5V signal has ceased, Pin 4 will be set LOW and configured back to an input.

In doing this, Pins 2 and 4 that are connected to each other will never be in danger of both being an output while one is HIGH and one is LOW at the same time.

The only problem that I see that this might have is if both inputs were HIGH, then one went LOW... There would be a miniscule amount of time between when the output pin went LOW and when it is configured to an input, and I don't know if that small amount of time is enough to fry the pins. Fortunately, when one output is HIGH, the software will be stuck in a while loop associated with that pin, which means pins 2 and 4 will never both get HIGH together. (In other words, there will never be a time when both are configured as outputs, so everything is fine.)
 
K.I.S.S ;) Just use 2 diodes. Most of the time your relay will be controlled via a transistor or mosfet, so the voltage drop wont matter much.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top