Home Brew Lighting System - Arduino Mega - SainSmart 16 Channel Relay Board

zparticle

New member
Just thought I'd share my project that I recently completed.

YouTube play list for the project videos

The Arduino Code

Building one of those systems to control Christmas lights and sync them with music. The project uses an Arduino Mega 2560, a SainSmart 16-Channel 12V Relay Module and the Vixen software package. The arduino is pumped data from the Vixen software running on a PC via a serial connection. This data tells the Arduino which lights to turn on and off via the relay module. The relay module does this by turning power on and off to 16 separate 120V AC wall outlets.

As I suspected at the beginning of the project the relays don't function well with PWM to do dimming so for next year I'll be replacing them dimmer circuits. The system does work nicely though. This is something you can easily build in a few full time days. It took me a week of working a few hours every night.

I set up the system with two modes (links are to example videos): random and Vixen driven.
 
I'd also be interested to know if anyone knows if it is possible to replace the mechanical relays on the SainSmart board with equivalent solid state relays (non-zero crossing) and if so what would the part number be for the SSR?
 
I'd also be interested to know if anyone knows if it is possible to replace the mechanical relays on the SainSmart board with equivalent solid state relays (non-zero crossing) and if so what would the part number be for the SSR?

What is the trigger voltage for the relays you're using, and are you switching + or ground?
 
The relays on that board are:

SRD-12VDC-SL-C RELAY T73-12V SONGLE 12V Power Relay

So they need 12V to trigger the switch. I'm switching +120V.

Here is link with info on the relay

It sounds like you're sending +12vdc to the relay. As such, it's not only the wrong voltage (too high), but wrong polarity for most DIYC SSR designs. However, there are some solid state relays that can accept +12v as the control signal; some of them are probably zero-cross SSRs which means on/off only and no dimming, but there may also be some that are random-cross SSRs which you need for proper dimming, and some of them may accept a +12v control signal.

For example, I have some Crydom 40amp SSRs that work with a control trigger between 3.5-24vdc. They are zero cross only and I use them to power up my main power lines to the displays: when the PC boots up, the 5vdc line from a spare hard disk drive connector turns on the Crydom which then lets power through to the displays. At the end of the night when the PC shuts down, it cuts power to the Crydom and of course, the power to the displays, too.

You could check Mouser's online catalog and I'll bet you'll find something. But I'll tell you this at the get-go: they're not cheap.
 
Thanks, I'll have a look on Mouser. The other option I was thinking of was to just build out my own dimmer circuits and replace the relay board completely.
 
If you are contemplating a DIY version then you can look in the wiki regarding SSR like Fig 1 of http://computerchristmas.com/christmas/link-how_to/HowToId-7/How_to_build_a_triac_switching_unit_SSR

To expand the arduino ports you could go the '595 route and hang another 8 SSR circuits on each '595. I don't know the limit of how many '595 can be handled by the arduino and still do dimming.
This site has numerous similar projects that you can explore and integrate with your arduino. You may need to develop your own firmware to customize it for your particular hardware setup.
 
Great work Zparticle, I've followed all your videos and its cool to see you work through each stage, describe the problems you ran into etc.
I'm going to create a similar setup, I've got 2x 4 SSRs (Yugibot I think is written on the boards). I don't think I'll get it running before this Christmas but I've been sitting on it for a year already so no hurry :) I've got a friend making up the relay/power/arduino box, he has mad skills in doing this sort of thing so is working on that this weekend. I get the easy job of getting Vixen running and the code on the Arduino.

Question for you: Are you using the Generic Serial plugin in Vixen? I've tried previously with another tutorial from Tokyospace I think it was which used the Open DMX, which just would not work for me.

My box is going to have extension cords coming out of the relays (rather than the 4x4 plug boxes you used) which will hopefully allow me to use it in other things like a light tree (pole with lights coming down from the centre). I'm also thinking of using a photo resistor to control when the lights come on, so if I am not there, once it gets dark it starts up (hopefully). I like your idea of a vixen bypass which lets the lights run randomly, I may also try a 3rd step which is prebuild sequences (for example imagine lights in a circle and they could chase each other or something like that). Similar to random mode but not random and not a vixen sequence :) and a 4th bypass which is on all the time, not flashing.

Great work, thanks to your post (I originally saw it on ardiuno.cc) I've found an easy to follow plan and the inspiration I needed to get back into getting mine working (and convincing my friend to build the box for me :)
 
Cool, I'm glad you liked the videos and I hope they help you. I'm using the generic serial plugin to output the data from vixen. Also I should mention that I had no luck with the Vixen version that is the obvious link on the Vixen site I had to use the 2.5.0.8 version which can be found here http://www.vixenlights.com/releases/ .

I have a number of ideas for more features, like you do. But for this year I'm leaving it be, don't want to break it now that it works. :)
 
Certainly a big help, so thank you again.
Awesome, thanks for the tips, I'm pretty sure that was what was wrong originally (not using generic serial) but will work this weekend to get something basic running whilst I get the relay box built. I've been using Vixen 2.1 and had issues with songs not playing correct (like they are running at variable speeds, slowing down whilst playing back). I'll give 2.5 and 3.0 Beta ago as well.

