Introduction: Christmas Lights Using 8ch Relay With Arduino
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
- Arduino Uno
- sain smart 8ch relay board
- extra wire
- 2x 4 bay light box
- 4x outlet
- female to male jumper wires(dupont wires)
- safety switch
- out door timers
- 8x extension chords
Tools you will need
- Hot glue gun (with glue)
- small screw driver
- larger screw driver
- pliers
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!