Arduino 3 Wire Matrix Keypad

106,966

104

25

Posted

Introduction: 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.






 

Step 1: 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

Step 2: Wiring Up the Resistors

The next thing is to wire up the matrix of resistors.

As you can see there is one single wire to analog input pin 0 on the Arduino plus a connection to +5V on the Arduino and also one to GND (ground)....3 wires in total.

Having worked out your rows and column wires, you need to follow this diagram.

I use ribbon cable as it makes things (relatively) neat.

The tiny capacitor is there to prevent interference induced in the wires being transmitted as a voltage to the analog input producing errors.

Step 3: Test It!

If you download the first Arduino sketch on the title page of this Instructable, also attached to this page, you get a simple routine that displays the value being "read" by the analog pin 0 (on a scale of 0 - 1023) representing 0 - 5V in the serial viewer window of your PC which you need to set to 9600 Baud.

There will be slight variations depending on tolerances of the resistors but the values you get should be roughly similar to those which I obtained.

Step 4: Write Software to Read Your Kepad

If you download the second Arduino sketch on the title page of this Instructable, also attached to this page, it gives you an idea how to write code to read the keypad and do useful things with the values obtained.

In this example, when you press a key, the value on each key will appear in the serial viewer window (i.e. 0 - 9) on your PC.

You can see that there has to be some code that takes the value, then waits for you to release the key before continuing, to prevent a whole sequence appearing of the same value.

The code is a bit clunky but it works. You will have to adapt this for your own applications but it should get you started.

The variable "keypressed" is the value of 0 - 9 which you can then use in the rest of your program.

Have fun.

Share

  • Worked really well, ...-jrosenzweig1

    jrosenzweig1 made it!

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • Sew Warm Contest 2018

    Sew Warm Contest 2018
  • Gluten Free Challenge

    Gluten Free Challenge
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

24 Comments

Really useful project for all arduino users. So easy to make in a couple of hours.

Made it in a breadboard, passed to a protoboard and worked at first. Awesome !!!

Thanks a lot for so simple and useful arduino project XD

i want to ask a question..

i used '<Keypad.h>'

but when i compiled error come and said: keypad.h No such file or directory..

why? can you help me

did u use 1% tolerance resistors?

I got different values on the ADC measures

i made a prototype for my project thanks so much for the ez keypad that gives me free pins for other stuff :D

it was so helpful

i had to change some resistors because i didn't have but it worked well

thank you so much

and sorry for my bad English

Tayeb

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

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.

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

Thanks in advance

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

Thanks I'll try this out.