no signal going to relays

Tlcinc

New member
I am using an Arduino Mega with 6 eight channel relay boards =48 channels for my Vixen program.
21 channels are not getting a signal to the relays.
What could be causing this? A bad Arduino board? thanks!:biggrin::biggrin::biggrin::biggrin::biggrin::biggrin::biggrin::biggrin:
 
Last edited by a moderator:
Can you activate/deactivate your relays with normal code, i.e. before trying to integrate the Vixen data? Can you share your sketch? Assume you are using the USB connection for your channel data? If you're following one of the examples on YouTube, there is an issue with the start channel configuration relating to leading zeros. You'll find info on that on a few posts on here.
 
#define MEGA_VIXEN
//#define UNO_VIXEN

#ifdef MEGA_VIXEN
#define MAX_CHANNELS 48
int channels[MAX_CHANNELS] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,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

#define POWER_UP_STATE 0 //0 = Lights off at power up, 255 = lights on at power up
#define INACTIVITY_STATE 255 //0 = Lights off when inactive, 255 = lights on when inactive

#define INACTIVITY_TIMEOUT_MILLISECONDS (20UL * 1000UL) // 20 = 20 seconds, 1000 = 1000 milliseconds in a second

int incomingByte[MAX_CHANNELS];

unsigned long inactivityTimer;

void setup()
{
int i;

Serial.begin(9600); // set up Serial at 9600 bps

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

inactivityTimer = millis();
}

void loop()
{
int i;

if (Serial.available() >= MAX_CHANNELS)
{
for (i=0; i < MAX_CHANNELS; i ++) incomingByte = Serial.read();
inactivityTimer = millis();
}

if ( (millis() - inactivityTimer) >= INACTIVITY_TIMEOUT_MILLISECONDS )
{
for ( i = 0; i < MAX_CHANNELS; i ++ ) incomingByte = INACTIVITY_STATE;
}

for (i = 0; i < MAX_CHANNELS; i ++ ) analogWrite(channels, incomingByte);
}
 
I've only been at this for 2 season now so I'm still learning. What is the solution to my problem?
 
There are other problems with your code too - I would recommend some better detection of the 'start' of the frame of byte data. You need a more robust mechanism to ensure the bytes coming on over serial are ending up in the right output channels. The recommended approach is to use a 'header' in the serial data, have a look at this example video... it's for pixels but the same concepts apply. Your use case is actually much simpler
https://youtu.be/oY6IoPM-sF

Also note the comment on YouTube from me about the header configuration which is wrong in this video vs the associated code.

This nasty code is all over the Internet in various forums with the same problems repeated. That's the danger of blindly copying something without understanding what it's actually doing. My suggestion - break this down into simple steps, read the arduino online docs and try some of the examples to understand the basics.
 
Last edited:
There are other problems with your code too - I would recommend some better detection of the 'start' of the frame of byte data. You need a more robust mechanism to ensure the bytes coming on over serial are ending up in the right output channels. The recommended approach is to use a 'header' in the serial data, have a look at this example video... it's for pixels but the same concepts apply. Your use case is actually much simpler
https://youtu.be/oY6IoPM-sF

Also note the comment on YouTube from me about the header configuration which is wrong in this video vs the associated code.

This nasty code is all over the Internet in various forums with the same problems repeated. That's the danger of blindly copying something without understanding what it's actually doing. My suggestion - break this down into simple steps, read the arduino online docs and try some of the examples to understand the basics.

The youtube video is no longer available. I got my code from this forum. http://doityourselfchristmas.com/for...duinos/page2
 
Thanks to everyone that helped! The problem was a bad Arduino board. That's one problem fixed but now.....I have changed to SSA relays but the ON / OFF was reversed. I now have that fixed but now the relays shut down after the first sequence of the show. I thought I read something about that on here but now I can't find it. Here is my CODE:

#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

#define POWER_UP_STATE LOW //0 = Lights off at power up, 255 = lights on at power up
#define INACTIVITY_STATE HIGH //0 = Lights off when inactive, 255 = lights on when inactive

#define INACTIVITY_TIMEOUT_MILLISECONDS (20UL * 1000UL) // 20 = 20 seconds, 1000 = 1000 milliseconds in a second

int incomingByte[MAX_CHANNELS];

unsigned long inactivityTimer;

void setup()
{
int i;

Serial.begin(9600); // set up Serial at 9600 bps

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

inactivityTimer = millis();
}

