Zeven Development

Control Up To 65,280 Relays with your Arduino!

Use the IO Expander and Relay Expander to control up to 65,280 Relays.


Need to add alot of relays to your project? Then you need the IO Expander with Relay Expanders.  Each IO Expander can control up to 16 daisy chained Relay Expanders for a total of 256 relays. Then connecting 255 IO Expanders together you can selectively control up to 65,280 relays.

Control Relays with a Single IO Expander.

Final



Feature List

  • Use cheap < $15 Arduino 16 Relay Boards.
  • Easy to use Relay Control Commands.
  • Control an Individual Relay or a Bank at a Time.
  • No Driver Required. Save Code Space.
  • No Data Space to Maintain Relay State.
  • No Extra Power Supply Needed.

Parts needed to build a Relay Bank


Wiring Diagram

Wiring

Note: In the above wiring diagram the IO Expander and Arduino Nano are being powered by the first relay board. All the Relay Expanders are powered from the relay board they are connected to.


/* IO Expander
 *  
 * Control 64 Relays
 *
 */


#include <SoftwareSerial.h>
#include "IOExpander.h"
#include <avr/wdt.h>

#define SERIAL_DEBUG
#define MAX_RELAYS    64

#ifdef SERIAL_DEBUG
SoftwareSerial swSerial(8,7);
#endif

bool ioexpander;
char cmd[10];

void setup()
{
  Serial.begin(115200);
#ifdef SERIAL_DEBUG
  swSerial.begin(115200);
  swSerialEcho = &swSerial;
#endif  
  wdt_enable(WDTO_8S);

  delay(1000);    // Delay 1 sec for IO Expander title
  while (Serial.available()) Serial.read(); // Flush RX buffer
  Serial.println();
  ioexpander = SerialReadUntilDone();
 
  sprintf(cmd, "eb%d", MAX_RELAYS / 16);
  SerialCmdDone(cmd);
}

void loop()
{
  static int i = 1;

  wdt_reset();
 
#ifdef SERIAL_DEBUG
  if (SerialDebugControl()) return;
#endif

  sprintf(cmd, "e%df", i);
  SerialCmdDone(cmd);
  delay(100);
 
  if (i++ >= MAX_RELAYS) i = 1;
  sprintf(cmd, "e%do", i);
  SerialCmdDone(cmd);
  delay(100);
}
 

Multiple IO Expanders Controlling Relays

Another way to control relays is to use multiple IO Expanders. This gives us the ability to distribute sensors and relays to a central, or star network, but still interconnect all the IO Expanders on a single serial bus. If you have to separate the IO Expanders up to 4000ft then use the IO Extenders as shown below with the standard blue Cat5 network wire.

Final



Wiring Diagram

Wiring

Note: In the above wiring diagram all the IO Expanders and Arduino Nano are being powered by the first relay board through the serial bus. All the Relay Expanders are powered from the relay board they are connected to.


/* IO Expander sketch optimized
 *  
 * Relay 9-bit with IO Expanders!
 *
 */


#include <HardwareSerial9Bit.h>
#include <SoftwareSerial.h>
#include "IOExpander9Bit.h"
#include <avr/wdt.h>

#define SERIAL_DEBUG
#define MAX_RELAYS    16

#define FROM_BOARD    1
#define TO_BOARD      4

#ifdef SERIAL_DEBUG
SoftwareSerial swSerial(8,7);
#endif

char cmd[128];

void setup()
{
  Serial9Bit.begin(115200, SERIAL_9N1);
#ifdef SERIAL_DEBUG
  swSerial.begin(115200);
  swSerialEcho = &swSerial;
#endif
  wdt_enable(WDTO_8S);
 
  swSerial.println("Reset");

  delay(100);                               // Wait 100 ms for IO Expander Title
  while (Serial9Bit.available()) Serial9Bit.read(); // Flush RX buffer
 
  Serial9Bit.write(0);                      // Set IO Expanders to 9-bit by sending zero
  delay(1);
 

  // Turn off all the relays on all the boards
  for (int board = FROM_BOARD; board <= TO_BOARD; board++) {
    SerialCmdDone(board, "esffff");         // Clear all the relays
  }
}

void loop()
{
  static int board = FROM_BOARD;
  static int relay = 1;

  wdt_reset();

#ifdef SERIAL_DEBUG
  if (SerialDebugControl(cmd, sizeof(cmd))) return;
#endif  

  if (board <= TO_BOARD) {
    sprintf(cmd, "e%do", relay);            // Turn on the relay
    SerialCmdDone(board, cmd);
 
    delay(100);                             // Delay, must be less than 8 sec or add a loop.
 
    sprintf(cmd, "e%df", relay);            // Turn off the relay
    SerialCmdDone(board, cmd);
 
    if (++relay > MAX_RELAYS) {             // Select the next relay
      relay = 1;
      if (++board > TO_BOARD)              // Select the next board
        board = FROM_BOARD;
    }
  }
}
 

So why do I need to control so many relays?

One such application is in Aquaponics or Hydroponics. Lot's of sensors and devices need to be automated down to each grow bed or individual plant. This requires extreme IO and the IO Expander delivers.

Aquaponics Devices

So get your IO Expander today and build your system!