First off, before I get started, I wanted to say thank you to everyone who has posted a question or answer on this forum. I have used it many times to help me get started with my arduino projects and it has been beyond helpful, and now I get to share and get input on a project that I could not find in this wealth of information (thats not to say its not here).
Now, on to the project:
I wanted a keypad system that was easy to expand, I could build with easy to get (or already owned) parts and used minimal pins on my arduino boards. This is what I came up with and I wanted to run it by you guys to make sure it is safe for my megas (it should be) and to see if you guys see any problems I might run into with this setup. Hopefully if it works as expected, it will help someone else's projects as well.
The basic idea is to make a voltage divider and use a switch to send each of these different voltages to an analog input on the arduino, which it recognizes as different key presses and performs the appropriate action.
The thought process:
A basic voltage divider (with resisters) didnt really seem like a good way to go, so my next thought was zeners in series. But zeners are only available down to about 1v or so (4 buttons after the additional circuitry), so that wouldn't really work well either. Then I realized I had a TON of 4148 signal diodes, and knew their forward voltage was lower, and could be manipulated down to about 400-450mv by restricting current (win win, low standby operating current). The low current probably needs to be amplified a bit, which is where the transistor comes in, the resistor (R2) at the emitter keeps the current from being too high.
Laying it out:
On paper it looks good, in simulation, I needed a resistor to pull down the transistor when no buttons were closed, which is what R3 is for. Otherwise I got about 900mv (slightly more than the second lowest button voltage) on the output. I plan to keep this resistor in my first prototype, but I'll remove it to see if its actually necessary when I finish the system. As expected on paper, the simulation showed that it will not be a completely linear climb in voltage as you work down the ladder, but thats not a problem, since the numbers dont get close enough to prevent a healthy buffer between button voltages.
The programming will simply watch for a non-zero (with some tolerance) voltage at the appropriate analog input(s) and use a case select to determine which button is being pressed, then perform the appropriate action.
As shown in the attachment, it only uses 3 pins, and for each additional 10 buttons, it adds 1 more. So, check on minimal pins, as long as you dont need a fully functional computer keyboard.
Simply add another switch circuit (the switches, transistor, R3, and R2) in parallel to the existing switch circuit and add another connection to a different analog input pin (another 'J1' in the attachment) and you have room for 10 more buttons, this is limited only by the number of inputs on your board that you can use. Expandable? CHECK!!!! (a big, bright red one 5x the size of the box)
It consumes very little current. I'm not sure if everyone else will see this as a good thing or bad thing, but since I'm limited to using as few pins as possible, I'm calling this a win (until someone shows me a better way).
I can build it with components I have on hand (and make use of the 100+ micro buttons I have, like the reset buttons), and all the parts are really common.
So yeah, that's what I was thinking. What do you guys think? I know I'm re-inventing the wheel here, but I wanted a system to call my own for my projects, and this rather simple approach fit all my criteria (assuming it works).
UPDATE: The system is working and now in library form with an example that outputs to serial. It can be downloaded in post #16.