Analog Keypad Backpack
Intro: Analog Keypad Backpack
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:
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.
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
- Insert the keypad into the vise.
- Strip both ends of the 2" red wire and the 2" black wire.
- Solder the red wire to the common terminal of the keypad.
- Solder the 12 black wires to the button terminals of the keypad.
- Glue the underside of the wires to provide stress relief to the solder joints.
- Thread all 13 wires into the protoboard in a straight line and solder them in place.
STEP 3: Construct the Resistor Ladder
- Insert the board into the vise with the copper pads down.
- Starting away from the common terminal, insert the ladder resistors, diagonally crossing over one column towards the common terminal with each one. (1st pic)
- Tape down the resistors and turn the board over in the vise.
- Bend the resistor legs towards the keypad terminals which are already soldered. (2nd pic)
- Solder the resistor legs to the keypad wires. (3rd pic)
- Clip the resistor legs. (4th pic)
- Bend the other legs of the resistors back towards the keypad so they adjoin with their neighbors (5th pic)
- Solder the resistor legs to the ajdoining ends and keypad wires. (6th pic)
- The ladder is now complete
STEP 4: Construct the Voltage Divider
- 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!)
- Solder one side of the resistor to the common terminal wire. (2nd pic)
- Strip insulation from the 3 signal wires.
- Insert the black (ground) wire at the end of the resistor ladder. (3rd pic)
- Insert the red (vcc) wire near the unconnected end of the 12k resistor at the common terminal.
- Insert the yellow (analog out) wire near the soldered end of the 12k resistor at the common terminal.
- Solder the signal wire to the end of the 12k resistor and keypad common terminal. (4th pic)
- Solder the black wire to the end of the resistor ladder.
- Soler the red wire to the unconnected end of the 12k resistor.
STEP 5: Tidy Up
- 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)
- Hot glue all the keypad wires to the protoboard to provide stress relief to the solder joints.
- Hot glue the 3 signal wires to provide stress relief to the solder joints
- Bend the protoboard back against the keypad (2nd pic)
- Hot glue the signal wires in place so they exit facing the direction which fits best for your application.
- 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.
- Connect the red wire to arduino VCC (+5v).
- Connect the black wire to arduino ground.
- Connect the yellow wire to arduino analog 0 input (A0).
- Power up the arduino and connect the usb port to your computer.
- Upload the attached sketch to your arduino.
- Open the arudino serial console.
- Set the baud rate to 115200.
- The sketch should be reading 1023 from the analog input (1023 = 5v)
- Press and hold the * key on the keypad
- The sketch should now read < 512 from the analog input
Onto the next part...we will install an Arduino library to do this for us.
STEP 7: Setup Arduino AnalogKeypad Library for Easy Use
- Leave the circuit you built in the last step in place as is but power it down.
- Make sure the arduino editor is shut down. If it's open exit now, we will open it back up again shortly.
- 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
- 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)
- Start up the arduino editor
- Open AnalogKeypad.pde
- Select Menu -> Sketch -> Import Library -> Analog Keypad
- The arduino editor will probably add another #include <AnalogKeypad.h> line (which you can remove if you wish)
- 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.
- Power up your test circuit again
- Upload the arduino sketch to the circuit.
- Open the arduino serial window by clicking on "Serial Monitor" in the toolbar.
- Select "115200" from the baud rate drop down
- Press buttons on the keypad and observe the printouts in the serial monitor.
19 Comments
DaSgtPunishment 7 years ago
Hi, I'm just wondering if I'm able to lower the values on the resistors and doing so, add more buttons?
I was hoping to use this as a basis for a keypad for a DIY media centre remote, but I need more than 12 buttons.
declanshanaghy 7 years ago
The resistors in this design were chosen to give a ratio of 1:12 per button in the ladder. Hence the pull up resistor is 10k and each of the 12 buttons uses a 1k resistor. This works well for commonly available resistor values even though the design has 1:10 ratio using 1k/12k
So depending on how many button's you're planning on utilizing I would choose a similar ratio for the ladder.
The thing to be aware of is the more buttons you add, the closer each step of the ladder gets and you may start running into issues figuring out which button was pressed. I'm not sure at what number of buttons this would start happening.
The library is setup so that you can pass in the resistor values for the pull up and ladder sections. It will then calculate the voltage it expects to see resistance value of each button.
You'll need to modify the library to work with a different number of buttons though, it's currently hardcoded for 12 buttons in numerous places
AlexW38 8 years ago
Thanx for this tutorial.
I have used it to make a toy organ.
It's works perfectly
PeterT15 8 years ago
Thank you for making this easy step-by-step tutorial. Worked like a charm.
acheide 10 years ago
Dominion-Network 12 years ago
http://dominion-network.co.uk/projectstuff/keypad.jpg
I'm currently in the process of neatening it up so it looks a lot better, and so I'm also able to 'waterproof' it with a diy membrane.
Dominion-Network 12 years ago
declanshanaghy 12 years ago
I cant help without seeing what you're working with.
Also send me some pics of the hardware physical
hardware setup or eagle schematics.
Im also a little unclear on what you mean by combining both.
I assume you want to capture input from the keypad and pass it onto
the password library. Is this correct?
Dominion-Network 12 years ago
Dominion-Network 12 years ago
But yeah I'm trying to capture input from the analog keypad and pass it through to the password library and so far everything I've attempted has failed...
Once I've had my dinner I will take the required photos and I will email them as well as the code I've got.
Dominion-Network 12 years ago
http://www.arduino.cc/playground/Code/Password
But I'm not having any luck, could you give me a hand?
Dominion-Network 12 years ago
declanshanaghy 12 years ago
All the source is avaiable on github:
https://github.com/declanshanaghy/KeypadBackpack
I've started implementing the Arduino Library to read the keys (see here)
https://raw.github.com/declanshanaghy/KeypadBackpack/master/AnalogKeypad/AnalogKeypad.pde
However, the code doesn't include any debouncing logic yet. I should get that implemented within the next week. (busy with some other stuff)
Feel free to fork and send me a pull request if you implement it yourself.
declanshanaghy 12 years ago
Dominion-Network 12 years ago
Where did you get your keypad from? was it Maplins? (UK) or Sparkfun? (USA)
declanshanaghy 12 years ago
The keypad must be the type that has 13 terminals.
1 for each of the 12 keys and 1 common termal
I got this "common terminal" keypad at allelectronics.com
http://www.allelectronics.com/make-a-store/item/KP-12/12-BUTTON-KEYPAD//1.html
Most people use matrix keyds because it saves pins compared to a common terminal keypad. However, i think the common terminal approach is much easier since you can get it down to only using 1 pin with a few measly resistors.
Dominion-Network 12 years ago
declanshanaghy 12 years ago
AllElectronics is pretty bad when it comes to datasheets - basically non existent for any of their products.
Dominion-Network 12 years ago