Keypad used usually in most of projects to enable customer to deal with project such as (Real Time Clock (RTC) to adjust day,time ,access control,.....etc) but if you use it with keypad library of Arduino it's so easy and not good so here we will learn how to use it with Arduino without using keypad library in 3 Tutorials

## Step 1: Components

all components we need are :
1- Arduino Uno Or Mega
2- 8 x Arduino Connection Wires (Male-Male)

## Step 2: Calculation of Index of Any Element in 4x4 Matrix

if we look to the above picture we obtain that index of any element is equal to
index=Number of Row x4 +Number Of Column

## Step 3: Connection

First Here Is The Pin configuration of keypad ....
R .... indicates the Row
C .... indicates the Column

Second Connect Keypad To Arduino As Following

Keypad Pin R1 –> Arduino Pin 2

Keypad Pin R2 –> Arduino Pin 3

Keypad Pin R3 –> Arduino Pin 4

Keypad Pin R4 –> Arduino Pin 5

Keypad Pin C1 –> Arduino Pin 6

Keypad Pin C2 –> Arduino Pin 7

Keypad Pin C3 –> Arduino Pin 8

Keypad Pin C4 –> Arduino Pin 9

## Step 4: Upload the Code and Explaining

Here The code in the link below:

http://sh.st/TwENk

To illustrate the code i will explain it in few lines:
the following instructions are repeatedly executed every 50ms first it check if no button is pressed if that's true the no press flag will be set to ONE and counters h and v will be reset to ZERO then all outputs will be LOW then check all inputs if any one of them is LOW( h became the number of column) a for loop changes first output to HIGH if the input Which Was LOW is change to HIGH That's Mean that's is the correct row of ( v became the number of row) then make all output as low to disable an pressed until you released the pressed button Reset The no press flag to ZERO and calculate the index and return it while you hold any button the no press flag is ZERO and the function return 50 and switch case used to output on serial monitor according to the return form keypad function.

<p>oh! there's no need for a response Sir. i figured it out. thank you so much for the code :D</p>
<p>why do you put return 50 at the end of the keypad function? thanks in advance.</p>
just &quot;dummy number&quot; as indication no button pressed and you welcome ☺
<p>Thanks for your answer Omar. I've tried changing that number and received different behaviours. My conclusion was that i have to put a number bigger than the last number of the list of switch (bigger than 8).. very funny. Thank you very much Omar! </p>
<p>yes yes you are right i forgot to mention this in previous comment and it must be greater than 15 not 8, you welcome </p>
Yes you are right Omar! Thank you very much for the fast answer. I said 8 cause i coded a 3x3 keypad. Your code is perfect and its a good example for inputs using the pull up resistor build up in the micro.
<p>You welcome any time, thank you ?</p>
<p>Hey Omar,</p><p>I thought I'd include these pictures of the keypad I'm using so If anyone has the same keypad as mine then they can use these pictures here (that I modified from yours) as a guide to wire theirs up and it should work with your code. And your code also works on a nano without any modifacations...</p><p>Thanks Again</p><p>jessey</p>
<p>Hello Again,</p><p>I figured it out. Part of the code didn't paste properly and I just reversed the wiring on the rows and columns and it works like a treat. Thanks again for the code....</p>
<p>alright it's awesome to hear that, and for the picture of keypad the keypad which i use it in this Instructable is like in attached image, thank you :D </p>
<p>Hi,<br>Thanks for the code but I can't seem to get it working on my Arduino Nano. I would really appreciate some help to figure out what I'm doing wrong. I hooked up <br>the keypad the same as it shows in your code using your pictures showing the rows and columns and corresponding pin numbers for the UNO. My Arduino Nano has the <br>same pins as the Uno (digital pins 2 to 9 are the same) so I thought it would work without doing anything to the code. I guess maybe I was wrong about something I did? One thing I don't understand is that the 2 pictures you have of the keypad showing R4 to R1 and C4 to C1, the keypad looks backwards, I mean the button lay outs looks upside down and inside out and you show the ribbon cable coming out the opposite end to where they should be according to the ones they sell on ebay? Any feed back<br>will be appreciated. Maybe I have my keypad wired wrong?<br>Thanks<br>jes</p>
<p>cool thanks</p>
<p>Thanks for sharing, would you mind posting the code here in instructables? the link provided is full of adware and hijack your browser.</p><p>Thanks in advance</p>