Introduction: Analog Keypad Backpack

About: I Make stuff. Use Arduino with DIY manufactured PCBs. Love the precision of CNC, Getting into 3D Printing. Someday I'll have a CNC mill. :-)
You know those ole 12 button keypads which are very easy to use but eat microcontroller IOs like they are candy? Well now you can have your cake and eat it with this simple backpack board which will convert one of these hungry beasts down to consuming only a single analog input rather than 12 digital inputs.

You will need:
  • 12 button common terminal keypad. 1x
  • 1k ohm resistor, 12x
  • 12k ohm resistor, 1x
  • Protoboard (approx 1.5" x 1.5"), 1x
  • Soldering iron & solder
  • Hookup wire (red - approx 2"), x1
  • Hookup wire (black - approx 2"), x12
  • Hookup wire (red,black,yellow - approx 5"), x3
  • Molex crimp pins, 3x
  • Molex female connector, 1x
  • Molex male connector, 1x
  • Hot glue gun
  • Mini vise

Step 1: Circuit Design

The circuit is a simple series resistor ladder + voltage divider.
The common terminal of the keypad is held high through a 12k pullup resistor.
Each key terminal of the keypad is connected to a 1k resistor.
That resistor is in turn connected in series with its neighbor in a ladder twoards the common terminal.
The end of the resistor ladder is tied to ground.
The signal line is a voltage divider with its reference point between the 12K resistor and the resistor ladder.
Depressing a key causes a chain of resistors with a unique value to be introduced into the voltage divider, giving each key a unique analog value.

Eagle schematic files are attached for ease of reproduction on a protoboard or single sided etched copper board.

Step 2: Connect Protoboard to Keypad

  1. Insert the keypad into the vise.
  2. Strip both ends of the 2" red wire and the 2" black wire.
  3. Solder the red wire to the common terminal of the keypad.
  4. Solder the 12 black wires to the button terminals of the keypad.
  5. Glue the underside of the wires to provide stress relief to the solder joints.
  6. Thread all 13 wires into the protoboard in a straight line and solder them in place.

Step 3: Construct the Resistor Ladder

  1. Insert the board into the vise with the copper pads down.
  2. Starting away from the common terminal, insert the ladder resistors, diagonally crossing over one column towards the common terminal with each one. (1st pic)
  3. Tape down the resistors and turn the board over in the vise.
  4. Bend the resistor legs towards the keypad terminals which are already soldered. (2nd pic)
  5. Solder the resistor legs to the keypad wires. (3rd pic)
  6. Clip the resistor legs. (4th pic)
  7. Bend the other legs of the resistors back towards the keypad so they adjoin with their neighbors (5th pic)
  8. Solder the resistor legs to the ajdoining ends and keypad wires. (6th pic)
  9. The ladder is now complete

Step 4: Construct the Voltage Divider

  1. Insert the 12k resistor at the common terminal side of the protoboard. (1st pic) (PS The pic shows a 10k resistor because i didn't have a 12k at hand, its close enough!)
  2. Solder one side of the resistor to the common terminal wire. (2nd pic)
  3. Strip insulation from the 3 signal wires.
  4. Insert the black (ground) wire at the end of the resistor ladder. (3rd pic)
  5. Insert the red (vcc) wire near the unconnected end of the 12k resistor at the common terminal.
  6. Insert the yellow (analog out) wire near the soldered end of the 12k resistor at the common terminal.
  7. Solder the signal wire to the end of the 12k resistor and keypad common terminal. (4th pic)
  8. Solder the black wire to the end of the resistor ladder.
  9. Soler the red wire to the unconnected end of the 12k resistor.

Step 5: Tidy Up

  1. Trim the end of the protoboard close to where the terminal wires enter so it can be bent back around onto the back of the keypad. (1st pic)
  2. Hot glue all the keypad wires to the protoboard to provide stress relief to the solder joints.
  3. Hot glue the 3 signal wires to provide stress relief to the solder joints
  4. Bend the protoboard back against the keypad (2nd pic)
  5. Hot glue the signal wires in place so they exit facing the direction which fits best for your application.
  6. Attach molex crimp pins to the end of the signal wires for plug n play connection to a host circuit (3rd pic)

Step 6: Test

I'm using a barebones Arduino on a breadboard but any arduino you have lying around will suffice.
  1. Connect the red wire to arduino VCC (+5v).
  2. Connect the black wire to arduino ground.
  3. Connect the yellow wire to arduino analog 0 input (A0).
  4. Power up the arduino and connect the usb port to your computer.
  5. Upload the attached sketch to your arduino.
  6. Open the arudino serial console.
  7. Set the baud rate to 115200.
  8. The sketch should be reading 1023 from the analog input (1023 = 5v)
  9. Press and hold the * key on the keypad
  10. The sketch should now read < 512 from the analog input
Now all we need is convert that analog reading to its corresponding key char.
Onto the next part...we will install an Arduino library to do this for us.

Step 7: Setup Arduino AnalogKeypad Library for Easy Use

  1. Leave the circuit you built in the last step in place as is but power it down.
  2. Make sure the arduino editor is shut down. If it's open exit now, we will open it back up again shortly.
  3. Save the attached files (AnalogKeypad.cpp and AnalogKeypad.h) to a folder called AnalogKeypad under the library folder of your Arduino sketchbook library location (see image 1 for where this is on a Mac) For further help on Arduino libraries see this tutorial
  4. Download the attached example sketch which uses the AnalogKeypad library (AnalogKeypad.pde) to wherever you like to save Arduino sketches (It must also go inside a folder called AnalogKeypad, as per Arduino sketch rules)
  5. Start up the arduino editor
  6. Open AnalogKeypad.pde
  7. Select Menu -> Sketch -> Import Library -> Analog Keypad
  8. The arduino editor will probably add another #include <AnalogKeypad.h> line (which you can remove if you wish)
  9. Ensure the arguments to the AnalogKeypad constructor are set properly as per the resistor values you used in the divider and ladder. The default is 12K (pullup) and 1K (ladder), so if you used them it will work fine.
  10. Power up your test circuit again
  11. Upload the arduino sketch to the circuit.
  12. Open the arduino serial window by clicking on "Serial Monitor" in the toolbar.
  13. Select "115200" from the baud rate drop down
  14. Press buttons on the keypad and observe the printouts in the serial monitor.