christmas lights

I have a 2560 mega, hooked up to and 8 channel relay board from pins 2-9, just using regular light and trying to use Vixen lights, problem I have is that I can only get five of my strings to light at the same time. I not sure if this is something within the code(extreme NOOB to coding). all lights do work separately but can only get 5 at one time.

this is the code im using. kind of copied it from someones else post, seems to work ok, but I only have 8 channels.
(Code tags added by Moderator)

#define MEGA_VIXEN
//#define UNO_VIXEN

#ifdef MEGA_VIXEN
 #define MAX_CHANNELS 52
 int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53};
#endif

#ifdef UNO_VIXEN
 #define MAX_CHANNELS 18
 int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A4,A5};
#endif

int incomingByte[MAX_CHANNELS];

void setup()
{
 int i;
 
 Serial.begin(9600); // set up Serial at 9600 bps

 for ( i = 0; i < MAX_CHANNELS; i ++ )  pinMode(channels[i], OUTPUT);
}

void loop()
{
 int i;
 
 if (Serial.available() >= MAX_CHANNELS)
 {
   for (i=0; i < MAX_CHANNELS; i ++)      incomingByte[i] = Serial.read();
 }

 for (i = 0; i < MAX_CHANNELS; i ++ )    analogWrite(channels[i], incomingByte[i]);
}

Last edited by jetty; 12-18-2014 at 09:24 PM. Reason:

You are failing to understand how arrays work.

  for ( i = 0; i < MAX_CHANNELS; i ++ )  pinMode(channels, OUTPUT);

Should be

  for ( i = 0; i < MAX_CHANNELS; i ++ )  pinMode(channels[i], OUTPUT);

Similarly you should specify the index every time you specify a pin.

You can not d an analogWrite to any pins bit the A0 to A5 pins that is pin 14 to 19.
You also loose all the serial data because you keep overriding the values you read.
That code never works for 5 relays, don't tell porkeys.

Please read the how to use this forum sticky post to see how to post code correctly here.

[/c#define MEGA_VIXEN
//#define UNO_VIXEN

#ifdef MEGA_VIXEN
  #define MAX_CHANNELS 52
  int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53};
#endif

#ifdef UNO_VIXEN
  #define MAX_CHANNELS 18
  int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A4,A5};
#endif

int incomingByte[MAX_CHANNELS];

void setup()
{
  int i;
  
  Serial.begin(9600); // set up Serial at 9600 bps

  for ( i = 0; i < MAX_CHANNELS; i ++ )  pinMode(channels, OUTPUT);
}

void loop()
{
  int i;
  
  if (Serial.available() >= MAX_CHANNELS)
  {
    for (i=0; i < MAX_CHANNELS; i ++)      incomingByte = Serial.read();
  }

  for (i = 0; i < MAX_CHANNELS; i ++ )    analogWrite(channels, incomingByte);
}
 
[code]

ode]

Grumpy Mike, is the rest of the code ok, I am extremely new to this, thanks for the heads on on posting code. andf im not sure what you are referring to in your last sentence

I am only using the pins 2-9 pwm as I only have 8 relays and 8 outlets to control via Vixen

You shouldn't do PWM to relays, besides making a lot of noise they'll chatter themselves to death in not much time.
PWM is 500 or 1000 changes/second, relays might be rated for 1,000,000 contact closure, so after 2000 seconds they start going bad. That's 33 minutes.

the relays are not making any noise at all at the moment. again they do work and might strings of lights come on separately, just cant get more than 5 to light at the same time. I have a Solid state relay board, not sure if that makes a difference. I can switch the pins to the digital outputs if need be. but again the relays are not making any noise at all.

//c#define MEGA_VIXEN
//#define UNO_VIXEN

#ifdef MEGA_VIXEN
  #define MAX_CHANNELS 52
  int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53};
#endif

#ifdef UNO_VIXEN
  #define MAX_CHANNELS 18
  int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A4,A5};
#endif

int incomingByte[MAX_CHANNELS];

void setup()
{
  int i;
  
  Serial.begin(9600); // set up Serial at 9600 bps

  for ( i = 0; i < MAX_CHANNELS; i ++ )  pinMode(channels[i], OUTPUT); // change made here
}

void loop()
{
  int i;
  
  if (Serial.available() >= MAX_CHANNELS) // waiting for 52 bytes to come - do you send that many with the Mega?
  {
    for (i=0; i < MAX_CHANNELS; i ++)      incomingByte[i] = Serial.read(); // need an array here to hold the date
  }

  for (i = 0; i < MAX_CHANNELS; i ++ )    analogWrite(channels[i], incomingByte[i]); // need arrays here - except there are only 15 or 16 PWM channels on a Mega, not 52.
// if the data from incomingByte[i] is < 128, a non-PWM channel gets a 0, otherwise a 1 I think.
}
[/code]

Here's an example of what you can expect to hear with normal mechanical relays, this is one of the three types of 8-channel relay cards I offer:
http://www.crossroadsfencing.com/BobuinoRev17/


Youtube video showing the Uno shield version with 8 strings of 120V LED lights. A Mega version lays next to it.

im not sure what kind of relay board I have but I know that it makes no clicking noise at all, the board is a SS realy board not sure if that's why. but im going to try the changes you made to the code and hopefully that will make the difference. I will take the max channels down to the 8 that im using as well. will let you know how it works out

I hadn't come across a multichannel solid state relay board before, I suppose that would be quiet while switching.
The code fixes should help.

What is marked on your Relays?

will reply when I get home to look at them

8-Channel 250V 2A Solid State SSR Relay Module with Fuse for Arduino

• 5V Solid State Relays Per Channel 240V 2A, Output with Resistive Fuse 240V 2A
• Size: 128 * 61 * 24 (L * W * H)
• The input power supply: 5V DC (160MA)
• The input control signal voltage: 0-0.5V LOW state relay OFF, 2.5-20V high state relays ON
• Rated output load: 2A at 100 to 240VAC.(50/60Hz

this is the exact one I bought

https://www.amazon.com/gp/product/B00SGHM3GI/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1

I am only using the pins 2-9 pwm

You might be but the Arduino can not. Depending on what sort of Arduino you have only some are capable of producing PWM output.

On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11.

From analogWrite() - Arduino Reference

And PWM is described here http://www.thebox.myzen.co.uk/Tutorial/PWM.html

thank you for both the tutorial and article both were enlightening, but I have one last question. I am using pins 2-9, which on the mega are PWM, and if you look at my code I am using analogwrite, so my question is can I use those same pins and, instead, use digitalwrite and get the effect of just on and off or will I have to use pins that are not PWM.
thanks for all your help.

signed NOOOOOOB

can I use those same pins and, instead, use digitalwrite and get the effect of just on and off

Yes, those pins work as a normal digital input / output in addition to having PWM capabilities.

I was reading about the pins and digitalwrite, its amazing how much you can learn if you just do a little reading. guess im going to spend a lot of time on the tutorials and learning to write the codes for them properly. but im going to try and change the part of my code that says analogwrite to digitalwrite and see what happens.