Instructables

Arduino 3 wire Matrix Keypad

Picture of Arduino 3 wire Matrix Keypad

Keypad connected with only 3 wires to Arduino.

Background:

A matrix keypad can be connected to an Arduino board so that numerical data can be entered by the user.
Instructions exist in various forums on how to do this. The main problem is that this usually uses up a total of 7 of your digital input/output pins.

The problem:
For me this is a big problem as I want these pins free to control external devices such as solenoid valves and actuators. I also need some to send data to a serial LCD display.

Options are either
a) Use an Arduino Mega with lots more pins or
b) Find a way of interfacing a keypad using less input pins.

Solution:
By using ONE single analog input pin and a grid of resistors, we can wire up the buttons on the keypad such that when each is pressed a different voltage is sent to the analog input pin.

Although it is a hassle wiring up all the resistors, the big advantage is that all your digital pins remain free to be used for other things.

This has been described before on AVR forums but I have adapted it for Arduino and written some code for you to get started.






 

 
Remove these adsRemove these ads by Signing Up

Step 1: Identify the keypad pins

Picture of Identify the keypad pins
On base of keypad are 7 solder terminals.

Keypad can be considered to have 3 "columns" and 4 "rows" - see photo.

First step is to work out which solder terminal represents each row and which represents each column. Write everything down as you go along, very easy to mix everything up.

This has been described and you need to follow the instructions on how to do this given in this Arduino keypad tutorial:

http://www.arduino.cc/playground/Main/KeypadTutorial

macogala7 days ago

Hi! First of all thank you because this may be really useful.

Second, I have a question. I haven't tried this project yet, but as far as I've understood it, it's nothing but a Voltage Partitor. Now, I wonder if you have provided some kind of control regarding the possibility of multiple keys pressed, because I think there may be some problems if I press 2 or more keys at the same time.

In this case, obviously, the voltage wouldn't split as it is supposed to be, but I guess it may even be splitted in such a way that, for the Arduino, it corresponds to a completely different key. Am I right? And if so, have you thought about a solution regarding this?

Thank you very much,

Marco

osdoyi7 months ago
I am using 4x4 matrix display and tried your way. But only the last row (*,0,#,D) is responding. The others not. Do you have any suggestion ? In the capacitor connected side i used 1000ohm, 890ohm,1000ohm and 890ohm resistors.
marcoboers osdoyi2 months ago

Do you have it working in the mean time? And what resistor values did you use?

Thanks in advance

osdoyi marcoboers2 months ago

Yeap I solved it. In schematics I add one more resistor in this order: 1000 ohms, 820
ohms, 1000 ohms, and 820 ohms.

marcoboers osdoyi2 months ago

Thanks I'll try this out.

tumbledown1 year ago
Hi Just put your circuit together and got the testsketch1 to work but can not get the keyboardreaderdemo to display on the serial monitor, any iders?.

its a wet and windy Sunday here in the UK and nothing else to do?
roachburn2 years ago
How do i get it to display the * or the # signs?
Has anyone actually done this? I'd love to see pictures of the end result.
thiagottjv2 years ago
Can i use another capacitor size? like a 100nf?
And the resistors? how did you calculate the sizes?
XenonJohn (author)  thiagottjv2 years ago
Capacitor, probably other values work. It helps debounce the keys I think.

The resistor values were borrowed from a post on similar topic on the AVR forums.

Best wishes

John
Data6433 years ago
(removed by author or community request)
XenonJohn (author)  Data6432 years ago
OK I will go and shoot myself then for wasting your time.

If you turn it over you see that several of the apparent solder terminals don't do anything and there are 7 active terminals.
budabob072 years ago
Very clever. Great way to save pins without using shift registers or other IC's
Wouldn't it be a lot simpler to do this with a parallel-in shift register? That would only use three pins, and you could do the same thing with parallel-out regs for outputs. Granted, it would cost a little more.
yes8s3 years ago
There is an error with your diagram above. The "1500 Ohm" resistor should actually be "15000 Ohm".
XenonJohn (author)  yes8s3 years ago
Thanks for spotting this.

I have changed the diagram to 15000 Ohm.

Best wishes

John
doby1623 years ago
I thought about doing this before. I guess since the keypad was only going to be for one project and it only needed a couple other pins I just took the lasy way out =). Well implemented though, I definantly think this shouldev been featured.
nadav3 years ago
WOW! how this didnt get featured is beyond me... Great 'ible thanks. -Nadav
XenonJohn (author)  nadav3 years ago
It's the weekend maybe! Also, until you have personally come up against the "running out of pins" problem you wouldn't realise it is a problem at all. John
nadav XenonJohn3 years ago
yeah, i always like to think ahead just incase there are upgrades to the project im doing. especially if its going to be permanent..
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!