cscuilla
Posts: 58
Joined: Tue Apr 26, 2016 6:35 pm

Control multiple relays with only One gpio pin (mcp23017)

Fri Oct 26, 2018 2:36 am

I have four relays hooked up which I want to power on and off all at the same time. They are all powered by external power supplies separate from the Pi/mcp23017. Can I hook the signal pins all up to the same mcp23017 output pin so that when i turn that pin high all the relays turn on?

Or do i need to hook each relay up to its own output pin.

I've tested with two relays hooked up to one output and it works, but i'm wondering if it is safe or would cause damage, and if it is safe, then how many relays can i hook up to the same pin?

LTolledo
Posts: 3428
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Control multiple relays with only One gpio pin (mcp23017)

Fri Oct 26, 2018 3:30 am

one "trick" you can use is to let one pin of the MCP23017 to control 1 relay (ex relay-1), and that relay-1 will control the other relays (relay-2, relay-3, .... relay-n) .

just make sure that the total current of all the relay coils passing thru relay 1 does not exceed 50% of the contact point maximum rating on relay-1
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

User avatar
davidcoton
Posts: 5027
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Control multiple relays with only One gpio pin (mcp23017)

Fri Oct 26, 2018 8:31 am

cscuilla wrote:
Fri Oct 26, 2018 2:36 am
i'm wondering if it is safe or would cause damage, and if it is safe, then how many relays can i hook up to the same pin?
You need to know to current draw (at 3V3) or sink (at 0V) of the relay input -- presumably there is a driver of sonme sort (transistor or optoisolator). If the total for four relays is below the GPIO specification, you're OK. If not a single transistor buffer would do the trick, at the slight complication of reversing the relay state relative to the GPIO state.

Finding the specs is left as an exercise for the reader -- ask again if you get stuck or want your findings confirmed.
Signature retired

cscuilla
Posts: 58
Joined: Tue Apr 26, 2016 6:35 pm

Re: Control multiple relays with only One gpio pin (mcp23017)

Fri Oct 26, 2018 12:35 pm

Thank you. It seems the relays use 5ma to trigger. The rpi gpio can output 16ma so I'm guessing it can only handle 3 relays.

The MCP23017 output 20ma I believe so it looks like I may be able to use 4 relays on this.

Is it safe to assume that if I try it, and it works, then I am ok, and will not cause damage to the rpi?

LTolledo
Posts: 3428
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Control multiple relays with only One gpio pin (mcp23017)

Fri Oct 26, 2018 2:09 pm

its the MCP23017 that will bear the brunt of the current surge, so it will get damaged first. Well, its cheaper to damage the I/O expander than the RPi itself

if you use 1 relay (controlled by 1 output pin of MCP23017) to control the other relays, you can control more than 100 (safe max 1000) other relays.
"1000 other relays" might be an overkill for your particular setup
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

cscuilla
Posts: 58
Joined: Tue Apr 26, 2016 6:35 pm

Re: Control multiple relays with only One gpio pin (mcp23017)

Fri Oct 26, 2018 3:18 pm

How would i use One relay to control the others..

Would i hold 5v in the relay, and then when that relay turns on, the 5v would be sent to the signal pin of the other relays?

@LTolledo

Brandon92
Posts: 847
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Control multiple relays with only One gpio pin (mcp23017)

Fri Oct 26, 2018 3:35 pm

What is the type of relais that you are using?


LTolledo
Posts: 3428
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Control multiple relays with only One gpio pin (mcp23017)

Fri Oct 26, 2018 9:57 pm

based on the information you provided this is what I have in mind....

that is..... if you dont mind.....
relaying1x4.png
relaying1x4.png (252.19 KiB) Viewed 1467 times
most relay modules will turn on if you ground their signal pins and will turn off if you provide 5v

the single relay may be replaced by a non-inverting transistor array (like the TBD62783APG) if you like to lessen the bulk
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

Return to “General discussion”