data displaying in serial monitor is random

I am very new to Arduino and running into some issues with what is being displayed on my serial monitor… I am trying to program a 4x4 keypad and when open the serial monitor and press any number on the key pad it will most of the time display the number I press and then every time it enters a bunch of 4 entries even if I dont press #4. at times numbers won’t record or will record as a 4… or record the number pressed and then 4 enters… I feel like I am missing something I have checked the wires and I cant see any issues with any of it.
here is the sketch I am using

#include <Keypad.h>

const byte ROWS = 4; //four rows

const byte COLS = 4; //three columns

char keys[ROWS][COLS] = {

{‘1’,‘2’,‘3’,‘A’},

{‘4’,‘5’,‘6’,‘B’ },

{‘7’,‘8’,‘9’,‘C’},

{’*’,‘0’,’#’,‘D’}

};

byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad

byte colPins[COLS] = {9, 8, 7, 6}; //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);
}
}

This is the preferred way to post code in the forum. Auto formatted in the IDE then right click in the IDE, choose Copy for Forum and post here to have code tags automatically added

#include <Keypad.h>

const byte ROWS = 4; //four rows

const byte COLS = 4; //three columns

char keys[ROWS][COLS] = {

  {'1','2','3','A'},

  {'4','5','6','B' },

  {'7','8','9','C'},

  {'*','0','#','D'}

};

byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //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);
  }
}

I can see no obvious reason for the problems that you describe, but you may be interested in Keypad data entry

Obviously you should check your wiring very carefully, particularly if you are using a breadboard, as the connections to it can be loose

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.... :slight_smile: