Introduction: Meet One Pin Keypad

About: Here at Progetto, we strive to help simplify your projects so you can spend more time working on the exciting stuff.

DISCLAIMER: THIS IS A USAGE GUIDE FOR AN OPEN SOURCE PRODUCT: THE ONE PIN KEYPAD. THIS IS NOT A DIY PROJECT. IF YOU WANT TO MAKE THE BOARDS YOURSELF, THE EAGLE FILES CAN BE FOUND AT THE END OF THE TUTORIAL.

What is the One Pin Keypad?

One Pin Keypad makes using a matrix keypad so much easier and lets you reserve your precious Arduino I/O for other purposes. A 16 button matrix keypad typically requires 8 digital inputs on an Arduino microcontroller. The most popular Arduinos limit you to only 14 digital pins, so a 16-button keypad leaves you with only 6 pins for the rest of your project. This resource-shortage may lead to a costly design trade-off or a more costly Arduino upgrade.

The One Pin Keypad module eliminates the need for all of these digital inputs. As its name implies, One Pin Keypad uses only one pin (an analog input) plus GND and VCC connections, so wiring your keypad is a snap! The One Pin Keypad Arduino library (included) also simplifies the programming required to process the keypad inputs, saving you more time and effort.

For the Raspberry Pi Usage Guide, click here

Step 1: Gather Parts!

To get started with your One Pin Keypad board, you'll need:

  • A One Pin Keypad Board
  • An Arduino of some flavour (An Arduino Nano was used in this case)
  • 3 M/F jumper cables
  • A 16 button membrane keypad
  • Breadboard (Optional), used here since the Arduino Nano is breadboard compatible

Step 2: Wire It All Together!

The One Pin Keypad requires 3 connections to the Arduino Nano, as follows:

GND to GND

VCC to 5V

AOUT to A0 ( or any other analog pin, just make sure to change it in the example sketch).

Once you've made the connections to the Arduino, connect your membrane keypad, ensure you have the correct orientation see images. To ensure you have it right verify that the coloured (white and black) sections indicating rows and columns above the female connector match up with those in the image.

Step 3: Install Arduino Library From Github

The Arduino library for the One Pin Keypad can be found here.

Download the library as a .zip file and follow the steps outlined at these amazing tutorials from Sparkfun here (for Windows) or here (for Mac).

UPDATE 10/30/2018: The Progetto One Pin Keypad Arduino library is now listed in the Arduino Library Manager, see this awesome tutorial (again from Sparkfun) for an easier way to install the library!

Step 4: Calibrate Your Board

For this step, we are going to need the calibrateThresholds example sketch. Plug your Arduino in and use the File menu to open the calibrateThresholds example from the Progetto One Pin Keypad Arduino Library.

Run this sketch and follow the instructions displayed on the Serial Monitor to calibrate your board. After calibration walks through all the buttons, test out your new analog values to see if they work by pressing some buttons when prompted to "Begin.", if the new values prove to be inaccurate, hit the reset button to recalibrate.

The calibration sketch should provide you with 2 lines of code you'll need in the next example, make sure to keep the Serial Monitor open and/or copy them both!

Step 5: Check Out ReadKeypadWithTimeout!

Now that your One Pin Keypad board is calibrated, use the File Menu to open the readKeypadWithTimeout example sketch. Remember that analog value array you copied? Replace line 20 (see below) with those newly calibrated analog values.

Example:

// ex: int myThresholds[16] = {calibrated values would be here}

is replaced with this:

int myThresholds[16] = {36, 104, 166, 218, 263, 307, 345, 379, 406, 436, 463, 486, 514, 525, 547, 562};

Next, add the next line of code after line 20, (see below):

keypad.useCalibratedThresholds(myThresholds);

is added after line 20:

// If calibrated values are being used, run useCalibratedThresholds(your array name) below:

making lines 20 and 21 look like this in the end:

// If calibrated values are being used, run useCalibratedThresholds(your array name) below:
keypad.useCalibratedThresholds(myThresholds);

After that's done upload the code and test it out by pressing some buttons! Feel free to adapt the example sketch to your projects! Remember that readKeypadWithTimeout returns the button being pressed as a char and the timeout is set in milliseconds! If you don't want a timeout use the NO_TIMEOUT constant.

Step 6: How the One Pin Keypad Works

Much of the One Pin Keypad's design is based off of Hari Wiguna's implementation of a voltage divider to obtain a unique analog value for each key in a 16 pin keypad. One Pin Keypad's design remains largely the same, with a few tweaks. If you a want a great tutorial on how the One Pin Keypad works, feel free to check out Hari Wiguna's awesome video here!

Step 7: Conclusion

In this instructable, we covered how to get started with your One Pin Keypad board. Now, the curious among you may have wondered why the readKeypadInstantaneous example sketch was never used, the reason is that it is not as useful, because the button has to be pressed when it is called, the readKeypadInstantaneous() function is used primarily to simplify readKeypadWithTimeout() in the library. If it catches your eye feel free to take it for a spin. Happy Hacking!

If you have any questions, leave a comment below or email us at progettocompany@gmail.com.

All the best,

Progetto Company

P.S. As promised, a link to the board's Eagle Files.

Step 8: NEW!!! LCD Example Sketches!

UPDATE: 11/8/2018:

We have released LCD example sketches that work with standard 16 x 2 LCD modules!

Hook up an LCD using the tutorial below, load up the readKeypadWithTimeout_LCD example sketch, add your calibrated array just as you would with the regular readKeypadWithTimeout example sketch and watch as the button you pressed appears on screen! Let us know in the comments what you create!

Arduino LCD hookup guide:

https://www.arduino.cc/en/Tutorial/HelloWorld

Remember to use the potentiometer to adjust your contrast!

UPDATE: 12/23/2018:

The LCD example sketches now allow the use of I2C backpacks for the LCDs! They use the library from the link below:

https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/

Make sure to run an I2C Scanner sketch to determine the LCDs address:

https://playground.arduino.cc/Main/I2cScanner

Happy Hacking!

John Wolf,

Progetto