I have a problem with the Arduino Uno.

I need to use a 4x3 keypad and 16x2 LCD together with an Arduino Uno. As 4x3 keypad requires 7 pins, I have defined pins 2, 3, 4, 5, 6, 7 and 8 to it. A 16x2 LCD requires 6 pins but only 5 pins remain (9, 10, 11, 12 and 13). Pins 0 and 1 are used for serial.

Please suggest a probable solution.

  • Welcome to Arduino SE! What exactly is your issue? Pin assignment? Please edit your question to reflect exactly what you need. Thanks! Mar 21, 2015 at 14:50

2 Answers 2


You could use a shift register to read the switches as outlined by the excellent tutorial Parallel to Serial Shifting-In with a CD4021BE. Quoting the summary:

Sometimes you'll end up needing more digital input than the 13 pins on your Arduino board can readily handle. Using a parallel to serial shift register allows you collect information from 8 or more switches while only using 3 of the pins on your Arduino.

So you would only use 3 pins to read the seven switches, which would leave you with 9 pins to play with, for the LCD.

In addition, you could use a similar method for the LCD, using a shift-out register, and use just 3 pins for the 6 inputs of the LCD. A tutorial for that is Alphanumeric LCD with Shift Register on Arduino – part 1, using the AlphaLCD library or 3-Wire Serial LCD using a Shift Register, which has no library, but provides code.

This would leave you with 6 pins free (out of the total 12 pins, if you exclude pins 0 and 1 for serial), after both the switches and LCD are wired up.

Of course, this solution requires you to purchase one or two shift (in and/or out) registers.

The Arduino IDE may come with a built-in library that use shift registers, but I am not sure about that. Maybe someone can confirm, or refute, this?

I hope that this helps.

  • Is there any tutorial for LCD and CD4021 using Arduino LCD Library?
    – xcoder
    Mar 22, 2015 at 1:08
  • @xcoder - I've updated my answer. Mar 22, 2015 at 5:21

Am new at this but I am working on a similar work, it is possible to use the pin 0 for your keypad, the pin is a RX pin by default making the pins(0,2,3,4,5,6,7).

As for the LCD I would suggest you use an i2c backpack, it is a parallel to serial converter and means you would only need to use 2 pins (SDA, SCL which would be connected to pin A4, A5)

Try the code below for the keypad (The code is if you have an i2c backpack)

#include <Wire.h>
#include <Keypad.h> //keypad library
#include <LiquidCrystal_I2C.h> //library for the backpack

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns

//define the Symbols on the buttons of the keypads
  char hexaKeys[COLS][ROWS] = {

byte rowPins[ROWS] = {0, 2, 3, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 6, 7, 8}; //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(){
  for(int i = 0; i< 3; i++)
    lcd.backlight();  delay(250);
    lcd.noBacklight();  delay(250);

void loop(){

  char customKey = customKeypad.getKey();

  if (customKey){

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.