SparkFun Electronics will be closed in observance of memorial day on Monday, May 29th. We will resume normal business hours on Tuesday, May 30th. Any orders placed after 2pm Mountain Time on Friday, May 26th will process and ship out on Tuesday, May 30th.

Creative Commons images are CC BY 2.0

Description: This is the SparkFun VKey Voltage Keypad, a simple board that adds a keypad to your microcontroller project without using multiple I/O pins. This keypad has 12 pushbutton switches in a 3x4 array. The VKey operates by outputing an analog voltage to encode which key has been pressed, which can be read by an analog to digital converter on a microcontroller on a single input pin.

Traditional digital keypad interfacing techniques can require a large number of digital I/O lines. On a small controller, there may not be many I/O pins left for other tasks. The VKey operates at a voltage of 3.3-5.5V and features a dual opamp which is used as a current source and buffer amplifier.

Note: The SparkFun VKey Voltage Keypad comes with the surface mount components assembled, but the PTH tactile switches are loose, and will need to be soldered to the board. Check the Hookup Guide in the Documents section below for assembly instructions.


Recommended Products

Customer Comments

  • If I hold a key down, it should report the initial keypress and then ignore because the same key is being detected. Sometimes, if I hold down the 4 key, for instance, it returns a 3 and then bounces back and forth between 3s and 4s. It happens with other keys, too and it’s always key and key-1. What’s up with that?

    • Not sure, but it seems like I have a defective one. Now it’s emitting a 12 key while idle. Using the demo program, so nothing fancy is going on.

      • There are a few things that you can check.

        First, make sure you’re declaring the Vkey library to match your power supply voltage in the sketch. The VKey::FIVE or VKey::THREE parameter, denepding if you’re in a 5V or 3.3V power supply. Also doublecheck that your connections are secure – that the buttons are soldered in neatly, and the power, ground and output connections are all solid. I recently chased my tail for a couple hours because an alligator clip was barely hanging on the end of its wire.

        Second, use a volt meter or oscilloscope to verify that the power supply is stable and sensible. Measure both VDC and VAC. The DC reading should be close to the nominal rating (3.3V or 5V), and not wiggling around. The AC reading should be close to 0 – an unstable supply will exhibit some AC voltage, and will wreak havoc with the VKey.

        Third, with the voltmeter still in hand, exercise the keys, measure the output voltage, and compare the results with the table in the hookup guide. While a key is held, the output voltage should be steady.

        Finally, you might glean some clues if you bypass the library, and call analogRead() directly. Are the conversion values reasonably steady?

  • What’s the center-to-center spacing on the buttons?

  • WARNING - there is no reverse voltage protection on this keypad, so be sure not to mix the supply pins. I, unfortunately, had to learn that the hard way…

  • It did not run correctly on any of my boards (Leonardo, Due). Thus, I dumped the library, determined the analogRead values for every key (which might be different per board), increase them a little bit (about 10 points) and use the following program adapted from DFrobot example code to use the five buttons on the Romeo, but added a threshold of 20, because the keyboard is noisy:

    int key=-1;
    int oldkey=-1;
    int adc_key_val [12] = {45,85,125,170,215,260,300,345,380,425,470,510};
    int adc_key_in;
    void setup()
    void loop(){ 
     if ((key != oldkey) && (key !=-1)){ Serial.println(key);}
     int get_key(unsigned int input){
     int k;
    for (k=0; k<12; k++){
      if (input<20){k=-1; return k;}
      if (input<adc_key_val[k]){k=12-k; return k;}
      if (k>=12){k=-1;return k;}
  • Hooked this up and am having trouble with the default library settings. Basically the 1 key doesn’t register a key press at all, 2 key reports as 1, 3 reports a 2, 4 reports 3, 5 reports 4. Then there is a gap (no 5 key), and the 6 key through 12 key work fine. I’m running this on a RedBoard with a measured Vcc of 4.987 volts. Looks like the VScaleKey table may need to be tweaked further for production variances. Here are the Vout readings for each key: 1 - 2.488v, 2 - 2.280v, 3 - 2.073v, 4 - 1.867v, 5 - 1.660v, 6 - 1.453v, 7 - 1.246v, 8 - 1.038v, 9 - 0.831v, 10 - 0.623v, 11 - 0.414v, 12 - 0.207v, Open - 0.061v. Is anyone else having similar problems with this board?

    • It looks like your samples are spaced a little wider than the boards I used to get the firmware running.

      In the calibration table, try the following values

      • min = 21
      • step = 43
      • max = 496

      I just used the spreadsheet in the github repo called ADC.ods. Using your VDC measurements, I estimated the ADC value (ADC = (Vin/Vref)*1024), and plugged that into the spreadsheet.

      You might get better values by using readAnalog() to capture the ADC value that each key yields, and putting those values into the green area of the spreadsheet. The min, step and max for those voltages show up in the light blue cells.

      • The results were about the same with min/step/max of 21/43/496. The ADC readings are as follows: No Key - 10, K1 - 504, K2 - 462, K3 - 420, K4 - 378, K5 - 336, K6 - 293, K7 - 251, K8 - 209, K9 - 166, K10 - 124, K11 - 82, K12 - 40. Plugging those into the spreadsheet and it shows min/step/max of 18.9/40/497.9 so I used 19/40/498 with similar results. Something still not right here.

        • Yeah…something doesn’t quite jive there. You report a max reading of 504, we somehow both arrived at a max of 496. I just put your measurements into the spreadsheet, and here’s the resulting table.

          18.9    min
          42  step
          Key #   lower threshold mid point   upper threshold
          12  18.9    39.4    59.9
          11  60.9    81.4    101.9
          10  102.9   123.4   143.9
          9   144.9   165.4   185.9
          8   186.9   207.4   227.9
          7   228.9   249.4   269.9
          6   270.9   291.4   311.9
          5   312.9   333.4   353.9
          4   354.9   375.4   395.9
          3   396.9   417.4   437.9
          2   438.9   459.4   479.9
          1   480.9   501.4   521.9

          That gives me a min/step/max of 18/42/522. The values you measured are within 3 counts of the midpoint of each bin there, so you should be squarely within each.

          Please give that a try.

          • Replacing the original (5v) min/step/max of 17/40/496 with 18/42/522 did the trick; the keys all decode perfectly now. Wondering if there is a way to have the Arduino auto-calibrate itself so these settings could be generated automatically as part of initialization? Also curious why your development keyboard varied from my production keyboard so much since the divider circuit on both boards is coming from a well regulated 5v source.

  • More than 20 years ago Microchip published an I/O app guide, a little 3x5in. sized printed pamphlet (remember those?) that was included with the development boards. Most of Microchip’s business was low pin count parts back then, so I/O was at a premium. This guide showed how to get more bang from each I/O - using one I/O to drive 2 LEDs, PWM for DAC output, etc. This is very similar to one of those app note circuits except as I remember that one used a simple voltage divider rather than a current source. Funny how nothing ever really changes.

  • Just port the Arduino Library to NETMF (Netduino Board) with a KeyPress Event and synchronous ReadKey() method that will block until a key is pressed - I don’t have the Keypad to test (but 90% sure it will work) so, am wondering if anybody have a Netduino and the Keypad to test the code for me before I upload it CodePlex

  • if you remove the opamp current source it would work across all voltage ranges (the buffer can take) … your comparing it against the supply voltage anyway so it would save a ton of pain!

  • With 12 keys on analog voltage, I’m thinking: map the 12 tones of the musical scale for an analog keyboard/synth. There’s a MIDI application in this. I want one.

  • Interesting concept! I wonder if a ‘digital’ version is planned?

    An MCU (micro controller) in place of the op amp, reading switch closures, using key-scanning of a matrix, could then output serial data of key closures. This would require only two signal pins (plus supply and ground) for the popular I2C (or TWI) protocol.

    Having an MCU allows programming of behavior, and resolution of the multiple button press issue. Or, to distinguish between a button “tap” (< a second) and a button “hold” (> a few seconds)

  • according to my calcs this design will only work when limited to +/- 10C of temperature change. due to the diode drop changing with temp. maybe add some temp comp, either in software or hardware. the old analog mono synths used a similar circuit and had temp comp to combat this issue.

    • Like many things in engineering, the temperature dependence was a tradeoff, so this can have a relatively constant output voltage regardless of the supply voltage (granted, around room temperature).

      If we can constrain the problem to a single supply voltage, then a simple resistor divider could be used to set the current. Or we could forward bias the diode more strongly – It looks like the Vf/Temperature curves track more closely above 100mA. Make that a lot more strongly.

      There might be some really clever ways to make self-calibrating software, too. If you put a jumper in place of button 1, the thing would idle at it’s max output voltage. Dividing that by 12 would tell you how big each step needed to be.

      And don’t get me started on monosynths, or we’ll be here all day!

  • if all you need is 1 key at a time it saves a lot of pins. wonder about temperature effects however.

  • Can it detect multiple button presses?

    • Not according to the “Hookup Guide” - “One situation to consider is when more than one key is pressed at the same time. The VKey implements high-key number (or low voltage) priority – when more than one of the switches is closed at a time, the output will indicate the higher key number. For instance, if you hold down 5 and 9 together, the output will indicate key 9 is pressed.”

Customer Reviews

4.3 out of 5

Based on 3 ratings:

Currently viewing all customer reviews.

1 of 1 found this helpful:

SparkFun Vkey voltage keypad.

the keypad was very easy to assemble and worked the first time. it would be nice to see a capacitive touch key pad that works with the same voltage output and maybe a little bit smaller package so it could be incorporated into a project. Good job SparkFun.

1 of 2 found this helpful:

Well made!

I haven’t had the chance to test it yet. I’ll update this as soon as I try it.


Handy pinsaver,almost like using shift registers, but that’s another story. Good build quality, easy to set up. And those screw holes are nice plus. Can’t find any flaws in this.

Related Tutorials

VKey Voltage Keypad Hookup Guide

February 13, 2014

A quick hookup for the VKey analog voltage keypad.