VKey Voltage Keypad Hookup Guide

This Tutorial is Retired!

This tutorial covers concepts or technologies that are no longer current. It's still here for you to read and enjoy, but may not be as useful as our newest tutorials.

Contributors: Byron J.
Favorited Favorite 3

Example Code

Once you have installed the library, open the Arduino IDE, and paste the following into the sketch:

 VKey Voltage Keypad decoding demo
 By Byron Jacquot @ @ SparkFun Electronics
 February 4, 2014

 This demonstrates interfacing the SparkFun VKey voltage keypad using 
 the VKey Arduino library.

 The VKey has an array of 12 pushbuttons, each producing a unique analog 
 voltage when  pushed.  A microcontroller can read the voltage, and determine 
 which key has been pressed.  The VKey library keeps track of the analog pin 
 connection, key status, and voltage calibration details.

 The VKey was connected to the Arduino as follows:
 VKey GND  -> Arduino GND
 VKey Vout -> Arduino analog input A1
 VKey V+   -> Arduino VCC 

 To use the library, instantiate a VKey object and periodically check for input 
 using the checkKeys() function.

 no additional library requirements

 Development environment specifics:
 Developed on Arduino IDE 1.0.5
 Tested on a 5V Redboard and 3.3V Pro Mini

 This code is beerware; if you see me (or any other SparkFun employee) at the
 local, and you've found our code helpful, please buy us a round!

 Distributed as-is; no warranty is given.

#include <VKey.h>

// Global declaration of the VKey class
// Initialized with analog pin number and supply voltage
VKey keypad(A1, VKey::FIVE );

void setup()
  // Initialize serial port for text output
  Serial.println("Welcome to VKey example");

  // No VKey specific initialization required.

void loop() 
  VKey::eKeynum k;  // Variable to receive the key indication

    /* CheckKeys will always return the current key in parameter k.
       The boolean return value indicates whether that value is different than
       the previous value.
    // Only print when value has changed
    Serial.print("Got key: ");

  // The responsiveness of the keypad depends on how frequently it is checked. 
  // 50 milliseconds seems to be a reasonable poll interval.

Build and upload the sketch. Then open a serial terminal, and observe the output while pressing buttons.

alt text

The Arduino recognizes keys based on the voltage produced by the VKey

The Arduino will print notifications as buttons are pressed and released. A key number of 0 indicates that no keys are currently pressed.

If the Arduino isn't properly tracking the key numbers, double-check that the VKey object was declared with the proper analog pin and supply voltage parameters. Also doublecheck that you've got the latest code from the Github repository.