Switching between two arduinos to drive an LED rope (novice question)

onethreenine

Sep 24, 2025
1
Joined
Sep 24, 2025
Messages
1
I've rather brashly stuck my hand up to help out with lighting and props for my kids' theatre performance. I need to simulate a flaming whip and a fire in a fireplace and I know enough to be dangerous and probably not enough to get the job done. I had the bright idea of getting a 5m ws2811 based rope that will do the trick for both if controlled right. I've got the programming down, but running two different programs off a single Arduino is a bit beyond me, so I've got two and loaded the appropriate code to each. I'm running the whole rig off a battery pack, which I tested and works just fine with one board and the rope.

So far so good. Now I need to mount it all up and provide a mechanism to switch between the two boards, powering one board plus the lights at a time. I was thinking I could do it with a 3 position switch and I've mocked up a very rough diagram of the circuit.

LED Rope.png
(D5 is the control feed to the LEDs, it's distinct from the power loop, but I figured it should be represented)

But I feel like I'm setting myself up for either a pratfall or a damp squib when each side of the switch is powering the lights and I think in the process putting the whole circuit in series, and leaving the nominally "off" board as a path of less resistance than a string of 250 ws2811s.

Am I best to switch the light and boards separately, or is there something I can add to essentially isolate the two sides of the circuit? The switch I have provides NC and NO terminals, but I can't map the logic to use that to deal with the issue. I was thinking I could wire the lights up to both sides of the NO, which would leave the lights always powered and the boards switched using the NC, but I don't know if that's going to leave the same problem in place.

Any help would be gratefully received by me, the Greater Northland Amateur Theatre, and about 80 kids involved in the show.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
running two different programs off a single Arduino is a bit beyond me
You can't. An Arduino is only running one piece of code at a time. However, switching between two code pieces within one program is easy as pie.

Assume you have two sketches sketch_1 and sketch_2:
C:
// sketch_1

void setup() {
    initialize the Arduino
}

void loop() {
    control the LEDs as required for sketch_1
}

// sketch_2

void setup() {
    initialize the Arduino
}

void loop() {
    control the LEDs as required for sketch_2
}

To merge these two sketches, use an addition GPIO as input (switch) to select one of the two main code loops:
C:
void setup() {
//    initialize the Arduino - this setup needs to work for both prior sketches (I assume it was the same anyway)
// add input pin to select between the 2 code loops
    // see e.g. here: https://docs.arduino.cc/built-in-examples/digital/Button/
    pinMode(ButtonPin, INPUT);
        }

void sketch1() {
// put the code from the former loop from sketch_1 here
}

void sketch2() {
// put the code from the former loop from sketch_2 here
}

void loop() {
    // this works for a switch. When using a pushbutton it will work, too,
    // but requires someone to hold the pushbutton pressed for as long as sketch2 needs to be active
    // as
    if digitalRead(ButtonPin) == 0
        sketch1();
    else
        sketch2();
}

Your schematic might work, but probably not as expected as you are backfeeding power to the unpowered Arduino via the GPIO pin connected to the LED's data line. With unpredictable consequences.
If you don't want to implement the software solution and want to keep the hardware solution instead: Simply keep both Arduinos powered, use a changeover switch to connect the data input of the LED string to either D5 of Arduino1 or to D5 of Arduino2. Both Arduinos will chuck along with their programs, but obly one of them gets to actually control the LED string, depending on the position of the switch.
 

Martaine2005

May 12, 2015
5,276
Joined
May 12, 2015
Messages
5,276
This is pretty much what I’m trying to do. But I’m no programmer and my code has #delay function which apparently makes it impossible for the arduino to multitask. Using the #mil function can do it but it’s also way over my head.
I’m using two nano’s and two dfplayer mini’s with both outputs to a crude resister for mixing both audio signals. I’m making a rather extravagant thunder and lightning simulator that’s completely random with random flashes and random thunder that follows after a random time. It’s much more realistic than the units you can buy.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
keep both Arduinos powered, use a changeover switch to connect the data input of the LED string to either D5 of Arduino1 or to D5 of Arduino2.
Here's a graphical representation, possibly much easier to read than text:
1758797312993.png
 

danadak

Feb 19, 2021
1,063
Joined
Feb 19, 2021
Messages
1,063
ESP32 have dual core versions, real HW multitasking, might be an option.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
Imho overkill. Only one task is active at a time.
Besides, using the second core in an ESP32 is not trivial.
 

danadak

Feb 19, 2021
1,063
Joined
Feb 19, 2021
Messages
1,063
Using Tuniot to do the block code the second core is quite straightforward.
Arduino IDE has examples as well. Not rocket science. But to your point
Multitasking has its own considerations, like a developer using interrupts
for the first time.....

Overkill, I think 2 Arduino boards overkill. But also agree one core just about
anything should be suffcient



Regards, Dana.
 

Huzurlu Adam

Oct 17, 2025
2
Joined
Oct 17, 2025
Messages
2
In addition to this post, it would be useful to take a look at the interrupt topic.
 
Top