User avatar
Vince8134
Posts: 5
Joined: Mon Feb 10, 2014 10:11 pm

Having a 8-channels relay working with ULN2803A and 5V

Tue Aug 12, 2014 12:42 pm

Hey,

I'm at the end of a project to monitor lighting, climate and several other devices in a chilled terrarium, but I'm stuck with troubles related to 8-channels 5V relay.
I try to follow the advice read here ==> http://arduino-info.wikispaces.com/RelayIsolation and I ended up willing to use a ULN2803A chip to benefit from the flyback diodes.

I found many advice on this forum and on the internet but unfortunately, I haven't completely figured out yet how to properly wire my boards, in order to profit from the opto-isolators and to be done with the EMI problems that I met at the moment. I would like to get a prior confirmation before any attempts.

I have summed up 4 diagrams, of which I hope one is correct.

Number 1). I don't use the opto-isolations and grounds are not common :
Image


Number 2). Because I read many times RPi and 5V power supply grounds must be common, here it is :
Image

Number 3) : Opto-isolation provided, but not common grounds :
Image

Number 4 ) : Opto-isolation + common grounds :
Image

Maybe I got everything wrong and I have to give it another go. Please, could you help me out here, and tell me which diagram I should follow to get everything working out ?

Thanks.

Vince

ddahms
Posts: 77
Joined: Tue Mar 18, 2014 3:38 pm

Re: Having a 8-channels relay working with ULN2803A and 5V

Tue Aug 12, 2014 8:40 pm

Your circuit #2 is the right way to go. The ULN2803 is driving optoisolators that do not produce any inductive spikes so the flyback diodes won't be doing anything. The connection to pin 10 is unnecessary.

User avatar
Vince8134
Posts: 5
Joined: Mon Feb 10, 2014 10:11 pm

Re: Having a 8-channels relay working with ULN2803A and 5V

Wed Aug 13, 2014 1:56 pm

Hello,

Thank you for your answer. Ok for #2, but I won't have any opto-isolation in this case, will I ?

User avatar
Cancelor
Posts: 780
Joined: Wed Aug 28, 2013 4:09 pm
Location: UK

Re: Having a 8-channels relay working with ULN2803A and 5V

Wed Aug 13, 2014 2:50 pm

The opto isolation is built into the relay board see U1 in the schematic in your link http://arduino-info.wikispaces.com/RelayIsolation ;)
Can't find the thread you want? Try googling : YourSearchHere site:raspberrypi.org

ddahms
Posts: 77
Joined: Tue Mar 18, 2014 3:38 pm

Re: Having a 8-channels relay working with ULN2803A and 5V

Thu Aug 14, 2014 3:57 am

I believe #3 will work too. In #2, your external supply provided power to turn on the isolators. In #3, the Pi's own +5V supply provides that power. Circuit #3 will have isolation between the Pi power and your relay power. Maybe this is important to your application.

onlineuser
Posts: 8
Joined: Mon Jun 08, 2015 6:31 am

Re: Having a 8-channels relay working with ULN2803A and 5V

Sun Jan 22, 2017 7:52 am

#3 is the best one - most secure for Raspberry!

- not common 5V supply
- not common ground

Ghwana
Posts: 77
Joined: Mon Nov 13, 2017 12:04 pm

Re: Having a 8-channels relay working with ULN2803A and 5V

Mon Nov 20, 2017 2:33 pm

Hi, I'm relatively new to this raspberry Pi 3b scenario, I'm using a keyestudio 8-channel 5v relay module and have tried examples 2 & 3 without any success, the only difference is the keyestudio does not have the separate power pins GND VCC and JD-VCC. It just has this, see below

VCC GND IN1 IN2 IN3 IN4 IN5 IN6 IN7 IN8 COM GND

Please can someone help, power light on relay board is coming on, have connected it to separate 2.5A 5V DC transformer, but relays are not coming on at all. Have had python code working perfectly on LED array, but nothing on relay board!!??

Please help if you can.
Cheers

pcmanbob
Posts: 13570
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Having a 8-channels relay working with ULN2803A and 5V

Mon Nov 20, 2017 3:21 pm

