I have attached a 3x4 keypad to my Arduino Leonardo as an input method. Whenever I press the buttons, the majority of the keys work but specific ones don't. Here's my code, I've set it up to beep a piezo buzzer when it gets a keypress.

#include <Keypad.h>

int buzzerPin = 0;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
byte rowPins[ROWS] = {12, 13, 8, 10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {11, 7, 9}; //connect to the column pinouts of the keypad

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

void setup(){
    pinMode(buzzerPin, OUTPUT); //Set buzzerPin as output
    keypad.addEventListener(keypadEvent); //Add an event listener for the KeyPad

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

void keypadEvent(KeypadEvent eKey) {
        // When the KeyPad will be pressed, the results will appear on the serial monitor.
        switch (keypad.getState()) {
        case PRESSED:
                Serial.print("Enter: ");

void beep(unsigned char delayms) { //creating function
    tone(buzzerPin, 2000); //Setting pin to high
    delay(delayms); //Delaying
    noTone(buzzerPin); //Setting pin to LOW
    delay(delayms); //Delaying

I based my rows/columns off of this pin-out: https://www.jaycar.com.au/12-key-numeric-keypad/p/SP0770, but I later found out some of the columns had to be swapped :P

Here's a diagram of what's happening: Diagram of working and not working keys

The keys in red do not work.

I wouldn't have posted this on stack exchange but it looks like an oddly specific pattern, and no matter what I changed, it didn't work.

(And yes, that is the exact keypad I bought from Jaycar)

Edit: I forgot to mention that I was using a prototype shield to plug the keypad into, but all pins are confirmed working on that.

  • 2
    If either row #2 or column #2 is used it does not work, unless both are used. Have you exchanged/mixed row #2 and column #2 somehow? There must be some logic in it. Can you disconnect the keypad and test every button with a multimeter? Please tell which arduino pins are connected to which keypad pins. – Jot Sep 9 at 10:22
  • One more question: is it a cheap clone board? Because row #2 is connected to pin 13. The official arduino leonardo has a extra logic chip, so pin 13 can be used as a input without problem. Try to use another pin for row #2. Update your question with the extra information. – Jot Sep 9 at 10:34
  • Agree w/@Jot, row #2 is swapped w/column #2. Try changing your code to read "byte rowPins[ROWS] = {12, 7, 8, 10}; //connect to the row pinouts of the keypad byte colPins[COLS] = {11, 13, 9}; //connect to the column pinouts of the keypad" to see if a code change can clear up the problem. – st2000 Sep 9 at 23:04
  • are you sure that 5 actually works? – jsotola Sep 10 at 0:43
  • Right so I've figured it out now (thanks to you guys), it turns out that yes in fact row 2 and column 2 were swapped around. I also forgot to mention that this was a prototype shield I was plugging the pins into, but thanks everyone for the quick and useful replies. In terms of marking this question as answered, I'm fairly new to this... Do I just quote one of you above in my answer button? Or do I requrie a moderator or something? – Neonalig Sep 10 at 9:49

A row against a row does not work, or a column against a colum.
That means there is a logical explanation. Row #2 is swapped with column #2.
Button 5 does work, because that still has a row against a column (but then the other way around).

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.