Simple Switch board
4 key pushbutton PCB with LEDs
Front panel mounted with spacers of 4mm minus panel thickness
Individual wires or 'multiplexed' onto an analog signal
Most of our projects have some pushbutton switches; the most common quantity being one or four. This board, consequently, gets reinvented over and over for client projects. Here we have just made a standard version to reuse, and to offer as a quick interim solution.
The board comes is used in two versions, one with four individually wired switches - almost always with the switches being returned to OV or ground. The second is "multiplexed" - to reduce the number of wires required to connect the keyboard to the main board. There is also an option to put two surface mount LEDs in the keyboard which can act as illumination or status.
With a larger number of keys, multiplexing normally consists of row scan and column return lines, with diodes to stop key ghosting. A microprocessor asserts each row scan line in sequence while monitoring the column return lines for active keys. A 16 switch keyboard multiplexed in this fashion only requires 8 signals connecting from the microprocessor board to the keyboard, rather than the 16 signals and return that would be needed for an unmultiplexed keyboard.
However, the traditional method of multiplexing requires 4 signals to multiplex 4 keys - it is no real improvement on reading the keys directly. The alternative we use here is to "multiplex" the keys using an analog resistance, converted at the microprocessor into an analog voltage and read in through an A/D converter. "Multiplexing" is really a misnomer, but conveys the correct idea.
Our "multiplexed" keyboard only requires two wires back to the microprocessor for the 4 keys. (However, we add a LED signal to the board as well, and so need 3 wires.) At the microprocessor we have a series resistor of 330R (in order to limit current in the event of a miswire), and then a pullup resistor of 1.6k to the microprocessor supply rail. For best operation these resistors should be 1% tolerance type, as should the resistors doing the "multiplexing" on our keyboard.
Given these resistor values, the code for reading the keyboard becomes unbelievably simple. In Pseudo code the operation is:
Read value from A/D converter |
Add (FullRange / 12) to value |
Integer Divide value by (FullRange / 6) |
Result 0 = Key 1 pushed |
Result 1 = Key 2 pushed |
Result 2 = Key 3 pushed |
Result 3 = Key 4 pushed |
Result 4 = No Key pushed |
Result 5 = No Keyboard connected |
Parts list and notes
PCB size | H | W | H x W |
Metric | 27.9mm | 57.2mm | 1597mm2 |
Inches | 1.100in | 2.250in | 2.47in2 |
Total holes | 63 | 6 sizes | >=0.71mm |
There are two versions of this PCB - the standard one has all components populated except CN11, the IDC10. Connection for this version of the PCB is through CN12 the 3 way terminal block. Actually, the same connections are also available on CN10 if that is more convenient - but a 10 way connector is hardly economic when 3 wires are all that is required. The second version of the PCB just allows use of the four Tactile switches and LEDs individually - this version is constructed by ommitting R91-R93 and CN12. Connections for the 4 switches and LED are then available on CN11, the IDC10. In addition, usually this version does not use L11,L12,R95 or R96, so leaving off the LED function.
There are centre holes under each tactile switch, so for a one-of front panel a blank PCB laminate can be used as a template to drill pilot holes for the switch cutouts.
The PCB manufacturing files
©2013 AirBorn - Last updated 21 April 2013
Background Image Credit: Dust Pillar of the Carina Nebula: NASA, ESA, and M. Livio and the Hubble 20th Anniversary Team (STScI)