Arduino Keypad 4x4 Tutorial

23,004

45

11

About: Currently am studying in CSE...interested in A.I. and robotics...

Intro: Arduino Keypad 4x4 Tutorial

Keypad input showed to serial monitor with arduino uno and 4x4 keypad full code...

Step 1: Connecting With Arduino

Connecting keypad with aruduino digital pins:

Keypad Pin Connects to Arduino Pin

1 D9

2 D8

3 D7

4 D6

5 D5

6 D4

7 D3

8 D2

Step 2: Code

CODE :

#include <Keypad.h>

const byte numRows= 4

const byte numCols= 4;

keymap[numRows][numCols]= { {'1', '2', '3', 'A'},

{'4', '5', '6', 'B'},

{'7', '8', '9', 'C'},

{'*', '0', '#', 'D'} };

byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3

byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3

//initializes an instance of the Keypad class

Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

void setup() {

Serial.begin(9600);

}

//If key is pressed, this key is stored in 'keypressed' variable //If key is not equal to 'NO_KEY', then this key is printed out //if count=17, then count is reset back to 0 (this means no key is pressed during the whole keypad scan process

void loop() {

char keypressed = myKeypad.getKey();

if (keypressed != NO_KEY)

{

Serial.print(keypressed);

}

}

Step 3:

here is my blogspot link it has some extra diagram which you might find helpfull... blogspot link

Step 4: Adding Library

Adding the library :

To add the library go to Skeetches -->>Include library--> Type the libray name "keypad" then press install.Then upload the sketch to your arduino.
Here's Some optional link :

wordpress blog

Blog spot

2 People Made This Project!

Recommendations

  • Metalworking Contest

    Metalworking Contest
  • Audio Contest 2018

    Audio Contest 2018
  • Tiny Home Contest

    Tiny Home Contest

11 Discussions

0
None
AntoninR3

Question 6 months ago on Step 1

Error message: No such file or directory

0
None
RiangieE

7 months ago

What are the materials needed to make that happen thing?

0
None
xtbynu

8 months ago

Error message:
" 'keymap' does not name a type"

1 reply
0
None
AzwadAxtbynu

Reply 8 months ago

put "char" (without quotation) in front that line.

0
None
ايادق

8 months ago

Thank You very much...

0
None
keval mistry

1 year ago

i tried a lot for connecting the keypad in the above given way but it showed no output in serial monitor, i think this technique does not work

1 reply
0
None
SiamHkeval mistry

Reply 1 year ago

Are you using arduino uno? can you please upload a pic of the connections you made. i guess you misunderstood the pin 8 of your keypad as pin 1 at the very beginning i made that mistake too... i would like to help you out...Thanks

0
None
jkj56

1 year ago

If you wan't to save four arduino pins you can use way: http://forum.arduino.cc/index.php?topic=141978.0 it's only require eight extra cheap diodes.

1 reply