Keypad with LCD Display — Arduino Uno simulation

Arduino Uno with membrane keypad and I2C LCD - keypad not responding to key presses

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by itsmebenn.

Components

Sketch code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2); 

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'}
};

// Connect to the row pinouts of the keypad
byte rowPins[ROWS] = {9, 8, 7, 6}; 
// Connect to the column pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; 

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

void setup() {
  Serial.begin(117647);
  lcd.init();                     // initialize the lcd
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Press a key:");
}

void loop() {
  char key = keypad.getKey();
  if (key) {
    Serial.print("Got key: "); Serial.println(key);  // <-- add this
    lcd.setCursor(0, 1);
    lcd.print("Key: ");
    lcd.print(key);
  }
}

More projects by itsmebenn