Christian
Published © GPL3+

256 Relays!

Control 256 relays! Seeing is believing!

BeginnerProtip1 hour12,955

Things used in this project

Hardware components

IO Expander
×1
Relay Expander
×16
Arduino Nano R3
Arduino Nano R3
×1
12V x16 Relays
×16

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

256 Relays Diagram

Code

Control 256 Relays

Arduino
/* IO Expander
 *  
 * 256 Relays
 *
 */

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

//#define SERIAL_DEBUG
#define MAX_RELAYS    256

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

char cmd[10];

void setup()
{
  Serial.begin(115200);
#ifdef SERIAL_DEBUG
  swSerial.begin(115200);
  swSerialEcho = &swSerial;
#endif  
  wdt_enable(WDTO_8S);
  sprintf(cmd, "eb%d", MAX_RELAYS / 16);
  SerialCmdDone(cmd);
}

void loop()
{
  uint8_t i;
  static uint8_t s = 1;
  static uint8_t d = 0;
  uint8_t r[32];

  for (i = 0; i < 32; i++) {
    r[i] = ~s;
  }

  SerialWriteRelayExpander(r, 32);
  delay(50);

  if (d) {
    if (s > 1) s >>= 1;
    else d = 0;
  }
  else {
    if (s < 0x80) s <<= 1;
    else d = 1;
  }

  wdt_reset();
}

Credits

Christian

Christian

7 projects • 59 followers

Comments