I am trying to control 42 relays with a Raspberry Pi 3 B+. Due hardware limitations, there I cannot do that with the current amount of GPIO pins. I've found some GPIO Expansion Boards online, but I was wondering if they're a good option or if there is any other way to achieve this.

closed as unclear what you're asking by Milliways, Dmitry Grigoryev, joan, Ingo, Darth Vader Aug 27 '18 at 10:36

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I am writing an answer below assuming that I/O expander is based on chips that give you more digital I/O pins. It would have been nice if you had explained and included pictures of the I/O expansion boards you were thinking of. – NomadMaker Aug 1 '18 at 22:40
  • I'm dying of curiosity. What on earth needs 42 relays! Please please share! :D – OyaMist Aug 2 '18 at 16:33
  • Related: shift registers or port expanders... – Ghanima Aug 2 '18 at 19:52

I/O expander chips are usually based on shift registers or an external microcontroller. In both cases, the time it takes to communicate with the board increases the time required to write the data. This may not matter much to a relay.


  • You can control a lot of relays.


  • You may have to learn to access these chips with the I2C or SPI interfaces.
  • You will have to figure out a way of isolating the voltage needed to control the relay from the Rapberry Pi. Relays produce quick voltage spikes which are not good for electronics.
  • You will require a power solution to power the relays because I don't think that you can expect a Raspberry Pi to directly power that many relays.

From the above, I'm assuming that you will be creating or buying a board that runs relays. Either this board will have 42 relays on it, or you will have separate boards with perhaps 8 relays on them which are triggered via I2C and have assignable addresses so you can talk to all 6 boards vi I2C.

I just found a stackable relay HAT that has 8 relays and you can stack for a maximum of 64 relays! These two products might do what you want. It's a Kickstarter that is supposed to deliver in September. There is an article about it.

PiFace also has a stackable relay board.

  • Use I2C because both hardware ( expansion boards / modules) and software are relatively easy and common. And addressing I2C devices is well defined too. Be aware that there are more than one "wire" library. SPI is a different story. The advantage of SPI is bidirectional communication but there are very few true bidirectional SPI devices. But you probably do not need bidirectional communication anyway. Make sure your relay modules have "shunt diodes" - some modules come without them! – Jan Hus Aug 2 '18 at 1:55
  • Add yes those relay boards with 8 blue plastic relays NEED very stiff 5V minimum 2 A supply per EACH board! – Jan Hus Aug 2 '18 at 2:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.