Matrix Keypad with fewer pins?

I've been looking around, and have seen this question asked, seen dicussions about analog, but haven't really seen a definite answer: Can I connect a 4x3 keypad with fewer than 7 pins?

Yes. Folks have devised ways to make voltage dividers such that you can get 12 unique voltages for the 12 buttons (not sure what happened if multiple buttons were pressed). There were some good solutions to this in the old forum, I'd guess in the Nov/Dec 2010 timeframe. I myself used a 4x4 keypad and 8 pins, using the keypad library for debouncing and a DIODE AND function to allow a keypress to create an interrupt from powerdown sleep mode. I used it for a remote, so didn't to save pins for other things.

What do you have in mind?

Check #9, click the British flag to get the Spanish page link in English. Not sure if can be done with a 4x3 matrix keypad, but is pretty clever.

see this:

Only 4 pins, and 2 of those are just supply pins. So really 2 pins!


And just 1 chip vs a bunch of resistors. Can it be procured in a DIP?

I'm wanting to use an LCD which takes 6-7 pins, and a 4x3 keybaord, 7 more pins, and run a solenoid... Most things I've come across that use another chip, I look for the chip and it cost $10! considering my Arnuino was only $20, that's just kinda high. this PCF8574 looks like it's only a few dollars, I'll search around for how it works...

As you want an LCD as well, How about one of the Serial/I2C controllers with combined support for the keypad. Then its just 2 pins plus supply and ground. Includes all the backlighting and contrast adjustment.

Libraries available as well. Ive had a play and it works well.


"LCD which takes 6-7 pins, and a 4x3 keybaord, 7 more pins, and run a solenoid" So you're up 15 pins, out of 19 available (A0-A5 are accessible as D14-D19). Leave D0/D1 out for serial Rx/Tx still leaves 2 free. Sounds like your're ok without having to add external chips.

"LCD which takes 6-7 pins, and a 4x3 keybaord, 7 more pins, and run a solenoid" So you're up 15 pins, out of 19 available (A0-A5 are accessible as D14-D19). Leave D0/D1 out for serial Rx/Tx still leaves 2 free. Sounds like your're ok without having to add external chips

...I wondered about that, so A0-A5 can be used... I may be alright, then. I just looked at the Serial/I2C mentioned. This looks pretty nice. So it runs the LCD display, and the keypad? Here's what I've ordered, will it work with them? A 1602 LCD w/backlight:

A keypad:

I'll have to find out more about Serial/I2C controllers

Whatever I2C is, (Does the Arnuino Uno have I2C?) It looks like it'd take a long time to figure out. So I'm hoping I have enough pins...

Take a look here
The keypad does not appear to be I2C, the keypad library should be enough for that.
I2C is pretty straight forward, you use the Wired.h library to send out serial commands, similar to shiftout but there are dedicated hardware pins.

Here is some of the code I set up for a max6953, which has an I2C interface, for example:

 Using IIC (I2C) for interfacing to MAX6953
 *  Arduino analog 5 - I2C SCL, pin 24
 *  Arduino analog 4 - I2C SDA, pin 23
#include <Wire.h>  // bring in Wire Library

//  I2C device address is 1 0 1   A3 A2 A1 A0  with AD1, AD0 both low
#define COMMAND_ADDRESS 0x50 // (B1010000)
#define CONFIG_ADDRESS 0x04
#define INTENSITY10_ADDRESS 0x01
#define INTENSITY32_ADDRESS 0x02
#define DIGIT0_ADDRESS 0x20 // write both Plane 0
#define DIGIT1_ADDRESS 0x21 // write both Plane 0
#define DIGIT2_ADDRESS 0x22 // write both Plane 0
#define DIGIT3_ADDRESS 0x23 // write both Plane 0
 // start up I2C, uses Analog 5 for Clock, Analog 4 for data
  Wire.begin(); // nothing in () because we are the master

  //  write config register
  // 0000 0001 => 0 shutdown, 1 = normal mode, no fooling with blink modes & stuff
  // 0000 0010 = not used
  // 0000 0100 => 0  slow blink, 1 = fast blink
  // 0000 1000 => 0 = global blink disabled (Plane 1 data ignored), 1  global blink enabled Plane 1 data used)
  // 0001 0000 => 0 = blink unaffected during I2C acknowledge
  // 0010 0000 => 0 = data unaffected during I2C ack, 1 = data cleared
  // 0100 0000 => not used
  // 1000 0000 => blank phase - blink status is read back
  // for this use: 0000 0101 => normal operation, fast blink


  //  write intensity10 register
  Wire.send(0xEE);  //  E = 15/16 (max)

  // write intensity32 register
  Wire.send(0xEE);  //  E = 15/16 (max)

I havnt used that keypad but if its got the usual pinouts it should be fine with that I2C controller. The lcd is fine as well, or you could use a similar 4x20.

There are loads of examples for using the keypad and lcd through I2C.


Crossroads, I'm a bit confused, that link doesn't seem to say anything about I2C, (or a keypad you mentioned)...

I get 8x6 key matrix plus 8bit parallel alph-numeric LCD using a bit of lateral thinking :)

Use the 8 data pins for the LCD as the diode isolated 'drive' pins for the keypad matrix. Scan these in a tight loop between screen updates.

When not actually writing to the screen, the EN line will be low so no risk of sending obscure characters to the screen, and when you're not actually scanning the key matrix it doesn't matter how much the lines wiggle about. Also with a couple of simple arrays you can get the state of every single key simultaneously (sort of).

Program up a chip, and dedicate it to this on a breadboard with just a cheap 16MHz resonator and a few resistors and caps. I pass data in and out via direct serial connections between a couple of these and a mega.

To keep comms to the minimum everything is in single byte commands. I don't need to display top-bit characters so 128+n is top row cursor position, 160+b 2nd row cursor etc. (4x20 display). 12 is clear screen (like the old terminals). 20 is flash cursor, 21 is steady cursor and 22 is cursor off. Chars 32 to 126 are normal printables.

For the keypad side, 128+n gives row/column key-down and 192+n gives corresponding key-up. Chars 32 to 126 are kept clear so the keypad/display module can send a wake-up message.