Hi.

Your board is different to the ones mention in this post in that it requires a 5v input high signal to turn the relays on, were as the one in the above examples require a 0v low to be applied to the input to turn the relays on. you cant use the examples above to control your relay board.

http://wiki.keyestudio.com/index.php/Ks ... lay_Module

you could prove this without using a pi.

connect power supply vcc to 5v, GND to GND, COM to GND then apply 5v to any of the in1 to in8 pins and the relay should activate.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Ghwana
Posts: 77
Joined: Mon Nov 13, 2017 12:04 pm

Re: Having a 8-channels relay working with ULN2803A and 5V

Mon Nov 20, 2017 4:31 pm

Thank you for your response, it is working, can I now use the ULN2803a with the RPi to change 3v3 to 5v?

pcmanbob
Posts: 13570
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Having a 8-channels relay working with ULN2803A and 5V

Mon Nov 20, 2017 6:58 pm

Ghwana wrote:
Mon Nov 20, 2017 4:31 pm
Thank you for your response, it is working, can I now use the ULN2803a with the RPi to change 3v3 to 5v?
No you cant use the ULN2803A in that way, as its a current sink not a current source.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: Having a 8-channels relay working with ULN2803A and 5V

Mon Nov 20, 2017 7:35 pm

Why do you need to use a ULN2803A at all considering the relay board already has a 817c optocoupler. Won't this prevent EMF feedback?

pcmanbob
Posts: 13570
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Having a 8-channels relay working with ULN2803A and 5V

Mon Nov 20, 2017 8:14 pm

Why do you need to use a ULN2803A at all considering the relay board already has a 817c optocoupler. Won't this prevent EMF feedback?
The relay boards shown in the above diagrams all use 5v on the opto-isolator inputs, and sink the current using the in pins which are connected to the pi gpio, this results in 2 problems

1 - 5v is being connected to the GPIO very bad.
2 - operation logic is reversed so low on GPIO = relay on

by using ULN2803A you isolate the GPIO form the 5v on the relay board and you restore normal logic so high GPIO = relay on
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Ghwana
Posts: 77
Joined: Mon Nov 13, 2017 12:04 pm

Re: Having a 8-channels relay working with ULN2803A and 5V

Tue Nov 21, 2017 8:51 am

Thank you very much for your responses. Just so I'm understanding this correctly, using the ULN2803A chip is a safer solution for the GPIO and RPi as a whole, is this correct? If so do I need to have 5V on pin 10?

pcmanbob
Posts: 13570
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Having a 8-channels relay working with ULN2803A and 5V

Tue Nov 21, 2017 9:13 am

Yes that's correct it provides the isolation between the 5v and the pi gpio, you may not need the 5v connection to the chip its normally used for fly back diode connections within the chip but by habit I always connect it.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Ghwana
Posts: 77
Joined: Mon Nov 13, 2017 12:04 pm

Re: Having a 8-channels relay working with ULN2803A and 5V

Tue Nov 21, 2017 9:26 am

OK, thank you. So in order to get 5V to the relay board through the chip, what sequence of resistors/transistor, do I need to make the relays work?

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: Having a 8-channels relay working with ULN2803A and 5V

Tue Nov 21, 2017 9:27 am

Ok thanks I have looked closely at the diagram and now realize they have a 1k resistor on the supply to the octocoupler and the indicator LED forward voltage means it will need a supply voltage of 5v.

So would either of these 2 options work as well :
1. Change the resistor to a smaller one so that you can use a 3.3v supply VCC supply to the octocoupler and wire like #3 but without the ULN2803A
2. put a voltage divider on you IN pins and wire like #3 but without the ULN2803A [edit] ok this wouldn't be so good as it could cause the octocoupler to part open.

This should be very safe for the MCU with full isolation.

[edit] yes I understand why it is probably an easy solution to use a transistor to switch the 5v returning to ground and also will invert high/low control of the relay. All caused by the boards being built designed for 5v with large 1k resistor on VCC on supply to ocotcoupler
Last edited by OutoftheBOTS on Tue Nov 21, 2017 9:46 am, edited 1 time in total.

