Using a single analog in as a keypad input

Wow I just stumbled on this, you guys have to check this out!

Those who want to save I/O ports only have to get the keypad to produce an analog voltage. That's the task for a resistor matrix.

This is just so cool I'm gonna have to quote him right here so you don't have to click the link ;D

This is such a resistor matrix. The columns are connected to ground, in between the column connections are three stacked resistors. The rows are connected via four such stacked resistors to the operating voltage (e.g. 5 V). The AD converter input is blocked by a condensator of 1 nF because the ADC doesn't like high frequencies, that could be caught by the keys, the resistors and the more or less long lines in between all this.
If the key "5" is pressed, a voltage divider gets active:

  • 1 k + 820 [ch937] = 1,82k to ground,
  • 3,3 k + 680 [ch937] + 180 [ch937] = 4,16k to plus.

At an operating voltage of 5 Volt a divided voltage of

5 * 1,82 / (1,82 + 4,16) = 1,522 Volt

is seen on the AD converter input. If we consider 5% tolerance of the resistors, the resulting voltage is somewhere between 1,468 and 1,627 Volts. The 10-bit AD converter converts this (at 5 V reference voltage) to a value between 300 and 333. If we ignore the lower two bits of the result (e.g. divide the AD result by four or left-adjusting the result - if the ADC provides that function) this yields an 8-bit-value between 74 and 78.
Each key pressed produces a typical voltage range, to be converted to the key code.

Well ok I lied, you will have to check the site to get it all :stuck_out_tongue:

I'm moving soon and have most of my stuff packed or getting ready to so I won't be able to try this for a bit. I just can't wait, this is so ingenious! On top of saving a 12 ports for a direct connection, it saves the very costy 74C922 16 Key encoder ~8$ (iirc) all with a few cents worth of resistors!

Just what I was looking for. Unfortunately I'm not as handy as I need to be to figure this out. Any volunteers? ::slight_smile:

nifty, but cant read the diagram... care to explain anyone?

The "Ub" is +5V.

So, when you press a button, it creates a connection between a point on the "ladder" of resistors going to +5, and a point on the one going to ground.

That gives you an instant voltage divider. The designer picked the resistor values so you get a unique voltage for each button.

The resistors in between that connection and the Arduino are very small compared to the input impedance of the analog pin, so their effect on the reading is so small it can be ignored.

There's no free lunch, though, and the cost of this meal is that pressing two or more keys at once will produce values that might confuse the software. You'd have to calculate all the possible combinations to be sure. But it's a really clever idea that will be just fine for many applications.

Ran

pressing two or more keys at once will produce values that might confuse the software.

Correction will confuse the software.

As there are 12 keys in order for it to not confuse the software then you would need at least a 12 bit A/D converter (probably 14 bits in practice) and resistors with an accuracy greater than 0.02%.

Then what happens about three key presses?

As it stands you might have to use 1% resistors to get it to work but I haven't done the sums yet.