Interactive Xmas Lights Project (Alittle early)

Hi All,

I'm new to Arduino and new to the forum.

My street is pretty into their Xmas lights and last year i decided i was going to make alittle more of a effort this coming year. I have a decent size(not xmas tree) tree in the front yard and my plan is to apply this project to this tree.

Plan:

Buy several different types of xmas lights, different colours/ effects.
Load them all into the tree and have and have a pedestal of some sort on the grass with a big red button that activates different relays one by one when the button is pressed effectively making the Xmas lights interactive.

My coding is not the best, I've basically been following through some tutorials and having a struggle to figure out how to do what I want.

I have managed to find some else's previous project that does something similar except each relay has its own button. I'm wondering if someone could point me in the right direction in editing the below code to achieve my purpose (one button that's activates the relays sequentially as appose to 4 buttons)

Acknowledgements to rawrrr_x3_xoxo as I stole this code from his 2018 post.
“Imitation is the sincerest form of flattery that mediocrity can pay to greatness.”
― Oscar Wilde

// Guitar amp relay module driven my microcontroller input
// 2018 - Eric Carlson - ECS Audio
int relay1 = 12; //Amp CH1 relay
int relay2 = 11; //Amp CH2 relay
int relay3 = 10; //Amp CH3 relay
int relay4 = 9; //Amp CH4 relay
int button1 = 2; //CH1 Button
int button2 = 3; //CH2 Button
int button3 = 4; //CH3 Button
int button4 = 5; //CH4 Button
void setup()
{
// Initialize digital output pins for relays:
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
// Initialize digital inputs with internal pullup resistors:
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
//Set the initial startup to CH1:
digitalWrite(relay1, LOW);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
}

void loop()
{
//CH1 EN
bool button1State ;
button1State = digitalRead(button1);
if(button1State == LOW)
{
digitalWrite(relay1, LOW);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
}
//CH2 EN
bool button2State ;
button2State = digitalRead(button2);
if(button2State == LOW)
{
digitalWrite(relay2, LOW);
digitalWrite(relay1, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
}
//CH3 EN
bool button3State ;
button3State = digitalRead(button3);
if(button3State == LOW)
{
digitalWrite(relay3, LOW);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay4, HIGH);
}
//CH4 EN
bool button4State ;
button4State = digitalRead(button4);
if(button4State == LOW)
{
digitalWrite(relay4, LOW);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
}
}

Thanks to everyone that made it to the end of my post :wink:

1 Like

So one button could increment the buttonState variable. Each light show can be ran from a detected count.

Button starts at 0 for no show.
Press button, count goes to 1, start show 1.
Press button, count goes to 2, start show 2.
Press button, count goes to 3, start show 3.
Press button, count goes to 4, start show 4.
Press button, count goes to 0 for no show.

Switch Case should work well.

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Take a look at the State Change Detection example in the IDE (File->examples->02.digital->StateChangeDetection). This will help you know when the button is pressed, not if the button is pressed. Combining that with @Idahowalker suggestion, you change your state whenever a button is pressed.

Probably the hard way.....

Use 12V WS2811 strings.
https://www.amazon.com/gp/product/B01MCQP7KP/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

I have almost 1,000 LEDs on a ten-ft tall "tree" (a PVC frame). The LED patterns are driven from a single Wemos D1 Mini. An Arduino Nano would work as well, but the Wemos is cheaper and faster and I have a dozen.

Using programmable LEDs, the patterns and colors are all done in software. You are only limited by your programming skill and imagination.

I haven't done it, but some have fed audio from a music source into the analog input to modulate the lighting effects to Christmas music. You could always use buttons to manually change the patterns.

If you want to use old-fashioned incandescent strings, I have a few thousand in my attic that you can have for the cost of shipping.

Check back when Christmas is upon us and tell us that you were, in fact, starting a little early.

Unless you meant Christmas 2022. :wink:

a7

I am wondering if my Halloween project will be finished in time....

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.