# Turn on a relay when the output is high

I purchased a 5V 8 channel realy to use with Arduino. When the output is low the relays are on. I need to turn the relays on when the output signal is high. Is there a way to make the board respond to a high input and to turn on the relay?

You could

• invert the signal inside the software. This would be my choice.
• put an inverter between the Arduino and the relay board. Take for instance a 74HC540(my original suggestion) or a much more common uln2803 as StevenH suggests. This would be my choice if you really can't change the software.
• change the board itself. Bad choice IMO.
• Just curious: For the software approach, "Invert the signal" meaning what exactly? The OP has an Arduino whose output is connected to the trigger input of the relay board. Current config: A Low from the Arduino turns the relay on. Desired config: OP wants a High from uC to turn it on. How could the code fix this? – boardbite Sep 10 '12 at 14:17
• The OP wants to have the relay on in a certain situation. The current software outputs a 1 in that situation, while a 0 is required to turn the relay on. If the OP modifies the software to output the inverse he gets what he wants without any hardware modifications. – Wouter van Ooijen Sep 10 '12 at 15:00

Inverting the logic in your software, like Wouter says, is the zero cost solution. If you don't want that you can change the logic with little hardware.

For a single relay I would use an NPN transistor, but you have 8 relays and then the ULN2803 is a good solution.

It's an array of 8 transistors with base resistors integrated, so you don't need any other components, not even a power supply. Due to the higher saturation voltage of the Darlington transistors your LED current will be a bit lower, but the Darlington on the relay side will fix this. You may also decrease the value of R1, the LED's series resistor.

• That's an open-collector (pull-down-only) chip, so depending on the relay module the OP might need 8 pull-up resistors. – Wouter van Ooijen Sep 10 '12 at 11:25
• @Wouter - did you look at the schematic of the module? The input is the cathode of a LED, in series with an optocoupler's LED, in series with a current-limiting transistor. Open collector is what you need here. (It's not clear to me why they need the optocoupler, though.) – stevenvh Sep 10 '12 at 11:32
• !! I checked the datasheet (click on the text "download link"), but that does not show the circuit. But the page itself has a picture. Stupid circuit IMO, but indeed, it fits well with an 2803. Equally well with my suggestion, but a 2803 is a much more common chip. – Wouter van Ooijen Sep 10 '12 at 11:50
• @Wouter - the outputs of the '540 can sink enough current to drive a relay, so that seems a good find, but the IC's ground current is 50 mA Absolute Maximum Ratings, so for all relays on you should stay well below 6 mA, and that may be too little for the (unidentified) optocoupler. In any case you'll have to increase the series resistors then. – stevenvh Sep 10 '12 at 14:13

Maybe I'm misreading the device data, but with this device you have both options available to you?

A logic 0 at the input connects relay pins 1 and 2 A logic 1 at the input connects relay pins 2 and 3

So if your load is currently over pins 1 and 2, swap it to 2 and 3

• That would mean you activate the relay to switch it off. That's not a good idea for two reasons. One: You may consume power to do nothing. If you activate the relay to switch something on, then there's a load anyway, so the extra bit for activating the relay doesn't matter. Two: Safety. If there's a power outage on the driving side the relay would get switched on. A failure always should switch off a load. – stevenvh Sep 10 '12 at 14:08
• @stevenvh - I absolutely agree, but the questioner wasn't asking that, was he? If you take that line, then the only safe answer to the OP is "No!" :) – Andrew Sep 10 '12 at 14:17
• @stevenvh "A failure always should switch off a load." not if the load is my Wifi Access Pont! :) If the Arduino fails, I want it on, and in normal circumstances I want it on without the Arduino providing any power. But I know you are normally right. – FrancescoMM Sep 29 '17 at 14:30

Have a look at Arduino cc and look at digitalWrite()

You then set your pin to output low to turn your relay on don't forget to set your pin as an output.

Bob

• This would be better if you included some more information, I assume the OP knows how to control outputs and just wonders how to invert them. – PeterJ Nov 25 '14 at 13:21

Inverting the logic on the code is not always a good solution because the relay can be turned on while the device is booting.

Another solution is using these connections:

JD-VCC ----> 5V
VCC    ----> Digital IO
IN     ----> GND
GND    ---—> GND


The digital input can be 3.3V

Unhappily it does not work when we have many relays on the same board sharing the same VCC and GND.

my relay board has 3 terminals for each relay center is the power input and then there is the normally open and closed sides as a safety option i believe the relay is set to open so if some mishap happened the power is off so just switch the output on the relay to the other side and in my mind you fixed the issue