One LED 2 Arduinos

Hello Group,

Simple question and please direct me to an answer. How do I control 1 LED using 2 Arduinos? Is it I2C or master slave configuration or what? Thanks for the guidance.

More details would be helpful.

For instance, is the LED controlled by one Arduino at a time or do both have control of it at the same time ? Are the Arduinos close enough to connect physically to one another ?

You should also tell us why two Arduinos need to have control of one LED

My, but 150 posts so far and you still do not "get it" about asking questions! :astonished:

Do not pose an "XY problem". Tell us what you actually want to do in the first place, why you suppose it is necessary to do it this way, and we can advise.

Otherwise it is a waste of time - the "XY problem - helping you to do it the wrong way instead of organising it properly in the first place. :roll_eyes:

@Paul__B: I guess I need to explain a little bit further as I was only looking on where to read about using 3 Arduinos to control items connected to each one.

This will be used for a model railroad application using sensors and red/yellow/green LEDS to be used as a signal.

Arduino 1: red yellow green led and one IR sensor
Arduino 2: red yellow green led and one IR sensor
Arduino 3: red yellow green led and one IR sensor

Here is what works: IR sensor is triggered and green led goes to yellow on each arduino and so on

What I would like to accomplish is when Arduino 1 sensor is triggered green led goes to red...which triggers arduino 2 led to go to yellow and arduino 3 led remains green and the cycle continues as the train goes around the circle of track and so on.

This will be my first attempt in joining several arduinos together. Thanks for the help.

Why do you need to user more than one Arduino ?

Yes, that is the immediate question - clearly a single Arduino is more than capable of doing all of this. Three LEDs and a sensor per section, a single Nano or Pro Mini could easily control four or five sections.

In a real life railroad, the distances dictate that signals be controlled in each section and you have a system for sending information (simply, an indication of occupancy) back along the track. On a(n indoor) model railroad it will generally be more practical to use a central controller.

Your initial description suggested wanting to have a single LED powered by more than one Arduino, which is a bit odd. If you needed to, you could have a Pro Mini ($2) per section and communication passed back like the "real thing" and if you have many sections, it may still be appropriate to have a hybrid arrangement with each Pro Mini controlling four sections and serial communications between that four sections and the previous.

Frankly, it sounds like great fun! You don't really need microcontrollers to do this since it is "straight" logic (and ridiculously slow in computer terms) but as I say, given how cheap the Pro Minis are, it becomes the most practical.

@Paul__B: yes it is alot of fun and the logic behind it as well....I am a locomotive engineer in real life and all I need to know is signal indication to tell me to stop, proceed, approach etc. If I was a signal maintainer this would be easier.

Now back to the modelling portion. I have an Arduino and a relay shield that controls a switch/turnout along with pushbuttons, dawrf signal indications and panel indications. That pretty much maxes out the Uno right there. With the logic in place depending on the position of the track switch/turnout the Uno needs to send info to the next Uno which has the exact same setup as the previous one and depending on switch/turnout position it will update its dwarf signals and panel indicators accordingly.

So now you have a bigger picture as one Arduino needs to control the other Arduinos LEDs and vice the question in the beginning was how can I accomplish this? Using I2C or the TX/RX on each Arduino and how to wire it correctly? Do you go TX from Arduino 1 to RX to Arduino 2 or what? And is it possible to daisy chain more than two? This is the area I am un familiar with. Again thanks for the help and info.

Well if you are already using UNOs with relay shields that fit directly on the UNOs, that does sound like one sort of "building block" albeit an expensive one. I would not recommend that to begin with. How many of these "blocks" are there?

Certainly there is no (logical) problem with daisy-chaining a number of these as required, each sends serial information "packets" ("TX" to "RX") to the previous using a "Token Ring" sort of system. You will need to define exactly what information needs to be conveyed.

The physical layout is a concern; you need to be concerned about the connections between one Arduino and the next, ensuring that there is a solid ground connection always accompanying the serial data line. There are not infrequently problems with relays switching interfering with code execution; you need to keep the turnout wiring completely separate from all other digital communications and should probably use checksummed communications between the Arduinos.

@Paul__B: Each Arduino stack controls 2 switches/turnouts in a simple demo loop and each stack is located about 8 feet away from each other. Each Arduino is powered separately along with separate 12v power supplies for each relay shield. The only connection would be the TX/RX on each board.

This way if you are pushing a button on either side of the loop opening/closing the switch/turnout would change the position indicator on the opposite control panel or vice versa.

Programming isn’t an issue it was checking to see which would be more reliable…I2C or serial communication via TX/RX.

How about using radio communication between the Arduinos ?

@UKHellBob: Oh that is a good suggestion as I was experimenting last year with different bluetooth modules and a motor shield to directly control 2 loops of track. The experiment worked very well. Instead of using blue tooth modules I could use wireless communications. I do in fact have 2 genuine Uno wifi boards that I haven't even opened yet. I would need to read up on how they work and I assume they work just like wifi access points? I do know you can upload sketches wirelessly with them so the TX/RX would almost be the same or am I off base with that? I will have to read up on that. Thanks for that suggestion.

Actually, what I had in mind was RF24

@UKHellBob: after you stated RF24 I went to look in my modules box and I found a few of the RF24 modules along with some blue tooth modules I must have ordered a long while back. Looks like I will be experimenting real soon. Thanks for the suggestion.

As always, "the devil is in the detail".

Eight foot sections? This is now a large layout, perhaps outdoor?

Wireless is gross overkill at this range (given that it is a static layout), but RS422/ RS485 would be appropriate simply to reliably pass plain serial data from one to the next given that they are separately powered. (I keep saying "previous" as that is of course, the nature of the block communications).

It is still not clear to me that if the stations are 8 feet apart, each one has its own local manual control. :astonished: