Keypads are a part of HMI or Human Machine Interface and play really important role in a small embedded system where human interaction or human input is needed. Martix keypads are well known for their simple architecture and ease of interfacing with any microcontroller. In this part of tutorial we will learn how to interface a 4x4 matrix keypad with AVR and 8051 microcontroller. Also we will see how to program then in Assembly and C.

►Constructing a Matrix Keypad

Constuction of a keypad is really simple. As per the outline shown in the figure below we have four rows and four columns. In between each overlapping row and column line there is a key.

4x4 matrix Keypad outline

So keeping this outline we can constuct a keypad using simple SPST Switches as shown below:

4x4 matrix Keypad schematic

Now our keypad is ready, all we have to do is connect the rows and columns to a port of microcontroller and program the controller to read the input.

►Scanning a Matrix Keypad

There are many methods depending on how you connect your keypad with your controller, but the basic logic is same. We make the coloums as i/p and we drive the rows making them o/p, this whole procedure of reading the keyboard is called scanning.

In order to detect which key is pressed from the matrix, we make row lines low one by one and read the coloums. Lets say we first make Row1 low, then read the columns. If any of the key in row1 is pressed will make the corrosponding column as low i.e if second key is pressed in Row1, then column2 will give low. So we come to know that key 2 of Row1 is pressed. This is how scanning is done.

So to scan the keypad completely, we need to make rows low one by one and read the columns. If any of the button is pressed in a row, it will take the corrosponding column to a low state which tells us that a key is pressed in that row. If button 1 of a row is pressed then Column 1 will become low, if button 2 then column2 and so on...

Now lets move on to the programming part of keypad in our next section.

◄ Back to Index  |  Connecting a Keypad ►


Tue Oct 13 2015, 06:08 AM
Can anyone please help me solve these problems?
Tue Oct 06 2015, 08:22 AM
HI you looking for ideas or you have solution
Fri Oct 02 2015, 03:39 PM
poojitha: projects on wireless communication between two microcontrollers
Thu Oct 01 2015, 04:38 PM
hey! i wanted to simulate my circit using proteus. i have a sugar cube relay in my circuit....but i dont know which one is that in the device libraries of the software. any help? thankyou.
Tue Sep 29 2015, 09:40 PM
@Michal, that rocket is too heavy for itself and trust is not enough unless afterburners are fed with fuel properly.
Sat Sep 26 2015, 08:19 PM
Hello, its possible to make a amateur rocket with this engine, or something simillar, which be able to flight?
Thu Sep 24 2015, 10:38 AM
Ir Switch sir.
Wed Sep 23 2015, 01:10 AM
@engr1931 which project ?
Tue Sep 22 2015, 11:57 AM
Hello sir, is it ok to use 12.000MHz oscillator in IRswitch, because the requirement written in the post is 11.059MHz. And i use PIC1018 as an Ir receiver
Mon Sep 21 2015, 04:15 PM
Hello sir, your blog is kind of helpful for us especially students. May I know do you have the coding for decimal to binary using proteus 8. My mini project is about to convert decimal to binary just like a calculator. The output is LCD. A bit confusing is the decimal to binary coding on proteus 8. pls help thanks.



Sat Oct 10 2015, 10:49 AM
Tue Oct 06 2015, 01:02 PM
Fri Oct 02 2015, 03:28 PM
Sat Sep 26 2015, 01:26 AM
Fri Sep 25 2015, 10:57 AM
Wed Sep 23 2015, 08:13 PM
Wed Sep 16 2015, 04:55 AM
Mon Sep 14 2015, 03:06 PM


Guests: 37, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37699
Newest member: abrahmed
Forum Activity
praveenraoms Avatar
Posted By praveenraoms
Tue Oct 06 2015, 01:06 PM
hi i want to know the code to access the geographi...
sachinmm Avatar
Posted By sachinmm
Wed Sep 30 2015, 08:54 AM
how to used polling method in this?? my code is co...
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Sep 29 2015, 09:39 PM
__irq is just compiler directive to wrap IRQ routi...
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Sep 29 2015, 09:36 PM
The comment does say the time values as per the th...
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Sep 29 2015, 09:33 PM
are you testing this on Proteus? or MplabX simulat...
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Sep 29 2015, 09:31 PM
[Topic moved to ARM Development Forum]
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Sep 29 2015, 09:29 PM
start with reading datasheet. SPI interface on LPC...
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Sep 29 2015, 09:27 PM
I am not sure you've solved it or not but "USARTRe...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Sep 29 2015, 06:31 PM
i am confused in "__irq"....how it is uesd??sachin...
sachinmm Avatar
Posted By sachinmm
Tue Sep 29 2015, 11:11 AM
my I2C.c file=>>/*********************************...