Turning on Multiple Leds with same button

I am working with Arduino uno Mega. I have no too many informations about circuts, leds and buttons.
I have to finish a project with 14 Buttons and too many Leds. I want to decrease number of led. I need your help.

I want to ask if it is possible to control one led with a few different buttons. For a project I need it. For example I have 9 leds and 9 Buttons. When I push to first button I want to let 1., 3. and 5. Leds turning on. When I push the 2. Button, I want to let 1.2. and 3. Leds turning on. I have tried to add 3 Signal cable to positive end of a Led. When 2 Signals connected to one led, led stops turning on.

If I could achieve this, instead of 98 Leds, I will work with just 38 Leds.

Is it possible what I want.?

You could use two MAX7219, each controlling up to 64 LEDs, and using just the SPI pins (SCK, MOSI, and chip select) to load them with data. You just load them with data.
MAX7219 has 8 registers, each controlling 8 LEDs.
So for example, to turn on 4 LEDs in Register 1, you would do this:

digitalWrite (ssPin, LOW);
SPI.transfer (registerAddress); // = 1 for register 1
SPI.transfer (data1); // could be = 0x0F, 0b00001111, decimal 1
digitalWrite (ssPin, HIGH);

Make the above a function you call. Maybe have the data in array, update all 8 registers when something changed:

