Christmas Lights Using 8ch Relay With Arduino




About: Wood working and electrical engineering....oh yeah and building stuff

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

2 People Made This Project!


  • Fandom Contest

    Fandom Contest
  • Frozen Treats Challenge

    Frozen Treats Challenge
  • 1 Hour Challenge

    1 Hour Challenge

15 Discussions


6 months ago

I was looking for a simple example of code and connection diagram to test my relay board. This was awesome!

Thank you!


2 years ago

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.

1 reply

Reply 2 years ago

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.


3 years ago

at the 1st picture they dont look so happy!


3 years ago

How can you get more channels, for example 64 channels?

1 reply

Reply 3 years ago

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.


3 years ago

any ideas on how to make it flash to music?


3 years ago

Thanks for the 'ible. With the code, if you put the individual elements of the code such as Turn lights off or Single counter on/off into functions, it would make it easier to rearrange the code i.e. in void loop(), 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).

Refer to this for help if you need it:

Here's an example of the bit in your code which switches everything off:

void allOff() { // Declaring the function

for(int x = 2; x < 10; x++){ //turns off lights

digitalWrite(x, HIGH);



void loop(){

...[other code here]...

allOff(); // Use this each time you want switch all the lights off. It acts almost like a shortcut to the for statement above.

...[other code here]...


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

Loads of possibilities!

1 reply

Reply 3 years ago

Wow! great suggestion! I totally forgot about this function while coding. Ill definitely adapt this control box to somethings else after the holidays!

Ive come up with some editted code in step 9


3 years ago

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

1 reply

Reply 3 years ago

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.

Heres the link to the video of it: