Switch multiple LEDs via buttons connected to 2 differnt slave Arduinos


i need your support.
My plan is to control differend LEDs (on/off) which are connected to different PWM-Pin on the Master-Arduino by switches connected to slave arduinos. - So its a kind of change circuit w/ buttons which are connected to different Arduinos to avoid complex wiring.

The Arduinos are communicating via I2C.

If e.g. the floor-LED-Button on one slave arduino is pressed, the correct Pin on the Master Arduino is changing its state (On / Off).

I'm wondering how to setup the control in a smart way. I thought about to send a char which identifies the correct LED. A general function is using this char as input and changes the state of the PIN. Like this example (based on a single Arduino setup:

LED-switch(char LED)
if(digitalRead( ) == HIGH){
if(led_an == true){
led_an = false;
digitalWrite(SLC, LOW);
led_an = true;
digitalWrite(SLC , HIGH);

Can you please give me a hint how to setup the system in a smart way?



Do some research about how I2C works, what it offers. As I got it the master will need to call each slave for a slave message. What data types to use, You look for that.
Searching for electrical data will be useful as the total number of devices might call for suitable pullup resistors on SDA and SCL.

Why not post a concept block drawing showing wiring lengths, links to technical info on hardware items you have chosen. This has a big impact on what I would recommend to use. The information you pass to control things is up to you. Using a character is a good way to start, you can see that on the monitor. You learn the concept that way and later expand upon it. There many standards which make it easier but they do not need to be followed.

I agree with @gilshultz , my curiosity is raised when you say ‘ buttons which are connected to different Arduinos to avoid complex wiring.’

This sounds like you are adding complexity to reduce complexity…
Block diagram, and reasons please.

Thanks for your feedback & sry for the unclear description.

@Railroader : Yes, im currently reading in parallel how the I2C bus works. I just wanted to get a direction from an expert how to realize such a system. thx.
@gilshultz @lastchancename : Below a diagram with some additional information.
I have 4 different buttons (not switches) per arduino. I have at least 2 Arduino to control the lamps.
In addition I would like to alluminate all 4 buttons independently.
The buttons are located direct next to the arduino.

If I wire all buttons to 1 Arduino I would need to connect 2 cables per switch (Button Signal & the 5V for illuminating). This would be in general possible but the SW solution is definitely the smarter way. Especially when I would like to extend the system in future.

Thx for your support!


Using I2C between disparate devices seems risky…
if I recall, the spec roughly defines about 600mm max length ( its intended to run between ICs, not modules.)

Any reason you’re not just using spare pins on the MEGA to detect the switch states… there are several options ?
The low frequency of button pushes at 5V makes them very easy to debounce / filter etc

From what you’ve explained so far, a MEGA2560 could do everything easily, with less risk & complexity.

Can you add to your diagram the distances between each unit?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Hi TomGeorge, The distances between the arduino are approx. 2-3meters (as shown in the diagram)
The buttons are located directly next to the arduino.


Put everything in the Arduino Mega 2560, with wires to the buttons+leds.
You can use shielded Cat cables, so the signals stay clean.

If sketch in the Arduino Mega is busy with other things, then you might have to re-organize your sketch to be able to do more.

Ok, then my proposed solution is not easily possible... Shit... I have mixed up UART w/ I2C here...

The idea was to avoid additional cables & be able to extend the system on a easy way in case needed.


Sorry your image has a black background to me. png.
In jgp its.

Not sure why.
Thanks...Tom.. :grinning: :+1: :coffee: :australia:

After your feedback I'll continue w/ 1 MEGA and additional cables!

Thank you very much for your support!


If you’re intent to use a MEGA and 4xUNO slaves, that’s not a problem…

The MEGA has FOUR serial ports (including the USB/console), or… if you’re keen, you could multi-drop the slaves off a single port of the host…(e.g.RS485)

For what you’ve drawn, I’d still think seriously about a single MEGA2560 doing everything.

Just plan your buttons & LEDs before you start, and you’ll be golden.