-1

I am working on a project on nano and want to use analog pins for 4x4 matrix keypad input. My connections are for keypad are as follows:

  • Digital pins are D10-D13 and Analog pins are A0-A3.
  • A0->14,
  • A1->15,
  • A2->16,
  • A3->17

Code is:

#include <Keypad.h> // includes the keypad library
const byte ROWS = 4; // four rows
const byte COLS = 4; // four columns
char keys[ROWS][COLS] = {
 {'1','2','3','A'},
 {'4','5','6','B'},
 {'7','8','9','C'},
 {'*','0','#','D'}
};

byte rowPins[ROWS] = {10,11,12,13}; // connect to the row pinouts of the keypad
byte colPins[COLS] = {14,15,16,17}; // connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

Can I use analog pins as I defined for keypad? Is "Keypad.h" library compatible with Arduino Nano v3.0?

  • if you want to use just a few pins, get a few cheap shift register ICs, like the 74HC165. – dandavis Apr 6 '17 at 9:40
  • Tested on Nano v3.0 and it works flawlessly with this exact code. You can't use A6 and A7 as they are analog inputs only. – KIIV Apr 6 '17 at 19:47
2

You can use the analog pins. I prefer {A0, A1, A2, A3} in the code instead of {14, 15, 16, 17}. That makes it easier to check if you connected the wires to the right pins.

Don't use pin 13 for an input with the Arduino Nano. An LED is connected to that pin. You can use that pin as an output for something else.

  • i tried that but nano is unable to take inputs from keypad. Keypad is working fine on mega. – Tanmay Yerunkar Apr 6 '17 at 6:55
  • You'd better try with another Nano if the solution Jot proposed not working. – Sener Apr 6 '17 at 7:52
  • it's working when tested separately but not with the whole 400 lines code which worked perfectly on mega. i changed pin numbers etc but no result. – Tanmay Yerunkar Apr 6 '17 at 8:17
  • Could the problem be a memory problem ? What does the compiler say about sram (dynamic) memory usage. Do you use large arrays or many String objects ? – Jot Apr 6 '17 at 8:25
  • In fact that, 4x4 keypad programming with Arduino is quite straight forward. So, I am surprised you have an issue with that . Since we can't see the entire code, it is hard to give a proper look and answer accordingly. You maybe do some debugging with some "Serial.print(yourvariable)" to see where the bottleneck is. As Jot has also mentioned that the memory is quite an issue when you use memory consuming large array or struct in the code. I am not talking about the memory used when you complied but in run time. – Sener Apr 6 '17 at 9:34
-1

The problem i was going through is because of pin number 13. Pin 13 is connected to LED and is not good option for taking input as it is connected to 3.3V internally. Because of this arduino was detecting one key pressed constantly making other key presses undetected. In this case the key was charecter *.

ADVICE: Don't use pin 13 for input!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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