Keypad taking all inputas the same

Hello!

I am making a keypad that prints to an LCD screen. I do not have a reason to keep the buttons in rows so I am only using 1 row. Whenever I press a button, the output is always '1'. Changing the first keymap value to anything else makes the output that, meaning that whatever input I give, it thinks it is the first button. I have checked my wiring and even disconnected the first button entirely but it still reads all input as the first button. The majority of the code is copied from the library's example. Here it is

#include <LiquidCrystal.h>
#include <Keypad.h>

const byte ROWS = 1;
const byte COLS = 6;

// define keymap
char keys[ROWS][COLS] = {
  {'1','2','3','4','e','c'}
};

byte rowPins[ROWS] = {3};
byte colPins[COLS] = {13, 12, 11, 10, 9, 8};

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

//set lcd pins
LiquidCrystal lcd(1, 2, 7, 6, 5, 4);

void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
}

void loop(){
  char key = keypad.getKey();
  
  if(key != NO_KEY) {
    lcd.print(char(key));
  }
}

Thanks for any help.

Welcome to the forum

LiquidCrystal lcd(1, 2, 7, 6, 5, 4);

You do not say which Arduino board you are using but if it is an AVR based board such as a Uno or Nano then it is unwise to use pin 1 because it is used by the Serial interface. I know that you are not using the Serial interface to print anything but you do have Serial.begin() in the sketch.

Hello, thank you for your reply.

I am using an Arduino Uno R3.
I was testing the output in serial first and forgot to delete that. Using serial as an output poses the same problem. Only '1' is shown.

Thanks!

Hi,
I tested the code here and it worked correctly.
See the pressed character on the serial monitor.

Hello, thank you so much for your reply.

I see it is a problem with my wiring then. I will open up a new topic for this if I do not figure it out.
Thanks again!

Hello!

I am working on a keypad using the keypad library. Whenever I push on a button, the serial monitor reads '1'. Changing the corresponding value on the keymap also changes the output, this value being the first column and the first row. Changing the dimensions of the keypad shows similar results. The library requires multiple push buttons to be connected through a single wire and also for them to be connected individually. Simulating this using a wire that can connect the buttons in series shows that the code works fine so it is not the problem. However, I only have breadboard jumper cables with me so I can not do such a thing. I have tried imitating it but for some reason, it is not working. This is my circuitry

image

Simulating my code using this circuitry in TinkerCad also shows the exact same problem.

And here is my code just in case

#include <Keypad.h>

const byte ROWS = 1;
const byte COLS = 6;

// define keymap
char keys[ROWS][COLS] = {
  {'1','2','3','4','e','c'}
};

byte rowPins[ROWS] = {3};
byte colPins[COLS] = {13, 12, 11, 10, 9, 8};

//create 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(char(key));
  }
}

Thank you for your help!

Please do not cross post. Moderator notified.

I have merged your topics @anon91845454.

In the future, please only create one topic for each distinct subject matter.

Thanks in advance for your cooperation.

Your diagram seems to show pull-down resistors and +5v connected to each of your keys. They should ONLY connect between a row pin and a column pin.

There is no good reason to run a 1x6 key matrix, that needs 7 pins (more than just connecting 6 switches straight to inputs).

If you have only six buttons, consider a 3x2 or 2x3 matrix (five pins).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.