DS 16038
DS 16038
DS 16038
Features
Ultra-thin design
Adhesive backing
Excellent price/performance ratio
Easy interface to any microcontroller
Example programs provided for the BASIC
Stamp 2 and Propeller P8X32A
microcontrollers
Key Specifications
Maximum Rating: 24 VDC, 30 mA
Interface: 8-pin access to 4x4 matrix
Operating temperature: 32 to 122 °F
(0 to 50°C)
Dimensions:
Keypad, 2.7 x 3.0 in (6.9 x 7.6 cm)
Cable: 0.78 x 3.5 in (2.0 x 8.8 cm)
Application Ideas
Security systems
Menu selection
Data entry for embedded systems
Copyright © Parallax Inc. 4x4 Matrix Membrane Keypad (#27899) v1.2 12/16/2011 Page 1 of 5
How it Works
Matrix keypads use a combination of four rows and four columns to provide button states to the host
device, typically a microcontroller. Underneath each key is a pushbutton, with one end connected to one
row, and the other end connected to one column. These connections are shown in Figure 1.
In order for the microcontroller to determine which button is pressed, it first needs to pull each of the
four columns (pins 1-4) either low or high one at a time, and then poll the states of the four rows
(pins 5-8). Depending on the states of the columns, the microcontroller can tell which button is pressed.
For example, say your program pulls all four columns low and then pulls the first row high. It then reads
the input states of each column, and reads pin 1 high. This means that a contact has been made
between column 4 and row 1, so button ‘A’ has been pressed.
Copyright © Parallax Inc. 4x4 Matrix Membrane Keypad (#27899) v1.2 12/16/2011 Page 2 of 5
Connection Diagrams
Figure 2
Figure 3
' 4x4MatrixKeypad_Demo.bs2
' Display buttons pressed on the 4x4 Matrix Membrane Keypad
' Author: Parallax HK Engineering
DO
GOSUB ReadKeypad ' Read keypad button states
DEBUG HOME, BIN16 keypad, CR, CR, ' Display 16-bit keypad value
BIN4 keypad >> 12,CR, ' Display 1st row 4-bit keypad value
BIN4 keypad >> 8, CR, ' Display 2nd row 4-bit keypad value
BIN4 keypad >> 4, CR, ' Display 3rd row 4-bit keypad value
BIN4 keypad ' Display 4th row 4-bit keypad value
Copyright © Parallax Inc. 4x4 Matrix Membrane Keypad (#27899) v1.2 12/16/2011 Page 3 of 5
IF keypad <> keypadOld THEN ' If different button is pressed,
GOSUB Update ' update the keypad graphic to clear
ENDIF ' old display
FOR row = 0 TO 3
DIRB = %1111 ' Set columns (P7-P4) as outputs
OUTB = %0000 ' Pull columns low (act as pull down)
OUTA = 1 << row ' Set rows high one by one
DIRA = 1 << row
Copyright © Parallax Inc. 4x4 Matrix Membrane Keypad (#27899) v1.2 12/16/2011 Page 4 of 5
IF Keypad.BIT4 THEN DEBUG CRSRXY, 14,12,"C"
IF KeyPad.BIT3 THEN DEBUG CRSRXY, 02,14,"*"
IF Keypad.BIT2 THEN DEBUG CRSRXY, 06,14,"0"
IF KeyPad.BIT1 THEN DEBUG CRSRXY, 10,14,"#"
IF Keypad.BIT0 THEN DEBUG CRSRXY, 14,14,"D"
RETURN
Note: This application uses the 4x4 Keypad Reader.spin object. It also uses the Parallax Serial Terminal
to display the device output. Both objects and the Parallax Serial Terminal itself are included with the
with the Propeller Tool v1.2.7 or higher, which is available from the Downloads link at
www.parallax.com/Propeller.
Revision History
v1.0: original document
v1.1: Updated Figure 1 on page 2
v1.2: Updated Figure 1 on page 2 (again); updated BS2 comments
Copyright © Parallax Inc. 4x4 Matrix Membrane Keypad (#27899) v1.2 12/16/2011 Page 5 of 5
Mouser Electronics
Authorized Distributor
Parallax:
27899