void loop()
{
int i;

if (Serial.available() >= MAX_CHANNELS)
{
for (i=0; i < MAX_CHANNELS; i ++) incomingByte = Serial.read();
inactivityTimer = millis();
}

if ( (millis() - inactivityTimer) >= INACTIVITY_TIMEOUT_MILLISECONDS )
{
for ( i = 0; i < MAX_CHANNELS; i ++ ) incomingByte = INACTIVITY_STATE;
}

for (i = 0; i < MAX_CHANNELS; i ++ ) digitalWrite(channels, ~incomingByte);
}
 
@Tlcinc

Below is the code that I am using currently, have been using this for many years and its the main code used by many on here. I'm not sure where you got your base from but this is based on the original Zparticle from years ago. Adaptions of this can be found all over the site. This is 36 channels SSR, and I have also modified it to have a Random and Twinkle mode when serial isn't plugged in so it can be stand alone also.

By the way, what are you using to send the data to the Arduino and what software are you using? (Vixen or xLights)

I suggest trying out a whole new setup if you continue having issues, I can also sent close ups of my Arduino setup if needed.

Code:
// This code was written by Victor Perez for doityourselfchristmas.com based on the code from Zparticle, Si_champion and Neil Tapp.
 // To adapt the code to your case, just change this top section, with the #define lines.
 
 // Includes the watchdog timer library
 #include <avr/wdt.h>
 
 // This sets how many channels will vixen be sending. Can be set to any number from 1 to 48 for Arduino Mega, and 1 to 18 for Arduino Uno.
 #define CHANNEL_COUNT 36

 // speed for the com port for talking with vixen. From 9600 to 115200. Use the same speed as set in Vixen.
 #define VIXEN_COM_SPEED 57600
 
 // Timeout waiting for serial input before going to random mode (in milliseconds).
 #define TIME_OUT 100
 #define MODE_2_SPEED 500
 
 // If the relays turn On and Off opposite to Vixen sequence, change "#define MODE NOT_INVERTED" for "#define MODE INVERTED"
 #define NOT_INVERTED 1
 #define INVERTED 0
 //Change Below
 #define MODE NOT_INVERTED
 
 
 //Switch Mode
 #define mode_switch1 7  //GND for ALL ON
 #define mode_switch2 8  //GND for slow random
 
 // which pins control which channels
 // You can change these assignment to use different pins, but be very careful to not repeat the same pin number for 2 channels. 
 // DO NOT use pings 0 and 1, as those are for the serial port to talk to the computer.
 #define CH01 22
 #define CH02 23
 #define CH03 24
 #define CH04 25
 #define CH05 26
 #define CH06 27
 #define CH07 28
 #define CH08 29
 #define CH09 30
 #define CH10 31
 #define CH11 32
 #define CH12 33
 #define CH13 34
 #define CH14 35
 #define CH15 36
 #define CH16 37
 #define CH17 38
 #define CH18 39
 #define CH19 40
 #define CH20 41
 #define CH21 42
 #define CH22 43
 #define CH23 44
 #define CH24 45
 #define CH25 46
 #define CH26 47
 #define CH27 48
 #define CH28 49
 #define CH29 50
 #define CH30 51
 #define CH31 52
 #define CH32 53
 #define CH33 02
 #define CH34 03
 #define CH35 04
 #define CH36 05


 
 int channels[] = {CH01,CH02,CH03,CH04,CH05 ,CH06,CH07,CH08,CH09,
 CH10,CH11,CH12,CH13,CH14,CH15,CH16,CH17,CH18,CH19,CH20,CH21,CH22,
 CH23,CH24,CH25,CH26,CH27,CH28,CH29,CH30,CH31,CH32,CH33,CH34,CH35,CH36};

 int incomingByte[CHANNEL_COUNT];

int i = 0;     // Loop counter
volatile unsigned long  timer_a = 0; // new line

//setup the pins/ inputs & outputs




void setup(){






  // enable the watchdog timer with a time of 1 second. If the board freezes, it will reset itself after 1 second.
  wdt_enable(WDTO_1S);
  
  // specifically for the UNO
  sei();  

// initalize PWM Channels / Pins
pinMode(mode_switch1, INPUT_PULLUP);  // Connect Pin7 to GROUND for All on, Open for Flicker.
 for (i=0; i < CHANNEL_COUNT; i++){
    pinMode(channels[i], OUTPUT);
  }

pinMode(mode_switch2, INPUT_PULLUP);  // Connect Pin8 to GROUND for Mode 1, Open for Flicker.
 for (i=0; i < CHANNEL_COUNT; i++){
    pinMode(channels[i], OUTPUT);
  }



// set all the realys to off to start with
if (MODE == NOT_INVERTED) {
 for (i=0; i < CHANNEL_COUNT; i++){
     digitalWrite(channels[i], LOW);

 }
}

else {
 for (i=0; i < CHANNEL_COUNT; i++){
     digitalWrite(channels[i], HIGH);
 }
}

 testSequence();
 
// set up Serial according to the speed defined above.
  Serial3.begin(VIXEN_COM_SPEED);
}

