Re: Christmas Lights Control System -Arduino Mega - 16 Channel Relay Board

I think I need some help I am new at this. I have an arduino and 4 , 16 channel relays I have a code to run them all but I am having trouble getting my Vixen to run on it. I had it going good earlier and now I lost it. can any one help. here is the code I am using

#define CHAN01  22
#define CHAN02  23
#define CHAN03  24
#define CHAN04  25
#define CHAN05  26
#define CHAN06  27
#define CHAN07  28
#define CHAN08  29
#define CHAN09  30
#define CHAN10  31
#define CHAN11  32
#define CHAN12  33
#define CHAN13  34
#define CHAN14  35
#define CHAN15  36
#define CHAN16  37
#define CHAN17  38
#define CHAN18  39
#define CHAN19  40
#define CHAN20  41
#define CHAN21  42
#define CHAN22  43
#define CHAN23  44
#define CHAN24  45
#define CHAN25  46
#define CHAN26  47
#define CHAN27  48
#define CHAN28  49
#define CHAN29  50
#define CHAN30  51
#define CHAN31  52
#define CHAN32  53
#define CHAN33  02
#define CHAN34  03
#define CHAN35  04
#define CHAN36  05
#define CHAN37  06
#define CHAN38  07                
#define CHAN39  10
#define CHAN40  11
#define CHAN41  12
#define CHAN42  13
#define CHAN43  14
#define CHAN44  15
#define CHAN45  16
#define CHAN46  17
#define CHAN47  18
#define CHAN48  19
#define CHAN49  20
#define CHAN50  21
#define CHAN51  A0
#define CHAN52  A1
#define CHAN53  A2
#define CHAN54  A3
#define CHAN55  A4
#define CHAN56  A5
#define CHAN57  A6
#define CHAN58  A7
#define CHAN59  A8
#define CHAN60  A9
#define CHAN61  A10
#define CHAN62  A11
#define CHAN63  A12
#define CHAN64  A13

int channels[] = {CHAN01,CHAN02,CHAN03,CHAN04,CHAN05,CHAN06,CHAN07,CHAN08,CHAN09,

// Total Channel Count
#define CHANNEL_COUNT 64

// Serial Speed
#define PC_COM_SPEED 9600

int i = 0;
int incomingByte[CHANNEL_COUNT];

void setup()

  // Set the channel pins to output mode
  for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){

void loop()
  if (Serial.available() >= CHANNEL_COUNT)
    for (int i=0; i<CHANNEL_COUNT; i++)
      incomingByte[i] =;
    digitalWrite(CHAN01, incomingByte[0]);  
    digitalWrite(CHAN02, incomingByte[1]); 
    digitalWrite(CHAN03, incomingByte[2]);  
    digitalWrite(CHAN04, incomingByte[3]); 
    digitalWrite(CHAN05, incomingByte[4]);  
    digitalWrite(CHAN06, incomingByte[5]);  
    digitalWrite(CHAN07, incomingByte[6]);  
    digitalWrite(CHAN08, incomingByte[7]);  
    digitalWrite(CHAN09, incomingByte[8]); 
    digitalWrite(CHAN10, incomingByte[9]);  
    digitalWrite(CHAN11, incomingByte[10]); 
    digitalWrite(CHAN12, incomingByte[11]); 
    digitalWrite(CHAN13, incomingByte[12]); 
    digitalWrite(CHAN14, incomingByte[13]); 
    digitalWrite(CHAN15, incomingByte[14]); 
    digitalWrite(CHAN16, incomingByte[15]);  
    digitalWrite(CHAN17, incomingByte[16]);  
    digitalWrite(CHAN18, incomingByte[17]);  
    digitalWrite(CHAN19, incomingByte[18]);  
    digitalWrite(CHAN20, incomingByte[19]);  
    digitalWrite(CHAN21, incomingByte[20]);  
    digitalWrite(CHAN22, incomingByte[21]);  
    digitalWrite(CHAN23, incomingByte[22]);  
    digitalWrite(CHAN24, incomingByte[23]);  
    digitalWrite(CHAN25, incomingByte[24]);  
    digitalWrite(CHAN26, incomingByte[25]); 
    digitalWrite(CHAN27, incomingByte[26]); 
    digitalWrite(CHAN28, incomingByte[27]); 
    digitalWrite(CHAN29, incomingByte[28]); 
    digitalWrite(CHAN30, incomingByte[29]); 
    digitalWrite(CHAN31, incomingByte[30]);  
    digitalWrite(CHAN32, incomingByte[31]); 
    digitalWrite(CHAN33, incomingByte[32]);
    digitalWrite(CHAN34, incomingByte[33]);
    digitalWrite(CHAN35, incomingByte[34]);
    digitalWrite(CHAN36, incomingByte[35]);
    digitalWrite(CHAN37, incomingByte[36]);
    digitalWrite(CHAN38, incomingByte[37]);
    digitalWrite(CHAN39, incomingByte[38]);
    digitalWrite(CHAN40, incomingByte[39]);
    digitalWrite(CHAN41, incomingByte[40]);
    digitalWrite(CHAN42, incomingByte[41]);
    digitalWrite(CHAN43, incomingByte[42]);         
    digitalWrite(CHAN44, incomingByte[43]);
    digitalWrite(CHAN45, incomingByte[44]);
    digitalWrite(CHAN46, incomingByte[45]);
    digitalWrite(CHAN47, incomingByte[46]);
    digitalWrite(CHAN48, incomingByte[47]);
    digitalWrite(CHAN49, incomingByte[48]);
    digitalWrite(CHAN50, incomingByte[49]);
    digitalWrite(CHAN51, incomingByte[50]);
    digitalWrite(CHAN52, incomingByte[51]);
    digitalWrite(CHAN53, incomingByte[52]);
    digitalWrite(CHAN54, incomingByte[53]);
    digitalWrite(CHAN55, incomingByte[54]);
    digitalWrite(CHAN56, incomingByte[55]);
    digitalWrite(CHAN57, incomingByte[56]);
    digitalWrite(CHAN58, incomingByte[57]);
    digitalWrite(CHAN59, incomingByte[58]);
    digitalWrite(CHAN60, incomingByte[59]);
    digitalWrite(CHAN61, incomingByte[60]);
    digitalWrite(CHAN62, incomingByte[61]);
    digitalWrite(CHAN63, incomingByte[62]);
    digitalWrite(CHAN64, incomingByte[63]);

void powerOnSelfTest()
    Serial.println("Power on self test running.");
    for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
      Serial.print("Channel: ");
      analogWrite(channels[channelIndex], 255); // Turn On relays one channel at a time
      delay(100); // Wait .1 seconds
      analogWrite(channels[channelIndex], 0);

void turnAllLightsOn()
  // Turn all Channels ON
  for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
    analogWrite(channels[channelIndex], 0);

void turnAllLightsOff()
  // Turn all Channels OFF
  for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
    analogWrite(channels[channelIndex], 255);

Moderator edit: Code tags. Why is it always code tags?

You only have 54 general purpose IO pins. Some of them are exclusively digital. Some are digital or analog. But, there are only 54 total. You appear to be using some pins twice.

  if (Serial.available() >= CHANNEL_COUNT)

Since the buffer is at most 64 bytes, waiting until there are 64 bytes or more to start reading is a big mistake.

An array of pin numbers would eliminate the need for so much code.
An array of pin numbers would eliminate the need for so much code.
An array of pin numbers would eliminate the need for so much code.
An array of pin numbers would eliminate the need for so much code.
An array of pin numbers would eliminate the need for so much code.
An array of pin numbers would eliminate the need for so much code.