www.nutsvolts.com/index.php?/magazine/article/october2010_PICAXEPrimer
*Pin Connection
1 Row 2
2 Row 3
3 Column 1
4 Row 4
5 Column 2
6 Column 3
7 Column 4
8 Row 1
From left to right
■ FIGURE 1. Schematic of 4 x 4
matrix keypad.
■ FIGURE 2. Pinout for 4 x 4
matrix keypad.
when declaring “overlapping” word
and byte variables.
■ FIGURE 3.
Resistor/matrix
circuit.
NEW BUSINESS
There’s another bit of information
I want to share with everyone. I’m
pleased to announce the recent
publication of my first book,
PICAXE® Microcontroller Projects for
the Evil Genius. By the time you read
this, it will be available at the NV
Webstore ( http://store.nutsvolts.com).
In addition to simply being a
shameless plug for the book, I’m also
mentioning it here because I need to
include the following statement:
Portions of the following project are
excerpted from the book with
permission from McGraw-Hill.
INTERFACING A 4 X 4
MATRIX KEYPAD
68 October 2010
Actually, the Evil Genius book
includes three different projects that
involve a matrix keypad. We’re going to
be focusing on a variation of the first
project, but when we have finished
I’ll also include some information on
what we did next in the book. We’ll
be using the same keypad from the
book’s projects (a 4 x 4 matrix), but you
certainly can adapt the project for use
with a 4 x 3 matrix keypad if you prefer.
The standard arrangement for a 4
x 4 matrix keypad is shown in Figure 1.
Whenever a key is pressed, the
connections for the corresponding row
and column are shorted together; for
example, pressing the “ 6” key connects
the pins for row 2 and column
USING AN ADC
APPROACH TO
DECODING MATRIX
KEYPADS
The ADC approach to decoding
a matrix keypad employs a resistor
matrix to produce an analog voltage
level that differs for each possible
key-press. (The output voltage remains
at ground level as long as no key is
pressed.) The analog voltage is
connected to an ADC input and the
processor simply converts the resulting
voltage level back to the corresponding
keypress. Figure 3 presents one
possible arrangement for a resistor
matrix that can be used in the ADC
approach to keypad decoding.
As you can see, each possible
key-press connects one, two, or three
resistors in series between the +5V
line and ground. By carefully
choosing the values of the seven
resistors in the layout, it’s possible to
produce 16 voltage levels that are
spread out far enough to easily
differentiate. I would like to be able
to say that I used a sophisticated
mathematical formula to determine
the required resistor values, but I
actually used a more primitive “trial