Numbers not showing up on LCD screen

I'm trying to use a 3x4 keypad to enter numbers to be shown on the LCD screen. There is no errors poping up, but the lcd only displays the line of press a key and the keypad doesn't seem to be working.
The lcd is a 1602 module and the keypad is a 3x4 Keypad MCU Board.

#include <Keypad.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal.h>
const int RS = 11, EN = 12, D4 = 2, D5 = 3, D6 = 4, D7 = 5;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
char keys[4][3] = {
 {'1','2','3'},
 {'4','5','6'},
 {'7','8','9'},
 {'*','0','#'}
};
byte rowPins[4] = {12, 5, 6, 10}; //connect to the row pinouts of the keypad
byte colPins[3] = {11, 7, 9}; //connect to the column pinouts of the keypad

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

void setup(void) {
lcd.begin(16, 2); // Initialize the LCD
 lcd.setCursor(0, 0);
 lcd.print("Press a key:");
}
void loop(void) {
char key = keypad.getKey();
 
 if (key){
   lcd.setCursor(0, 1); // set cursor to second line
   lcd.print("Pressed Key: ");
   lcd.print(key);
   delay(2000); // Display the pressed key for 2 second
   lcd.setCursor(0, 1); // Clear the pressed key
   lcd.print("");
lcd.print(millis()/1000);
   }
}

Can you please clarify which pins are used for the keypad and which are used for the LCD?

and once you have sorted the pins that you seem to use for two purposes, fix also

one is enough for a nice looking code , especially if you indent the rest of the code :slight_smile:

the delay will make your code not responsive, you might want to look at

Those constants are supposed to be the pins used for the LCD, like this

LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);

but then you seem to be using some other pins in the next line.

It's the pin numbers in the second line that actually get used. The pin numbers in the first line are not used.

Either way, there is an overlap between the pins for the LCD and the pins for the keypad.

1 Like

Post an annotated schematic so we can sort this out. Be sure to show all connections and devices including all power sources.

Not this... (too many LiquidCrystal.h)

Do this... (remove one LiquidCrystsl.h)

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

Not this... (LCD pin definitions are a mess)

Do this... (LCD needs not-yet-defined pins)

const int RS = 7, EN = 8, D4 = 9, D5 = 10, D6 = 11, D7 = 12;

Not this... (keypad pin definitions are a mess)

Do this... (re-wire your keypad to match these pins)

byte rowPins[4] = {13, A0, A1, A2}; //connect to the row pinouts of the keypad
byte colPins[3] = {A3, A4, A5}; //connect to the column pinouts of the keypad

Not this... (delay stops the keypad read, setCursor does NOT clear the pressed key, all useless)

Do this... ("comment-out) the useless stuff)

  if (key) {
    lcd.setCursor(0, 1); // set cursor to second line
    lcd.print("Pressed Key: ");
    lcd.print(key);
    // delay(2000); // Display the pressed key for 2 second
    // lcd.setCursor(0, 10); // Clear the pressed key
    // lcd.print("");
    // lcd.print(millis() / 1000);
  }

Fin.

The problem has been solved. The issue was caused by the wringing.
I have one more question though, how can i get this code to display 7 consecutive key inputs at the same time?

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