when I need more than 13 digital pins :S

Hey all,

Looking at starting an project using an LCD screen and a 12-key keypad, but have stumbled across a bit of a problem. I need more pins than I have.

I also want to have a small buzzer hooked up to emit tones as well.

While searching for a solution I only seem to come across two things, manually writing to the LCD via serial or attaching the keypad and LCD to the same pins. (At least that's what I gather from reading this).

I know I can use the LCD in 4bit mode to free up some pins - but can I really attach the keypad and LCD to the same pins? OR would the better option be to write out manually via serial?

Thanks for the help

You can use the analog pins as digital pins also, A0-A5 = D14-D19.

LCD - 4 pins buzzer - 1 pin 12-key keypad - 7 pins (4 rows, 3 columns)

12 pins - use 2 for serial, still have 10 left.

If your environment is not too electrically noisy, you might try a trick which I have used:
Build a resistive ladder ( take five 1Kohm resistors (R1-R5, connect them end to end)
Connect the open end of R1 to +5 V Arduino supply
Connect junction of R1 and R2 to Keypad Row 4 pin
Connect junction of R2 and R3 to Keypad Row 3 pin
Connect junction of R3 and R4 to Keypad Row 2 pin
Connect junction of R4 and R5 to Keypad Row 1 pin
Connect the open end of R5 to Arduino GND

Connect Keypad Coll 1 pin to Arduino Analog Input (like A0)
Connect Keypad Coll 2 pin to a NON adjacent Analog Input (like A2)
Connect Keypad Coll 3 pin to a NON adjacent Analog Input (like A4)

Reading A0 twice will give a count reading which will indicate open value, or sorta, unique value (use INT) representing which row pin was pushed in coll 1. If you divide that value by 10, or 100, you eliminate some variation due to noise. Same logic gives unique values for row pins pushed in coll.s 2 & 3.
Takes a little work figuring out the values returned for each key push (they will vary due to resistor’s tollerance error and noise present) and what kind of delays, and where to put them, to ‘debounce’ the keypad button pushes. You cannot exactly use the digital key debounce, because you are doing analog reads, but it is close.

Keep your kepad leads as short as possible, or shield them if you can. It works for me, and, saves FOUR pins when using a 3 X 4 Keypad (principle works on a 4 X 4 pad also). works with the Sparkfun hard keypad and the Membrane keypads. I have tried to upload a simple Eagle schematic if the ladder.

untitled.sch (48.1 KB)

Buy a Mega? XD

CrossRoads: You can use the analog pins as digital pins also, A0-A5 = D14-D19.

LCD - 4 pins buzzer - 1 pin 12-key keypad - 7 pins (4 rows, 3 columns)

12 pins - use 2 for serial, still have 10 left.

Um.... Not sure how you got "10 left".

Standard 44780 lcd using the liquidcrystal library will need 6 pins: 4 data, E, and RS Use a 4x3 matrix for the 12 button keypad and the one for the buzzer. A total of 6+1+7 = 14 pins. Add in 2 for serial = 16 pins.

So still plenty of pins assuming the keypad is a 3x4 matrix. All the above will still leave 4 spare pins.

If you need more pins you can add a shift register and reduce the lcd pin count to 2 pins to free up an additional 4 more pins for a total of 8 spare pins. http://code.google.com/p/arduinoshiftreglcd/

--- bill

Oops, had my math a little off there :grin:
Should have been 6 with OP’s “4 pin serial LCD”.
I have a couple, guess I should wire one up one of these days.