Matrix keypad help! (Keypad.h) [SOLVED]

Hey all,

I didn't think I'd ever have to post a topic like this again after my first few months of using Arduino, but how wrong I was! Despite having used the Keypad library in projects before, I seem to have forgotten how to use it.

Here is my code:

#include <Keypad.h>

const int ROWS = 4; //four rows
const int COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};

byte rowPins[ROWS] = {12, 13, 4, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 10, 11}; //connect to the column pinouts of the keypad

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

void setup(){

}
 
void loop(){
  byte key = kpd.getKey();
  //Serial.println(key); 
  if (key != NO_KEY){
    Serial.println(key);
  }
}

As you can see it's pretty much identical to the example provided for the keypad library, save for the pin assignments. Trust me when I say this: I have checked and double checked my wiring and it agrees with the rows and columns pin assignments. I have the three COL pins connected to 5v through 10K pull ups.

Running the example code gives me strange results. First, no matter how many key presses I make, there is no output on the serial monitor. Second, when pressing any buttons on ROW 1 (Arduino pin 13), I can see the LED (the on-board LED connected to pin13) on my Arduino Uno board light up. Otherwise it is lit up very faintly.

I really cant understand what's going on here, even code I used successfully in the past is not working and I can not understand why. Would really appreciate it if someone could lend some advice.

Thanks,
B

EDIT: the keypad itself is functional as well, continuity testing with a multimeter is as expected.

Have you used pin 13 as a row pin before ? It is used to drive the on board LED which involves resistor on the board which can interfere when using it as an input. Can you try the keypad with a pin other than 13 ?

I can't recall if I've ever tried pin 13 before, but I can find no evidence for why this shouldnt work. After a little Google-fu i've found that there should be no issue using pin 13 as an input.

I get the same behavior when using it on a breadboard, so pin 13 is definitely not the issue. Thanks for the suggestion though!

Any other ideas?

Which Uno do you have? Recent ones have the LED driven via an op-amp. That shouldn't affect your results but might explain the LED lighting up.

Nick, I have an UNO R2, the same one that I got started on over a year ago!

UGH!!!

I suppose Serial.begin(9600); might have been a good idea :blush:

UKHeliBob,

While I've got the keypad working, I experimented a bit on my Uno (rather than on a standalone) and it seems that the Uno does indeed have problems using pin 13 with the keypad.

After a little experimenting, I found that pin 13 works if I use it as a column pin (remember the 10K pullups on the columns?), but when connected as a row pin, it spits out seemingly random output, i.e. a key is constantly being pressed.

Didn't see any mention of this online, but it seems like you were on the right track.

boredat20:
Nick, I have an UNO R2, the same one that I got started on over a year ago!

On the R2 (I think I have the right circuit) there is a path to ground from pin 13 via a resistor and the on-board LED.

That could account for your problem. Also why it is glowing faintly.

I think the keypad library enables the internal pull-ups which would account for the glow.

hey, Nick Gammon,

could you help me on a problem

here is the link: rc car program not working!! - Programming Questions - Arduino Forum

thanks!!