Arduino Tutorial Lesson 3.1 – Keypad and LCD


In the previous tutorial, we’ve learned how a keypad works and how to use it and the Serial Monitor to display the output. This time, we will use LCD instead of the Serial Monitor.

To make our life easier, we will use the built in LCD on the e-Gizmo development board. As you might notice in the previous tutorials about Keypad and LCD, the keypad takes 7 I/O pins and the LCD takes 6 I/O pins so combining them together will require 13 digital I/O pins on our Arduino. Yes we have 14 digital I/O pins from digital pin 0 to 13 but normally we don’t use digital pins 0 and 1 (unless necessary) because they are dedicated to TX and RX. Every time the board initializes, it triggers the TX and RX and so if we have something connected to it we will have false triggers. So we can only use digital pins 2 – 13. But don’t worry we can use the analog pins as digital and that’s exactly what we will do to complete our 13 I/O pins requirement. We will use analog pin A0 as digital pin 14. Let’s try that.



/* Numeric keypad and LCD
   Uses e-gizmo development board
   Uses analog pin as digital pin
   Uses Keypad and LCD libraries for Arduino

   LCD Connection
 * LCD RS pin to digital pin 14 (analog pin A0)//using analog pin as digital pin
 * LCD Enable pin to digital pin 13
 * LCD D4 pin to digital pin 12
 * LCD D6 pin to digital pin 11
 * LCD D7 pin to digital pin 10
 * LCD D8 pin to digital pin 9
 * LCD R/W pin to ground

   Keypad Connection
 * ROW0 to digital pin 5
 * ROW1 to digital pin 4
 * ROW2 to digital pin 3
 * ROW3 to digital pin 2
 * COL0 to digital pin 8
 * COL1 to digital pin 7
 * COL2 to digital pin 6

#include "Keypad.h" //call the keypad library
#include  //call the LCD library

LiquidCrystal lcd(14, 13, 12, 11, 10, 9); //initialize LCD connection

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] =

byte rowPins[ROWS] = {5, 4, 3, 2}; //initialize keypad connections
byte colPins[COLS] = {8, 7, 6};
int count=0;

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

void setup()
  lcd.begin(16, 2); //using 16x2 LCD
  lcd.print(""); //print a message on the first row

void loop()
  lcd.setCursor(0, 1); //move the cursor to the second row to display the numbers pressed
  char key = keypad.getKey(); //check if a key is pressed
  if (key != NO_KEY)
    lcd.print(key); //print it on LCD



  • Nice post. I learn something new and challenging on blogs I stumbleupon every day.
    It will always be interesting to read through articles from other authors and use something from other sites.

  • What other specific LCD models can I use and can I just use any model of the numeric keypad?

    • Any 2×16 LCD model can do. Just look for its datasheet if the pin connections are not properly labeled.
      I believe pin connections of most keypads if not all are standard. So you can use any. Also try to look for its data sheet just to make sure of its connections.

  • Throughout this great pattern of things you actually secure a B+ with regard to effort and hard work. Exactly where you confused me was first in your details. You know, it is said, details make or break the argument.. And it could not be much more accurate in this article. Having said that, permit me say to you just what did work. Your writing is definitely really persuasive and this is probably the reason why I am taking the effort to opine. I do not really make it a regular habit of doing that. Second, while I can certainly notice the jumps in reasoning you come up with, I am definitely not convinced of just how you seem to unite your details which inturn help to make your conclusion. For the moment I will subscribe to your position however hope in the foreseeable future you link your facts better.

    • Thanks for your comment. I appreciate it.
      I missed to include the explanation on how the sketch works in this specific article. Sorry for that. Ill update this article soon.

  • Heya i am for the primary time here. I found this board and I find It really helpful & it helped me out a lot. I’m hoping to offer one thing again and aid others such as you helped me.

    • Good to hear that. Tnx

    • Good to hear that. Thanks

  • Hello There. I found your weblog the use of msn. This is an extremely neatly written article. I will make sure to bookmark it and return to read extra of your useful information. Thanks for the post. I will certainly comeback.

  • hello,

    That’s a good post.thanks for sharing.

    • You’re welcome. My pleasure.

  • Hey there, I think your site might be having browser compatibility issues. When I look at your blog site in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, amazing blog!

    • Thank you for letting me know. Ill check that.

  • Can I just say what a relief to come across someone who in fact knows what theyre talking about on the internet. You definitely know easy methods to bring an concern to light and make it fundamental. More many people have to read this and comprehend this side of the story. I cant think youre not much more common simply because you surely have the gift.

    michael kors shoes on sale

  • I’m impressed, I ought to say. Seriously rarely do I encounter a blog that is both educative and entertaining, and let me tell you, you’ve hit the nail on the head. Your thought is outstanding; the concern is some thing that not sufficient many people are speaking intelligently about. I am especially happy that I stumbled across this in my search for something relating to this.

  • quite nice post, i surely adore this website, maintain on it

    cheapest jordans

  • I had this page saved a while previously but my computer crashed. I have since gotten a new one coupled with it took me a while to find this! I also actually like the template though.

  • I’ve read several good stuff here. Certainly worth bookmarking for revisiting. I surprise how much effort you put to make such a great informative web site.

    • Thank you. I’m a busy person. But doing stuff like this helps me to keep updated with technology and improve my knowledge.
      I appreciate that you like the info.

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>