// time for an update?
for (x = 0; x < 8; x = x+1){
digitalWrite (ssPin, LOW);
SPI.transfer (x +1); // register addresses are 1 to 8, while arrays start at 0
SPI.transfer (dataArray[x]);
digitalWrite (ssPin, HIGH);

Use a couple of modules like these for testing
MAX7219 Dot Led Matrix Module 88 MCU LED Display Control Module for Arduino 5V Interface Module 8x8 Output Input Common Cathode: Amazon.com: Industrial & Scientific?
Then change to a breakout module if you need to break out the LEDs to bunch of discrete LEDs if that's what you need in the end.

Thank you very much for your fast reply.
But I think I could not explain what I need.
It will be little bit long text, Sorry.

My aim is not to use too many Leds. I am already able to light 182 Leds, and i can reach my goal. But 98 Leds are total mass with cables on so on.

I have attached a PNG which reflects the plan of my Project. I want to explain it shortly,

C1,C2.....C21 are my columns. Each Colum has 5 cm lenght in my work space.

Numbers are the leds which should be lightened when I push the Buttons. And I have 14 buttons.

When I push B1, the 7 Leds in C1,C2,C4,C5,C7,C9,C11 must be turned on.
When I push B5, the 7 Leds in C4,C6,C8,C9,C11,C13 must be turn on.
I do not push 2 or more Buttons at the same time.

It is enough for me when 1 Led in each column is turned on.
For example; there must be 10 Leds in Column 9. In a 5cm area, it is not easy to fit all leds with cables. It is complicated.

What I want is;
For example there Should be 1 Led in C5. When push in order of B1, B7,B8, B10 or B14, it should be only this 1 Led, which has 5 Button Signals, in Column C5 must be turned on.

Is this system possible to setup. Can one Led recieve more than 1 Signals.

Thanks for your patient.

so each button will activate 1 to n LEDs
you press a maximum of 2 buttons at the same time.


If you release one button - the LEDs activated by that button should immediately switch off (if not activated by the other button still pressed)?

basically you only want 1 LED per column. You have got 21 Columns. So you want to switch on a maximum auf 21 LEDs.

14 Buttons and 21 LEDs schould fit on a Mega.

if so, define n - the maximum LEDs (columns) activated by one button.

Each button will activate 7 Leds. It is correct but lets say Column instead of led. Important thing is with a button, it must be activated 7 different Column.
Each button will activate 7 different Column. I think in this formulation, each button will activate 1 to n. n=7
When I push B1 button , the 7 Columns (C1,C2,C4,C5,C7,C9,C11) must be turned on.

Your question: if i press max of 2 buttons. It is not correct.
Answer: Everytime I press a single button. 2 Buttons will never be pressed at the sametime.

Your Question: If you release one button - the LEDs activated by that button should immediately switch off (if not activated by the other button still pressed)? correct?
Answer: I will not press buttons in a same time.

Your Question: basically you only want 1 LED per column. You have got 21 Columns.?
Answer: This is completely correct. Continue: "So you want to switch on a maximum auf 21 LEDs." Yes this also correct. I want to switch 14 diffent button on a maximum of 21 leds.

14 Buttons and 21 LEDs schould fit on a Mega. Yes Arduino mega has 52 channel. If I would apply my first plan (activating 96 Leds), I have achieved o a breadboard. (I have connect 7 parallel led to 1 led pin, it worked. Leds are very small by the way)

ok, the concept should be pretty easy.
Are you used to put a lot of pins (for buttons and/or for LEDs) into an array?
Are you used to use for loop?
Have you heard about bit shifting before?

ok, the concept should be pretty easy.

I am so happy, but answer of 3 questions is unfortunaltely "no". But I am semi good at Soldering.

into an array question: if it is something like in picture which i uploaded. I think i can do it but if you can send me some videos.

Bit shifting: I have found a page like this. https://www.arduino.cc/en/Tutorial/Foundations/ShiftOut
I think I can follow the steps and try to apply them all.

the question about loop, I did not find any info.

It should be so. I have also created a code for 14 buttons and 14 led.
void setup()
pinMode(2, INPUT);
pinMode(5, OUTPUT);
pinMode(3, INPUT);
pinMode(6, OUTPUT);
pinMode(4, INPUT);
pinMode(7, OUTPUT);

void loop()
if (digitalRead(2) == HIGH) {
digitalWrite(5, HIGH);
} else {
digitalWrite(5, LOW);
if (digitalRead(3) == HIGH) {
digitalWrite(6, HIGH);
} else {
digitalWrite(6, LOW);
if (digitalRead(4) == HIGH) {
digitalWrite(7, HIGH);
} else {
digitalWrite(7, LOW);
delay(10); // Delay a little bit to improve simulation performance

when you have already an example with:

  if (digitalRead(2) == HIGH) {
    digitalWrite(5, HIGH);
  } else {
    digitalWrite(5, LOW);

why haven't you considered to switch on other LEDs also within such a if clause?

  if (digitalRead(2) == HIGH) {
    digitalWrite(5, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(42, HIGH);

what the heck. :o

In code section when I write corectly as you show if clause, does it function so.

Why i havent so considered. Because I did not know. It looks perfect and very easy. Thank you very much. I think i have understood the logic. I hope i can code it.

Do some tries on your own know.
If you are happy with the result, show your code in code tags and then we can see, if it should be improved.

It works. Thanks a lot. for now I do not have enaough Transistor and signal cable but first 12 led are working correctly. That means the others also will be working.

Your commands were clear and easy, thanks.

here is my code:

void setup()
pinMode(2, INPUT);
pinMode(22, OUTPUT);
pinMode(3, INPUT);
pinMode(23, OUTPUT);
pinMode(4, INPUT);
pinMode(24, OUTPUT);
pinMode(5, INPUT);
pinMode(25, OUTPUT);
pinMode(6, INPUT);
pinMode(26, OUTPUT);
pinMode(7, INPUT);
pinMode(27, OUTPUT);
pinMode(8, INPUT);
pinMode(28, OUTPUT);
pinMode(9, INPUT);
pinMode(29, OUTPUT);
pinMode(10, INPUT);
pinMode(30, OUTPUT);
pinMode(11, INPUT);
pinMode(31, OUTPUT);
pinMode(12, INPUT);
pinMode(32, OUTPUT);
pinMode(13, INPUT);
pinMode(33, OUTPUT);
pinMode(14, INPUT);
pinMode(34, OUTPUT);
pinMode(15, INPUT);
pinMode(35, OUTPUT);
pinMode(36, OUTPUT);
pinMode(37, OUTPUT);
pinMode(38, OUTPUT);
pinMode(39, OUTPUT);
pinMode(40, OUTPUT);
pinMode(41, OUTPUT);
pinMode(42, OUTPUT);

void loop()
if (digitalRead(2) == HIGH) {
digitalWrite(22, HIGH);
digitalWrite(23, HIGH);
digitalWrite(25, HIGH);
digitalWrite(26, HIGH);
digitalWrite(28, HIGH);
digitalWrite(30, HIGH);
digitalWrite(32, HIGH);
} else {
digitalWrite(22, LOW);
digitalWrite(23, LOW);
digitalWrite(25, LOW);
digitalWrite(26, LOW);
digitalWrite(28, LOW);
digitalWrite(30, LOW);
digitalWrite(32, LOW);

Man your post is too long…Please use code tags to post code (</> )…!

please read in the forum how-to how-to post code in code-tags.
Modify/edit your post accordingly.

Next step:
if you want to improve your code, please read about pin definitions in arrayhttps://www.arduino.cc/reference/en/language/variables/data-types/array/.

Afterwards see this explanation

if you like this concept, let us know - then it makes sense, to guide you to the next step.