Ghwana
Posts: 77
Joined: Mon Nov 13, 2017 12:04 pm

Re: Having a 8-channels relay working with ULN2803A and 5V

Tue Nov 21, 2017 9:38 am

Thank you, #3 has separate GND,VCC & JDVCC pins, the Keyestudio, does not have the separate power pins, just see below

VCC GND IN1 IN2 IN3 IN4 IN5 IN6 IN7 IN8 COM GND

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: Having a 8-channels relay working with ULN2803A and 5V

Tue Nov 21, 2017 11:26 am

Does anyone have a schematic for the Keystudo relay board?

I am a little confused why or how they have wired an optocoupler when they only have 1 power source.

pcmanbob
Posts: 13570
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Having a 8-channels relay working with ULN2803A and 5V

Tue Nov 21, 2017 7:51 pm

OutoftheBOTS wrote:
Tue Nov 21, 2017 11:26 am
Does anyone have a schematic for the Keystudo relay board?

I am a little confused why or how they have wired an optocoupler when they only have 1 power source.
No diagram but from the way the board seems to work 5v from arduino input used to power led side of opto-isolator with a common ground and 5v supply on relay board used to power relays via transistor in opto-isolator

were as the other type of relay board uses the same relay board power supply to supply the LED in the opto-isolator and the ground is supplied via the in pins which get connected to the GPIO hence the reversed logic operation and 5v supply on relay board used to power relays via transistor in opto-isolator
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: Having a 8-channels relay working with ULN2803A and 5V

Tue Nov 21, 2017 8:01 pm

for give me if I am wrong but if the board is designed using the common power led side of opto-isolator with a common ground and 5v supply on relay board used to power relays via transistor in opto-isolator doesn't this defeat the purposes of using a opto-isolator.

They would get exactly then same outcome just switching a transistor to turn on the relay with the 5v and add a fly back diode.

pcmanbob
Posts: 13570
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Having a 8-channels relay working with ULN2803A and 5V

Tue Nov 21, 2017 8:27 pm

This is the diagram for the most common relay board.

Image

vcc from power supply is used to power relays can be 5v or 12v depending on board and second 5v vcc from pi or arduino used for powering LED side but many boards have jumper connecting these to and now some boards dont even have a jumper just both vcc hard wired together.

now the board that needs a 5v input to power LED has the VCC and the IN0 reversed so it looks like this

Image

so the common point instead of being the VCC input now becomes the COM terminal which is jumpered to GND on the board in question.

personally I don't used ready made relay boards I just build what I need using relay, diode and ULN2803A for multiple relays or replace ULN2083A with transistor for single relays.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: Having a 8-channels relay working with ULN2803A and 5V

Wed Nov 22, 2017 12:44 am

ok now I understand why they put a octo in. It is for a relay that requires more than 5v to operate. The ocoto will provide isolation from relay that needs more than 5v but is totally not needed for 5v relays that is used by these boards and to further more once you connect the jumper or the board doesn't have the jumper then the octo doesn't do anything anymore anyway. It would seem to build a board with an octo on a 5 volt relay or on a board without the removable jumper doesn't make any sense. I can't work out their thinking is having them there

Ghwana
Posts: 77
Joined: Mon Nov 13, 2017 12:04 pm

Re: Having a 8-channels relay working with ULN2803A and 5V

Wed Nov 22, 2017 10:37 am

Thank you all for your help, I managed to get it to work perfectly with 2 x resistors and 1 transistor, without ULN2803A and using existing 3V3 from Raspberry, relay board has built in protection, so no high return voltage coming back. Runs 24V pump perfectly, with pulse action so can use it as sprinkler system, also had no problem running all eight relays with same pulse action at 0.09s.

Thank you all for your help, it was much appreciated.
Cheers Ghwana

pcmanbob
Posts: 13570
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Having a 8-channels relay working with ULN2803A and 5V

Wed Nov 22, 2017 6:30 pm

Just be aware that if you are switching mechanical relays on a 9 second interval, you may wear them out very quickly, as mechanical relays are no designed to be switched on and off on such a short cycle..
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Automation, sensing and robotics”