Keep the topic updated with your changes if you can! I thinks the best example I can find of creating this and hopefully becomes a good source of tips, tricks and improvements!
 
Hi again, my friend has almost finished building my controller box and so far so good. We had a couple of minor hiccups but he managed to overcome them (we were initially running both a power supply for the relays and a wall power supplier for the arduino and the relays, whilst almost working, didn't like that, they weren't clicking). We are just doing a couple of switches to go from Vixen to Random mode and a 'on all the time' mode. Currently in Vixen mode the relays don't seem to be making the right noise, but we are looking into that (random mode is fine).

We now have the code uploaded and turning lights on and off which is awesome (thanks again!).

I've got a couple of questions regarding the code, just wondering if you could give some input there.
Firstly, whilst I have a Mega, I'm not using it, rather a Freakuino (which has built in wireless... :). Not sure if that has an impact on what I'm about to comment on but thought I would mentioned it.

So, using your latest code paste from Arduino.cc, you have used
Serial1.begin(VIXEN_COM_SPEED) (about line 50)

Which causes a compile error (Serial1). There are a couple of other references as well to Serial1. Should that just be Serial or have you used this for a reason and it needs tweaking to get working?

In the turnLightsOff() function (line 96) you have for(int channelIndex=0;channelIndex<16;channelIndex++){
Which I changed to for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
To keep it consistent with other for loops using Channel Count (might cause a hiccup if you had more than 16 channels..).

Thanks again
Scott
 
Looks like the Freakuino is an Arduino UNO copy. I'm using the Mega which has 4 UARTs so Serial, Serial1, Serial2 and Serial3. You only have one so change it to Serial instead of Serial1. Thanks for the note on the CHANNEL_COUNT in the loop, missed that one.

Glad you got it working. :)
 
I actually bought the exact same sain smart relay board when i was first looking into it, But after finding out it wouldn't dim i started looking for other boards, But if you find parts to convert it over that be amazing, as i have 2 16 channel and 2 8 channel
 
Thanks Zparticle, that makes perfect sense. If I select Mega for the board as well it compiles, so clearly its a difference between the boards.

Appreciate your help :) do let us know if you get the dimming working :)
 
This is my first year as well and I am using an Arduino Mega driving 2 x Sainsmart 8 SSR boards and 1 Sainsmart 8 Relay board for a total of 24 channels. I used the Generic Serial plug-in with a pretty simplistic code set on the 'duino. All is working well as long as I keep the sequence at 50ms time slices. Any less when switching 20 channels or more and the 'duino slips a channel. The only other thing I have run into is after about 10 hours of running, the USB port dies out on the Dell Mini laptop driving this. All I have to do is reset the port and all runs well again.
I do plan on switching over to a Renard system next year with a mix of 8's, 16's, and 24's as well as the Dirkcheaps driving other elements.
Year 1 - experiment... SUCCESS!!!
Year 2 - Going for broke
 
I am using an Arduino Mega driving 2 x Sainsmart 8 SSR boards and 1 Sainsmart 8 Relay board

I am a huge noob, and new to this forum, but I just got a MEGA 2560 and the SainSmart 8x SSR just to get a mini 8-channel version working. I have the duino code running an 8 led breadboard circuit, and sync'd to Vixen using the generic serial driver and everything works as expected.

My problem is with the SSR board. I can't get it to work at all, but I think I smoked it when I reversed polarity on the 120v at initial setup. The LEDs on the SSR board light, but the christmas light string connected to the outlet never fires. Assuming that I did not fry the SSR board, will this part work? (Sainsmart 8 Channel 5V Solid State Relay Module Board.OMRON SSR 4 PIC ARM AVR DSP Arduino
SKU:20-018-902) And more importantly, will it dim?

I really appreciate any help, or pointers in the right direction. This is a lot of fun, but I think I quickly ventured out of my depth.
 
I haven't tried the 8 channel SSR boards yet. But two did just show up in the mail yesterday :) So I'll be trying some experiments before I tear our the 16 channel mechanical board. I need to see if the SSRs will really handle dimming, I suspect they won't, I think we need true random-cross dimming circuits but I wanted to try. Couldn't get a definitive answer anywhere. One thing I noticed with the SSR boards is that they don't have a 5v output which sucks. On the 16 channel board I power the Arduino from the relay board which means one less power supply.

If the LEDs are lighting correctly then I'd guess the relays aren't fried, but can't say for sure.
 
Last edited:
This is my first year as well and I am using an Arduino Mega driving 2 x Sainsmart 8 SSR boards and 1 Sainsmart 8 Relay board for a total of 24 channels. I used the Generic Serial plug-in with a pretty simplistic code set on the 'duino. All is working well as long as I keep the sequence at 50ms time slices. Any less when switching 20 channels or more and the 'duino slips a channel. The only other thing I have run into is after about 10 hours of running, the USB port dies out on the Dell Mini laptop driving this. All I have to do is reset the port and all runs well again.
I do plan on switching over to a Renard system next year with a mix of 8's, 16's, and 24's as well as the Dirkcheaps driving other elements.
Year 1 - experiment... SUCCESS!!!
Year 2 - Going for broke

I've been slowly picking up clearance sale sets of lights, by next year I should have a more than enough to have a nice light show going. :)
 
Back
Top