Keypad not working with Arduino Nano/ always a 1 in Serial Monitor

Hello Community.

I am working on a 8 Channel Relay which i want to activate by a generic Keypad.
I was working with a Arduino Mega 2560R3 before and everything worked fine untill i accidently connected Vcc and Gnd on the Relay Module with an Jumper and it all stopped working :confused: . So i got a new Relay Module and a Arduino Nano for spacial reasons.

When i upload the Code below (Pins have been changed from Mega2560R3 Pins previously), it uploads without error, but the Serial Monitor only displays a 1, right after uploading the Code without pressing a button. Nothing else, even when pressing any key. The relay is not connected atm.

Did i miss something i have to do when switching boards or something like that? I would appreciate some help, this project is only backfiring :slight_smile:

Right COM/ Right Board/ Right chip selected, Chip driver installed/ Programmer: AVRISP mkll/ Jumper wires checked

#include <Key.h>
#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;
char keys [ROWS][COLS] = {
  {'1','2','3', 'A'},
  {'4','5','6', 'B'},
  {'*','0','#', 'D'},
  {'7','8','9', 'C'}
byte rowPins[ROWS] = {13,A1,A2,A3};
byte colPins[COLS] = {A4,A5,A6,A7};
Keypad myKey= Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

 #define RELAY1 2
 #define RELAY2 3
 #define RELAY3 4
 #define RELAY4 5
 #define RELAY5 6
 #define RELAY6 7
 #define RELAY7 8
 #define RELAY8 9
 #define Key1 13
 #define Key2 A1
 #define Key3 A2
 #define Key4 A3
 #define Key5 A4
 #define Key6 A5
 #define Key7 A6
 #define Key8 A7
void setup()
 pinMode(RELAY1, OUTPUT);
 pinMode(RELAY2, OUTPUT);
 pinMode(RELAY3, OUTPUT);
 pinMode(RELAY4, OUTPUT);
 pinMode(RELAY5, OUTPUT);
 pinMode(RELAY6, OUTPUT);
 pinMode(RELAY7, OUTPUT);
 pinMode(RELAY8, OUTPUT);

 pinMode(Key1, INPUT);
 pinMode(Key2, INPUT);
 pinMode(Key3, INPUT);
 pinMode(Key4, INPUT);
 pinMode(Key5, INPUT);
 pinMode(Key6, INPUT);
 pinMode(Key7, INPUT);
 pinMode(Key8, INPUT);

 digitalWrite(RELAY1,HIGH); // This will Turn the Relay Off
 digitalWrite(RELAY2,HIGH); // This will Turn the Relay Off
 digitalWrite(RELAY3,HIGH); // This will Turn the Relay Off
 digitalWrite(RELAY4,HIGH); // This will Turn the Relay Off
 digitalWrite(RELAY5,HIGH); // This will Turn the Relay Off
 digitalWrite(RELAY6,HIGH); // This will Turn the Relay Off
 digitalWrite(RELAY7,HIGH); // This will Turn the Relay Off
 digitalWrite(RELAY8,HIGH); // This will Turn the Relay Off
void loop(){
  {char keypressed = myKey.getKey();
  if (keypressed){Serial.println(keypressed);}}
 char keypressed = myKey.getKey();
 if (keypressed == '1'){
  digitalWrite(RELAY1, LOW);}
 if (keypressed == '2'){ 
  digitalWrite(RELAY1, HIGH); // Relay 1
 if (keypressed == '4'){
  digitalWrite(RELAY2, LOW);}
 if (keypressed == '5'){ 
  digitalWrite(RELAY2, HIGH); // Relay 2
 if (keypressed == '7'){
  digitalWrite(RELAY3, LOW);}
 if (keypressed == '8'){ 
  digitalWrite(RELAY3, HIGH); // Relay 3
 if (keypressed == '*'){
  digitalWrite(RELAY4, LOW);}
 if (keypressed == '0'){ 
  digitalWrite(RELAY4, HIGH); // Relay 4
 if (keypressed == '3'){
  digitalWrite(RELAY5, LOW);}
 if (keypressed == 'A'){ 
  digitalWrite(RELAY5, HIGH); // Relay 5
 if (keypressed == '6'){
  digitalWrite(RELAY6, LOW);}
 if (keypressed == 'B'){ 
  digitalWrite(RELAY6, HIGH); // Relay 6
 if (keypressed == '9'){
  digitalWrite(RELAY7, LOW);}
 if (keypressed == 'C'){ 
  digitalWrite(RELAY7, HIGH); // Relay 7
 if (keypressed == '#'){
  digitalWrite(RELAY8, LOW);}
 if (keypressed == 'D'){ 
  digitalWrite(RELAY8, HIGH); // Relay 8

Do not use: pinMode(Key1, INPUT), The keypad library uses INPUT_PULLUP, If you use those lines of code, pin mode will be overwritten, causing the unexpected behavior. See how to use keypad with Arduino

Thank you for your reply IoT_hobbyist.

Now the problem i have is the following. Your stated cause for the incorrect function was a code segment i added later, because it didnt work proberly without pinMode ("analogkeyinputs as Input"). So i tried my Luck that way. Side Question: How could i possibly check single Pins for damage with certanty (from soldering or stuff)? Blink code with LED_BUILTIN is working btw.

suggest you get the example working

/* @file CustomKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact
|| @description
|| | Demonstrates changing the keypad size and key values.
|| #
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){

void loop(){
  char customKey = customKeypad.getKey();

  if (customKey){

Dear gcjr.

Thank you for this simple test and obvious solution. I will try it out later and report problems if observable.

So i tried it out with the digital Pins. working fine. but i need those for the 8channel Relay Module.
The way the Keypad library works with INPUT_PULLUP, how would i translate that to using the analog pins A0-A7 for my keypad? Because i now understand i cant just use pinMode (A0, INPUT). Do i have to make changes to the library?

I tried google and also read another Thread but honestly i didn't understand a bit :o Said Thread

Thank you for your time.