I'm 16 years old so my knowledge on these relays is not that extensive, for another instructable to do more research click here.

Or you could check out my blog where I post some of my best projects!

This project is can be used for a Christmas lights display or just controlling higher powered applications like motors, large amounts of LEDS, and home control.

All relays are basically the same and use very old technology. In mechanical relays a coil is powered and closes a switch which allows power to flow to the object. There are also non-mechanical relays which don't make a clicking sound when closing the circuit. But for this project we will be using mechanical relays rated up to 10A at 250V ac or 10A at 30V dc.

What you will need

Tools you will need

Step 1: Safety

You are working with 120v AC which can KILL if miss handled!!! That is why you should ground everything you possibly can. Add a fuse and safety switches if you can. This is not a toy but you should be safe if you take all the right precautions. Finally cover all connections so that nobody can accidentally touch the wires. When connecting the arduino to the relay board sain smart uses optically isolated boards. Which means that the arduino can just power an led that in turn switches the relay closed or open(on or off). So the arduino isn't directly in contact with the relays on the board. However the easiest way to run the 8ch relay board is to power the coils directly from the arduino.

Also know you will be switching the hot wire on and off. So the neutral wire will be the common.

Step 2: Prep the Relay Sheild

The relay board comes with these metal tabs in each of the wire ports. Now when these were in place the wires would fall out of the ports with some stress. So to combat this I unscrewed the screw all the way and tilted the board so the tab would fall out. Then I put the screw back in and it made a big difference in the strength of the connection.

Step 3: Combine All the Hot Wires

To connect all the hot wires together I used a terminal block which made it easy. But this type of terminal block has NO circuit protection so you have to be very careful when near it, to make sure you don't touch it. All I did was make wires of various lengths and found a open screw to attach the wires to. This will later be hot glued to the side of the container.

The ports that are connected to the common terminal block are marked in red in the third picture.

Make sure you are running the hot wire through the relay board not the neutral it is very dangerous.

Step 4: Prep the Outlets

There is a tab on the hot and neutral sides of the outlet. You want to break the tab on the hot side. What this does is it separates the top and bottom ports, allowing them to be controlled separately. bacily instead of buying 8 outlets for 8 ports you only have to buy 4 outlets for the same amount of control.

Step 5: Add Jumpers From the Relay Board to the Outlets

I used a spare extension chord to make the jumpers from the outlet to the board. The colorful wires go to the arduino.

Now the space management in this box could have been a lot better but all i cared about was if it worked or not.

Step 6: Connect All the Neutral Wires Together

Since I don't have a picture for this one I put some red lines representing the wires I put in.

Step 7: Adding a Plug

This was a simple extension chord that i found in Meijer. I picked this one because it had and inline switch for safety. Then i cut it to about 3ft and connected the black wire (hot) to the common hot terminal block. The white wire (neutral) to the common neutral. Last the green wire to the ground on the ground on the outlets.

Step 8: Connecting the Arduino to the Relay Board

The arduino has enough power to run the relay board with out having to use an external power supply.

When looking at the relay board you will see a small jumper wire connecting the JD-Vcc to Vcc. Leave it on if your using the arduino to power the board, if you were to use an external power supply you would remove it.

The 10 pins in the middle of the board connect to the board as follows:

  • GND to GND on arduino uno
  • INT1 to pin2
  • INT2 to pin3
  • INT3 to pin4
  • INT4 to pin5
  • INT5 to pin6
  • INT6 to pin7
  • INT7 to pin8
  • INT8 to pin9
  • VCC to 5v on arduino uno

To power the arduino use a usb cord and a phone adapter.

Step 9: Code for the Display

int relay1 = 2;
int relay2 = 3; int relay3 = 4; int relay4 = 5; int relay5 = 6; int relay6 = 7; int relay7 = 8; int relay8 = 9; int time = 250; int timef = 450; int timeA = 500; int timeC = 250;