void loop()


{
   if (Serial3.available() >= (CHANNEL_COUNT+20)) {
     wdt_reset(); // resets the watchdog
     timer_a = millis (); // new line
     int uno = Serial3.read();
     if (uno == 126){
       
       int dos = Serial3.read();
       if (dos == 33){          
   
         for (i=0; i < CHANNEL_COUNT; i++) {
             // read each byte
          incomingByte[i] = Serial3.read();
         }
		 if (MODE == NOT_INVERTED) {
			for (i=0; i < CHANNEL_COUNT; i++){
			int value = incomingByte[i];
			if (value <= 127) {
				digitalWrite(channels[i], LOW);
			}
			else {
				digitalWrite(channels[i], HIGH);
			}
			}
		 }
		 else {
		 for (i=0; i < CHANNEL_COUNT; i++){
			int value = incomingByte[i];
			if (value < 127) {
				digitalWrite(channels[i], HIGH);
			}
			else {
				digitalWrite(channels[i], LOW);
			}
			}
		 }

       }
     }
   }
// Random mode code. Random mode starts if no serial input has been received in TIME_OUT millisenconds
   else {
     wdt_reset(); // resets the watchdog
// If the switch is connected to ground, keep all the lights on when Vixen is not running.

///move twinkle here
	 if (digitalRead (mode_switch1) == LOW) {
                
//MODE 1 - TWINKLE   1-24             
                
         unsigned long diff = millis() - timer_a;
           if (diff >= TIME_OUT) {
             timer_a = millis ();
             int random_a = 0;
             for (i=0; i < CHANNEL_COUNT; i++){
               random_a = random(0, 20);  //(MIN, MAX) sets the odds of hitting 0 to turn channel off
                 if (random_a == 0) {
                 digitalWrite(channels[i], LOW);
                 } else {
                 digitalWrite(channels[i], HIGH);
                 }
             }
             
             for (i=24; i < 36; i++){  //start at channel 24 and turn on remander up to 36
                 digitalWrite(channels[i], HIGH);
                 
             }
             
           }
                
                
                

	} else if (digitalRead (mode_switch2) == LOW){
  
//MODE2 SLOW RANDOM 1-24


          unsigned long diff = millis() - timer_a;
           if (diff >= MODE_2_SPEED) {
             timer_a = millis ();
             int random_a = 0;
             for (i=0; i < 24; i++){  //set to max out at channel 24 not 36 (CHANNEL _COUNT)
               random_a = random(0, 2);  //(MIN, MAX) sets the odds of hitting 0 to turn channel off
                 if (random_a == 0) {
                 digitalWrite(channels[i], LOW);
                 } else {
                 digitalWrite(channels[i], HIGH);
                 }
             }
             
             for (i=24; i < 36; i++){  //start at channel 24 and turn on remander up to 36
                 digitalWrite(channels[i], HIGH);
                 
             }
           }
  
//FLICKER  
        } else {    // ALL ON
    
           
           
                           unsigned long diff = millis() - timer_a;
                if (diff >= TIME_OUT) {
                timer_a = millis ();
		if (MODE == NOT_INVERTED) {
			for (i=0; i < CHANNEL_COUNT; i++){
				wdt_reset(); // resets the watchdog
				digitalWrite(channels[i], HIGH);
			}
		} else {
			for (i=0; i < CHANNEL_COUNT; i++){
				wdt_reset(); // resets the watchdog
				digitalWrite(channels[i], LOW);
			}
		}
                }      
           
           
           
           
        }  
   }
}


void testSequence(){

if (MODE == NOT_INVERTED) {
 for (i=0; i < CHANNEL_COUNT; i++){
   wdt_reset(); // resets the watchdog
   digitalWrite(channels[i], HIGH);
   delay (250);
   digitalWrite(channels[i], LOW);
 }
}

else {
 for (i=0; i < CHANNEL_COUNT; i++){
   wdt_reset(); // resets the watchdog
   digitalWrite(channels[i], LOW);
   delay (500);
   digitalWrite(channels[i], HIGH);
   }
 }
}
 
Last edited:
Question last year I ran a arduino mega on vixen running 32 relays ran great now I use xlights and how do I use the arduino in xlights to run the relays

Sent from my SM-N975U using Tapatalk
 
I tried that looks very different than vixen
And doesn't the arduino code need to be different?

Sent from my SM-N975U using Tapatalk
 
Back
Top