Introduction: Hotkey Keypad From Cash Register
This spring, as I was perusing the engineering building’s “free” pile for goodies, I found a gem – an all-in-one cash register! One component caught my eye: A keypad with mechanical switches. I had been planning to make a custom hotkey keyboard for some time, and this was the perfect opportunity to explore it.
If you don't have access to an old cash register, look around for mechanical switches and keycaps!
There are some with remove-able labels on ebay, found by searching "16mm Square Momentary Push Button Switch Self-Lock LED Lamp 5 Pins"!
Mechanical switches and key caps. The amount of is up to you! I had 46 for mine.
Resistors (10 kOhm, you will need between 5 and 10 depending on how big your array is)
Arduino Pro Micro or similar (knock off of same model is ok) - Check compatibility here: https://github.com/NicoHood/HID/blob/master/Readme...
Wood or other materials for making an enclosure
Hand/power tools to cut and machine your chosen enclosure material. For wood: chisels, files, sandpaper, and some cutting tool (hand saw or table saw).
Soldering iron & solder (Recommend also having a "solder sucker"! It helps a lot)
Step 1: Clean It Up!
If you salvaged your keypad from something else, it's likely grimey and gross. Take off the key caps and wash them in the sink, and give the base a good cleaning too!
If you have keycaps that have clear covers that allow you to customize the picture on the key, take some time to design some sweet labels! I got some from online icon sources, or designed them myself. I wanted greek letters for my lab reports, so I filled most of my real estate with that. I decided to keep the original "cash" button in the bottom right to remember where the keypad came from!
Step 2: Reverse Engineering / Setting Up Your Key Matrix
If you've salvaged your keypad from an existing device, you may have to reverse-engineer the printed circuit board (PCB) to determine how the board is wired. If you are using new switches instead, you should follow the same procedure for keeping your circuit layout organized!
First, make a labeling system for all of the switches.
Here is my grid:
A1 B1 ---- ---- ---- --- ---
A2 B2 C2 D2 E2 F2 G2
A3 B3 C3 --- E3 F3 G3
A4 ---- ---- --- E4 F4 G4
A5 B5 C5 D5 E5 F5 G5
A6 B6 C6 D6 E6 F6 G6
A7 B7 C7 D7 E7 F7 G7
A8 B8 C8 D8 E8 F8 ----
You may have noticed that in my picture, there are conductive traces that run between the switches. In general, each line is either designated as a "column" or a "row". For example, line 1 (a "column") would connect switches A1 - A8. Terminal 12 (a "row") would connect switches A3 - G3.
See the attached GIF for a visual explanation of how this works! GIF source: http://pcbheaven.com/wikipages/How_Key_Matrices_Works/
If you're making yours from scratch, make sure to solder the lines together vertically and horizontally only, to make programming easier later. If you've done this well, you should be able to have an "A" column, a "B" column, etc, and a "1" row, a "2" row, etc. This will make programming much easier later on, since you know that button A1 is connected to "A" and "1"!
If you're reverse engineering, turn over the board and go switch-by-switch, following the input and output lines leading from the switch to the terminals of the board. Label each terminal with a number, and mark which two lines were connected to each switch. For example, A1 may be connected to line 1 and line 11.
Once done this step, you should have a grid with each button labeled, and a lookup table for determining what button is connected to any two given wires. It would be a good idea to check your work using a multimeter, to ensure the lines are connected to where you wrote down they were!
Step 3: Design Your Circuit
Now that we know how our switches are connected, we should make a circuit diagram to make checking for mistakes easier. But first, we need to deal with a problem: We don't have enough I/O pins on an Arduino Pro Micro for this size of a keypad!
Thankfully, we have our friend: the shift register. I will be using the 74HC595, which I purchased from DigiKey. Using this Integrated Circuit (IC), we will be able to turn 2 I/O pins into 8 controllable outputs. This can be daisy-chained with more shift registers if we want to save even more outputs, but it will not be necessary for this project. Essentially, the circuit takes an input line (logical High or Low), and a clock signal to tell the chip when to read the input line value. Each pulse on the clock line shuffles the signal through all of the output pins, until it drops off. For more information on how a shift register works, see Ben Eater's fantastic video demonstration:
(skip to 8:43 for the shift register demonstration)
As you can see from my drawn diagram, I've used the data sheet to label all of the pins of the Arduino Pro Micro and the 74HC595 shift register, then connected them. I used arrows to indicate the wire being connected to the keypad matrix.
Important things to note:
This is the time to choose whether your rows or columns will be the "output" lines. The microcontroller will be cycling through each of these lines and toggling them to logical high, then the input lines will be checked one-by-one to see which key has been pressed.
SRCLK and RCLK of the shift register can be connected for our project. Also, the output pins (A-H) of the shift register cannot read input signals, so make sure to have its 8 pins as outputs into your matrix (rows or columns, depending what you decided).
All of the input pins should have a 10 kOhm resister tied to the ground pin of the microcontroller. This ensures that there are no "floating" pins.
At this point, drawing a circuit diagram is very helpful for troubleshooting. Use the datasheet of the shift register and Arduino to determine what pins you should be connecting to.
Step 4: Test Your Circuit
It's important at this point to test your circuit. Use a breadboard to plug in your Arduino Pro Micro, resistors and shift register. Then, run wires according to your wiring diagram to the keypad terminals.
Once you are satisfied, you can move on to the code.
Setup and FAQ:
If you've never used an Arduino before, look here for more information: http://media.nbcmontana.com/class/Arduino-Class/
If you are using a knock-off version of the Arduino Pro Micro, there are a few issues you can run into.
The first is that you may need the CH340G driver, which can be found on the following website: http://www.wch.cn/download/CH341SER_MAC_ZIP.html Translate the webpage to English, then choose the driver that fits your operating system. If you still have trouble with it, here's a guide: https://learn.sparkfun.com/tutorials/how-to-instal...
The second issue could be that your knock-off uses the older bootloader. The following link helps navigate that: https://arduino.stackexchange.com/a/51985
It is advised that you test your microcontroller with the Blink sketch, to ensure everything is working as intended. I recommend that you don't code the whole program right away, but instead do it in steps to make troubleshooting easier.
Teaching how to code is outside of the scope of this Instructable, but here is a high-level view of what your program should include:
A loop that toggles each output on one at a time, and then a nested loop to check all input pins to see if they received a "High" signal. If a signal is detected, a function should be called. The arguments should be which output pin is currently on, and which input pin received a signal.
The function will use the given input and output pins to look up what switch has been pressed. Nested switch statements work nicely for this. Once a button is found, the action will be executed. For now, just print to the serial output with Serial.println("A1") .
This is a good time to test every button to make sure you mapped the keys correctly!
Here's a copy of my program: https://github.com/fwacer/hotkeyboard/blob/master/...
Please note that my nested switch statements do not cover all combinations of key presses, because they do not exist on my keyboard. This is due to how it was wired on the PCB by the original designer.
Step 5: Adding Functionality and Shortcuts
This step is the reason that we were only allowed to use certain models of Arduino microcontrollers. We'll be using NicoHood's HID Project library (or the Arduino Keyboard library) to emulate key presses to the computer we're attached to. You'll need to add your chosen library by using the following steps: https://www.arduino.cc/en/guide/libraries#toc2 then adding the line: #include "HID-Project.h"
Test first that the keyboard library is working. Here's an example that you could add to your sketch's "setup()" function (if using HID Project):
Once you have it working, a good starting point is to program your switches to have the action of typing their identifier: For example, A1 would type "A1". When you are more familiar, you can try creating shortcuts, such as CTRL+T to open a new tab in your web browser. See my code for examples of shortcuts as well as simple number typing (for the number pad).
Some useful links:
Definitions of special characters used by NicoHood's library: https://github.com/NicoHood/HID/blob/master/src/Ke...
The Arduino Keyboard library (more limited, and actually was made by NicoHood as well): https://www.arduino.cc/reference/en/language/funct...
If you're on Windows, there is a neat feature that allows you to type all sorts of characters. If you hold ALT then type numbers on the numberpad, when you release it will result in a special character. These are also known as ALT Keycodes. Here is the website I used to determine the codes for the Greek letters on my keyboard: https://usefulshortcuts.com/alt-codes/greek-alt-co...
Step 6: Make It Stick
It's finally time. Time to disconnect the circuit from the breadboard (gasp!) and solder it together. Double check that your diagram matches your working prototype, since that is all you will have. Taking pictures is not a bad idea!
If you purchased individual buttons, you'll want to build the enclosure first to make this step easier. Go to the next step, then come back!
Using a small electronics perforated board to solder the components to is advised. You also should solder headers for the arduino to plug into, in case it ever needs to be replaced. It's also a good to use different colour wires for your "columns" and your "rows", as you can see I did in the photo.
I chose to add a speaker and a "volume" knob for it, but it's definitely not necessary. I just wanted to be able to rick roll people at the push of a button! Note: if you want to do something similiar, only certain pins have the tone() functionality. I used pin 9.
Finally, make test your connections with a multimeter on continuity mode. Make sure everything that should be connected is, and everything that shouldn't be isn't!
Now, plug it in. Does it light up, do the buttons work? If not, unplug and continue troubleshooting. It's good to break down the problem into sections, so you can eliminate possible errors. Double check your diagram!
If it all works, now it is time to build the enclosure!
Step 7: Build the Enclosure
There's two main ways to do this step. You could purchase a project box that matches the size of your keypad, or you could build a custom one out of MDF or a similar easily workable material. If you buy a project box, make sure that it's deep enough for all of your wiring, the buttons and the Arduino Pro Micro itself!
For a pre-built project box:
By using a pre-built box, you may not have to paint! Avoid marring the surface by covering the outside with painter's tape. Drill your holes and use a chisel and file as required to "square up" the holes. Don't forget the hole for the USB cable!
If you're not planning on painting, assembling the electronics before soldering is a great idea.
For a custom box:
Due to the size of my salvaged keypad, I decided to make a custom box out of 1/8th inch MDF. I drilled pilot holes with a drill press, then cut out the square shapes required for the switches with a chisel. I then smoothed out the edges with a file. After a lot of work, it fit nicely over the top face of the keys.
After finishing the top face with sandpaper, I realized that it sat lower than I wanted on the keys, so I added some spacers on the underside, held to the top face with wood glue.
The edges of the box were measured and cut, then glued up using some squaring corners that included a ratchet. Due to the small thickness of the wood, I had to be careful to not tighten the clamp too much.
After the bottom and sides were glued into one shape, I countersunk some holes into the bottom face so that 4 nuts could fit. Long screws will come down from the top to hold the lid on.
To the edges, I also added a hole for the USB cable to pass through. It would have been better to do this before gluing all of the pieces together.
Make sure your electronics assembly fits before moving to each next step!
Step 8: Finishing Touches
If you choose to paint your enclosure, I recommend going for a non-glossy finish.
I tested my chosen paint (black satin) on some spare MDF, and noticed that the finish was mottled and unappealing. I tried on another test piece by first sealing the wood with a shellac sealer and primer, which resulted in a much smoother finish. Painting should be done in a well ventilated area with some backdrop (flattened cereal boxes work well), and some risers to get the material off of the backdrop is recommended to avoid it sticking.
I used this method to paint the entire enclosure, sanding lightly in between coats, and finishing off with a clear sealer to reduce the chance of scratching the surface.
After this is complete, put your electronics back in, and admire your handiwork.
Step 9: Complete!
Thank you for coming on this journey with me! If you make or adapt this project, please let me know! I'd love to see it.
Participated in the