Matrix only detects one press at any give time

i have made a 4x4 matrix using Matrix of SPST switches and buttons with Arduino - Electrical Engineering Stack Exchange as a reference. my matrix only detects one keypress at a time. example if i have 3 turned on and i press button 4. 3 turns off and 4 lights up. if i now switch off 4, button 3 which was already in on position turns on.

is this the correct way of working ? i have diodes before each row input of the switch.

.

i am able to detect indivisual button presses,no ghosting but two buttons cannot be on at the same time only latest pressed one shows up as on.

Is what the correct way of working? You didn't provide a schematic.

i have edited my orginal post with the schematic

Your diodes do nothing. The power bus is allowing the signal to pass under the diode.
Use the middle of the board instead.

What are you using for software?

If you want anti-ghosting diodes, use one per button. If you use the Keypad library, the Cathode (-) end of the diode points to the Column pin.

Excellent keypad/ button matrix tutorial here, with the correct wiring.

Thankfully, the column drivers are not connected together, which could easily blow the Leonardo's output drivers. However, if you pushed more than one button at the same time, there is an indirect route through the switches that could do that. Better check your outputs...

Clearly this is only a training exercise as using four buttons/ switches in a matrix uses four pins and using them individually uses four pins.

And a matrix can distinguish any two simultaneous connections without diodes, the potential problem comes only with three or more.

And we have no idea of what code you actually used. :face_with_raised_eyebrow:

i have fixed the wiring.

#include <Joystick.h>

#include <Keypad.h>

const byte ROWS = 2; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'B','1','g'},
  {'I','2','t'},
};
byte rowPins[ROWS] = {15, 14,}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {16, 10, 8,}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
}

void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){
    Serial.println(key);
  }
}

with this code even if i dont have the diodes the problem of if switch 1a is turned on and switch 2b is turned on after the former 1a does not turn off and 2b does not turn on and vice versa. now the problem is only a single button in the whole matrix is detected.

changed it to 2*3 still same issue.

how does this fit to the image you have have posted?

byte rowPins[ROWS] = {15, 14,}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {16, 10, 8,}; //connect to the column pinouts of the keypad

please post a picture of YOUR schematic (not the breadboard view!)
please post real pictures of your setup wherein we can see each and every connection you have made.

32-FUNCTION-BUTTON-BOX/ARDUINO_BUTTON_BOXV2.ino at master · AM-STUDIO/32-FUNCTION-BUTTON-BOX · GitHub used the code from this and my problem has been solved. idk how the wiring has stayed exactly the same but this code just works.Can detect multiple buttons now. Even the matrix code i posted above didnt work properly but the github one does work.

Excellent, In the future you'll get better help faster if you post actual pictures of your project.
BTW, I still think it would be wise of you to do so. The circuit you originally created is one wire short of being able to burn out your Arduino and it's entirely possible that you still have a dangerous condition.
Just a suggestion though.

i changed that circuit.now my diodes run horizontally on the main part of the breadboard.basically they run in parallel.

problem with actual pictures is its a rats nest of wires.

No doubt. :grin:

Are you actually using a Pro Micro rather than a Uno? If so, why it it not plugged into the breadboard? Pro Micro is made to plug into a breadboard. Maybe this is why your circuit is a rat's nest of wires?

1 Like

i can plug the pro micro into the board and it still would be wires given the amount of switches.anyways now i have simply soldered the diodes to the switches themselves and the wires to the diodes all of that respectively. much cleaner now and easier to work with.