void allOff() { // Declaring the function for(int x = 2; x < 10; x++){ //turns off lights digitalWrite(x, HIGH); } }

void flashR(){ digitalWrite(relay2, LOW);//flash r digitalWrite(relay4, LOW); digitalWrite(relay6, LOW); digitalWrite(relay8, LOW); delay(timef); }

void flashW() { digitalWrite(relay1, LOW);//flash w digitalWrite(relay3, LOW); digitalWrite(relay5, LOW); digitalWrite(relay7, LOW); delay(timef); } void AlternateColors(){ digitalWrite(relay1, LOW);//alternate w/r digitalWrite(relay4, LOW); digitalWrite(relay5, LOW); digitalWrite(relay8, LOW); delay(timeA); allOff(); digitalWrite(relay2, LOW);//flip colors digitalWrite(relay3, LOW); digitalWrite(relay6, LOW); digitalWrite(relay7, LOW); delay(timeA); }

void Wcounter(){ for(int x = 3; x <= 9; x=x+2){//counter w digitalWrite(x, LOW); delay(timeC); } for(int x = 9; x >= 3; x=x-2){//rewind counter w digitalWrite(x, HIGH); delay(timeC); } }

void WcounterOpp(){ for(int x = 10; x >= 3; x=x-2){//back counter w digitalWrite(x, LOW); delay(timeC); } for(int x = 3; x <= 10; x=x+2){//back rewind counter w digitalWrite(x, HIGH); delay(timeC); } } void Rcounter(){ for(int x = 2; x < 10; x=x+2){//counter r digitalWrite(x, LOW); delay(timeC); } for(int x = 8; x > 2; x=x-2){//rewind counter r digitalWrite(x, HIGH); delay(timeC); } }

void RcounterOpp(){ for(int x = 8; x > 2; x=x-2){//Back counter r digitalWrite(x, LOW); delay(timeC); } for(int x = 2; x < 10; x=x+2){//Back rewind r digitalWrite(x, HIGH); delay(timeC); } }

void counter(){ for(int x = 2; x < 10; x++){//single counter on/off digitalWrite(x, LOW); delay(time); digitalWrite(x, HIGH); delay(time); } }

void setup() { // put your setup code here, to run once: pinMode(relay1, OUTPUT); pinMode(relay2, OUTPUT); pinMode(relay3, OUTPUT); pinMode(relay4, OUTPUT); pinMode(relay5, OUTPUT); pinMode(relay6, OUTPUT); pinMode(relay7, OUTPUT); pinMode(relay8, OUTPUT); }

void loop() { // put your main code here, to run repeatedly: allOff(); counter(); allOff(); Wcounter(); delay(timeC); allOff(); WcounterOpp(); delay(timeC); allOff(); Rcounter(); delay(timeC); allOff(); RcounterOpp(); delay(timeC); allOff(); flashR(); allOff(); flashW(); allOff(); flashR(); allOff(); flashW(); allOff(); flashR(); allOff(); flashW(); allOff(); AlternateColors(); allOff(); AlternateColors(); allOff(); }

Step 10: Add More Lights!!

This project was pretty expensive please help support me!

Try Amazon Prime 30-Day Free Trial

<p>I used mechanical relays for my light display one year (so I could run more power through a preprogrammed box). The relays only lasted one season, 1 million cycles is not allot when it comes to flashing christmas lights. I ended up remaking the box with solid state relays.</p>
<p>As I pulled the relay box out of storage this year I found out 3 of the channels are broken. So 5 worked, which isn't enough to do the same display as last year so what I ended up doing was wrapping the tree in the front which looks nice.</p>
<p>I made this last year too. Was working off 3 different instructables to try and add music to it but the music controller failed to work. (programming issues). Since then I have got the music controller to work but have not tried it out on the Arduino Chirstmas box.</p>
<p>Nice! Well my original plan was to add music to it but I too failed to do that. And realizing the fact that you can only get so far with 8 channels.</p>
<p>Ho ho hooo!</p>
<p>at the 1st picture they dont look so happy!</p>
<p>How can you get more channels, for example 64 channels? </p>
<p>You could do something like using more relay boards with a shift register controlling each output. I know the same company that makes these 8ch relay boards also makes 16 channel boards. So you could get 4 of those and 8 shift registers, theres probably and easier way to do this but if your proficient in arduino code than this is a good DIY option. If not you could get some name brand controllers which are more expensive but a lot easier to do.</p>
<p>any ideas on how to make it flash to music?</p>
<p>I'm making something similar, except using 16 channels, an Adruino Mega, and programming it using Vixen 2</p>
Nice! This year I just wanted it to work. Plus it get pretty expensive buying all the extension chords.
That's cool! I'm taking every extension cord I find in the house... The advantage to yours is programming in Vixen takes quite a while, plus having lights flash or do a pattern is already enough to beat most neighbors :P
<p>I use Vixen add-in called Frequency as a Color Organ. Quick and easy.</p>
<p>So true! Hopefully next year there will be more lights and music. Just wanted the practice with the for-loop function in arduino. </p>
<p>Techno Tony, I am building the 16 channel model with Vixen 3. Did you have any trouble getting Vixen to communicate with your Arduino? Would you share your code with me for Vixen 2? Yours is looking really good, I like your setup better than mine. Great job.</p>
<p>I had trouble getting Vixen 3 to communicate, as it would just freeze the moment I tried to add the Arduino to it. That's why I switched to Vixen 2. It's less featured, but for what I did using simple relays, it worked just fine.</p><p>Here is a link to the Arduino Sketch: </p><p><a href="https://dl.dropboxusercontent.com/u/98990586/Arduino%20Sketch.zip" rel="nofollow">https://dl.dropboxusercontent.com/u/98990586/Ardui...</a></p><p>After you have uploaded the file to your Arduino, when configuring the output from Vixen 2, use the Generic Serial option for channels 1-32 (The sketch is made for 32 channels. If you plan on only using 16 like me, then create the sequence as 32, but only program the first 16). Then, make sure you set the Baud rate for the serial plugin to 9600. Then, check the option to send a text header, and type ~! for the header. Vixen should now output to your Arduino.</p><p> If this isn't clear enough, then feel free to leave a reply if you would like me to add screenshots.<br></p>
<p>Thanks for the 'ible. With the code, if you put the individual elements of the code such as <em>Turn lights off</em> or <em>Single counter on/off </em>into functions, it would make it easier to rearrange the code i.e. in <em>void loop()</em>, you'd just have a list of the functions when you want them e.g. turnOff(); turnOn(); turnOff(); turnOn(); turnOff(); singleCounterOnOff() etc... (with a new line after the semicolons).</p><p>Refer to this for help if you need it: <a href="https://www.arduino.cc/en/Reference/FunctionDeclaration" rel="nofollow"> https://www.arduino.cc/en/Reference/FunctionDecla...</a></p><p>Here's an example of the bit in your code which switches everything off:</p><p>void allOff() { // Declaring the function</p><p> for(int x = 2; x &lt; 10; x++){ //turns off lights</p><p> digitalWrite(x, HIGH);</p><p> }</p><p>}</p><p>void loop(){</p><p>...[other code here]...</p><p>allOff(); // Use this each time you want switch all the lights off. It acts almost like a shortcut to the <em>for statement</em> above.</p><p>...[other code here]...</p><p>}</p><p>Doing this would help you make more complex sequences or even make the lights respond to something like a motion sensor or even an email or Twitter post using <a href="https://ifttt.com" rel="nofollow"> https://ifttt.com</a>...</p><p>Loads of possibilities!</p>
<p>Wow! great suggestion! I totally forgot about this function while coding. Ill definitely adapt this control box to somethings else after the holidays!</p><p>Ive come up with some editted code in step 9</p>
<p>Nice job!</p>
Hi RomanD I just wanted to say great job on your project it's very cool. I would love to see a YouTube of it in action. As a contractor I should tell you that the box should really be water tight and have more protection around the high volt side in case of loose wire spark. Hope you don't mind the two cents. Great job all the same
<p>Thanks! The control box is outside by the front door, so its under a roof and i put it inside a plastic trash bag. It is also elevated on some flower pots so it wont be in a puddle of water. </p><p>Heres the link to the video of it:</p><p>https://www.youtube.com/watch?v=26d0t-QCq_g</p>
<p>Awesome light controller. </p>
Thanks! I tried to make it simple and doable.

About This Instructable




More by RomanDz:Simple LED Blink Circuit DIY Light Box Simple Wire Pumpkin 
Add instructable to: