Arduino Leonardo matrix 5x4

I am a bit confuse with the connections of my iluminated buttons to my Arduino Leonardo board using a matrix 5x5 because I have 17 iluminated buttons, 3 switches on/off, 2 switches on/off/on.

The buttons are 10x16mm with 5 pins (NO/NC/C/+/-), 6x12mm 4 pins (NO/NO/+/-), 1x22mm 4 pins (NO/NO/+/-).

The problem is that the buttons only work if I have:

  1. NO connect to + and to PIN GND
  2. C connect to a PIN (for instance PIN 0)
  3. '-' connected to PIN 5v

and in the 4 pins buttons:

  1. NO connect to + and connect to PIN GND
  2. The other NO connected to PIN (for instance PIN 1)
  3. '-' connected to PIN 5v

Only with these configurations I got the buttons iluminated and generating the number corresponding to pin where they are connected.

With these connections I cannot create a matrix of ROWS and COLUMNS. I can put the DATA PIN in COLUMNS but I have no PIN to connect to ROWS, I have only GND and 5V pins.

I am confused, can someone help to understand how to create a matrix with these iluminated buttons?

It's a bit difficult to help without a schematic, your code, parts list, and maybe some pictures.

Buttons with only two pin I think it is easy to create a matrix because each pin is a row and a column. But with my buttons I have only 1 pin. The other are GND and 5V.

These are the 5 pin button https://pt.aliexpress.com/item/1005004432461088.html?spm=a2g0o.order_list.order_list_main.117.9167caa4iVWzlh&gatewayAdapt=glo2bra

Can you tell me how to create a matrix of 2x2 with 4 of these buttons. How do I connect them to a Leonardo board?

I wouldn't see an issue using these in a matrix. The ground and 5V are for the light. The C and NO pins will work like a traditional 2 pin momentary switch.

That is what I thought but if I dont connect the + or '-' pin to the ground I do not have light in the button.

I didn't say not to connect them. Use them to illuminate the button and use the C and NO pins in the button matrix wiring.

You didnt understand what I said. If I use only C and NO, the button works and I can use the matrix. But to lighten the button I need to connect the pin + or pin '-' to C and to ground, so I loose one PIN (it is connected to ground) to use in the matrix.

In other words I have to connect the NO or C pin to ground if not it does not work.

I understood that. You didn't understand when I said that you would need to post a schematic and your code in order to receive proper help. Please do so now and I will be happy to look at them.

I am going to talk about the 4 pins button (it is easy), They only work connected like this

How is pin 1 configured in your software and how are you reading it?

You seem to have 5V running to your negative terminal according to your drawing.

Is this the same 5V and ground that is powering the Arduino? If not, do they have a signal ground between them?

These questions and more are why a full schematic and the associated code are necessary.

Sorry, but this is to technical to me. I am not an electronic technician or a software guru. I know something about coding but electronics only the basics. I think I am going to reduce the number of buttons and keep it clean without matrix.

It sounds like you don't have a schematic and just limited code. Is that correct?

The matrix shouldn't be an issue. Wiring that 5v and ground for the switches light should be separate from the rest of the matrix. The ground for the switches needs to be connected to the ground on the Arduino.

Do you need to read only one switch at a time or is there the potential for multiple switches to be pressed?

Edit: show whatever code you do have, please

Yes, CORRECT ;). I dont need several buttons at same time, only one.

Leonardo has 3 pins GROUND. Do I need to connect the gnf of the light and gnd of the switches to different PINS? But I do I create a matrix if I only have 3 GND pins?

Give me 30 minutes. I can help a bit more.

I am not in my desktop so I cannot say which code I have in the board but I think it is one of these two (I think code 2).

Code 1.txt (1.3 KB)

Code 2.txt (4.1 KB)
I have search in google for a code for my button box, found many and use mainly these two and trying to adapt them to my needs.

Where are you using this? In a car or on a desk?
How do you intend to provide it with power? USB cable or separate power?
Will it be connected to a computer when it is used as a finished product?

You mentioned 3 on/off switches. Can only one of these be on at a time or can more than one be latched? Can they be on when another button is pressed as well? It's fine if the answer is yes, I just need to know. same for the two on off on switches.

It would help to know more about the intended use of the button box as well.

I am a simracer, it is to be connected to a USB port of my desktop and provide some aditional clicks to manage my races. Power is from USB but, if needed, I can use a separate power as the Leonardo board as a connection for it.
No need to have more than one button pressed at a time. Same for the switches.

It is a button box that could be an emulated keyboard. It just sends code to my game that I configure to execute some tasks. For instance, Put Seats UP or Down, Front or backward, Show Time Table, open Chat, etc.

Do you intend to connect anything else to your Leonardo?

Also, this is a traditional Leonardo, R3 board format?
Looks like this?