Arduino Keypad 4x4 Tutorial

80,597

54

17

Introduction: Arduino Keypad 4x4 Tutorial

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

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

Supplies

Arduino uno x 1

4x4 Keypad

All these can be found on this site:

BDSpeedy Tech Parts

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

3 People Made This Project!

Recommendations

  • Fandom Contest

    Fandom Contest
  • Microcontroller Contest

    Microcontroller Contest
  • Teach With Tinkercad Contest

    Teach With Tinkercad Contest

17 Comments

0
kb3cxegmatgmaildotcom
kb3cxegmatgmaildotcom

Question 7 days ago on Step 2

Dear SiamH,
This is nicely laid out. Good work. My question is this. I am trying to use a 4x4 keypad for numeric input to a CNC morticing machine. I need to input float values such as 1.25", 2.5" and anything in-between. Can I do such a thing with a 4x4 keypad, or am I asking too much?
Thank you,
Roland

0
RiangieE
RiangieE

4 years ago

What are the materials needed to make that happen thing?

0
imLuc
imLuc

Reply 10 months ago

2 Arduino UNO
1 Keypad 4*4
1 bread board
1 relay SPDT
1 light bulb
1 power supply
4 resistors
4 LED

0
jessey
jessey

2 years ago

I don't understand. What's the point of this project, what does it do? Whats a practicable application for this code?

0
JILSS
JILSS

Question 3 years ago on Step 2

what is const byte

1
xelast
xelast

Answer 3 years ago

const means constant - you can't change the value once set,
byte - it can only be one byte of storage long
const byte - a one byte long value that cannot be changed

0
AntoninR3
AntoninR3

Question 4 years ago on Step 1

Error message: No such file or directory

1
xtbynu
xtbynu

4 years ago

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

1
AzwadA
AzwadA

Reply 4 years ago

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

0
ايادق
ايادق

4 years ago

Thank You very much...

0
keval mistry
keval mistry

5 years 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
SiamH
SiamH

Reply 5 years 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
jkj56
jkj56

5 years 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.

0
SiamH
SiamH

Reply 5 years ago

Thanks :)

1
DIY Hacks and How Tos

This would be a great way to make your own DIY keypad security lock.

1
SiamH
SiamH

Reply 5 years ago

Thanks for your query ill upload it soon...stay connected..