4

I want to control multiple relays in my house using the raspberry pi.

How manny relays can I control using it ?

8

You can buy add-on boards with up to 8 relays. Example 1. Example 2.

There are also some with 16 relays. Example 1 Example 2 Example 3

The Pi's GPIO header has 17 GPIO pins, some of these are allocated to other purposes but I believe you can free them up in software for uses as GPIO pins that can control relays.

All the GPIO pins can be reconfigured to provide alternate functions, SPI, PWM, I²C and so. At reset only pins GPIO 14 & 15 are assigned to the alternate function UART, these two can be switched back to GPIO to provide a total of 17 GPIO pins[3]. Each of their functions and full details of how to access are detailed in the chipset datasheet

If you need more IO ports, you can use one or several I²C port expanders. Example

Note that revision 2 Pis have unpopulated "P5" headers for four additional GPIO ports.

enter image description here

Additional I/O Expansion

To utilise GPIO signals released by the removal of the version identification links, a new connector site P5 has been added. This carries the four GPIO signals [BCM2835/GPIO28 – BCM2835/GPIO31] named GPIO7 – GPIO10 respectively, along with +5V0, +3V3 and two 0V. Currently this connector is not populated.

This GPIO allocation provides access to one of:

  • SDA0, SCL0 (Operating independently of P1 SDA1, SCL1); or
  • PCM_CLK, PCM_FS, PCM_DIN, PCM_DOUT or I2S; or
  • Four GPIO signals.

This connector is intended to be a suitable attachment point for third-party clock and audio codec boards, and is pinned to be mounted (ideally) on the underside due to connector clash. Pin 1 is marked with the square pad (top left – looking from the top).

| improve this answer | |
6

You want to research a "shift register", such as the 74HC595 which I've also recently used to control some relays.

A shift register lets you take some serial data - 8 bits from the RPi - and translate it to parallel data - the 8 output pins on the shift register. You can use each of those 8 output pins to control a relay, while you only need 3 pins on the RPi to control the shift register.

The 74HC595 like many others is a 'cascading' shift register. This means when you write a bit in, the oldest bit is 'shifted off' to a special output pin. Connect this output pin to another shift register's input, and your data can 'cascade' down to the second chip. You can chain them like this basically infinitely; for two chips you'd just write out 16 bits, for 3 chips 24, and so on ad infinitum.

The end result is multiplying the 3 control pins on the RPi to as many relays as you wish, depending only on how many shift registers you can connect together.

Here's a pretty good guide from Adafruit; while it's geared at the Arduino, the ideas and methods of control are still the same:

http://learn.adafruit.com/adafruit-arduino-lesson-4-eight-leds/the-74hc595-shift-register

| improve this answer | |
1

I remember a project I did many years ago whilst studying for my degree. It was a VME bus relay controller for a bed of nails PCB tester. It had to control hundreds of relays. In the end I used relay controllers that had serial in and serial out controls and daisy chained them together and then used PLCs and FPGAs to cycle the serial data and modify the required relay state.

So, on a RPi you can use a four pin approach: Serial In, Serial Out, Clock and Select and control it as follows:-

for (i = 0 to number_of_relays)
{
  read serial in
  if relay requires setting
    write new state to serial out
  else
    write old state to serial out

  toggle clock line
}

toggle select to latch the relay states

You can then control as many relays as you want. Of course, the more relays, the longer it takes to update the states. You can split them into equal size groups and have several pairs of serial in and out. If you simplify it, you could get rid of the serial in and just set all the relay states each update. This would double the number of relay groups you can control.

| improve this answer | |
0

This is an interesting question. The RPi itself has 8 GPIO pins according to wikipedia. Assuming you could use all 8 pins as outputs it is theoretically possible to control 256 devices (i.e. 2^8). Each number, that is 000 to 255 could be fed into a separate circuit, like an Arduino or PIC which then turns something on or off. Neat idea, I can certainly see some fun in a little project like this.

| improve this answer | |
0

You can add up to 64 relays WITHOUT USING ANY OF THE GPIO PINS on the interface. Check THIS LINK

| improve this answer | |
-3

if you make a gpio extender hat you can add more . its simple and pluges onto the i2s and you can get 18 extra gpio pins

| improve this answer | |
  • 1
    Welcome to the site. While this does address the question, it lacks enough detail to be a complete answer - how would one make a gpio extender hat exactly? You can find some information on how best to approach answering in the tour and the help centre. – goobering Mar 30 '17 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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