Key Scanning with a Small Number of Connections Schematic Circuit Diagram
If a large number of keys have to be scanned, the individual keys are not normally connected directly to the microcontroller. Instead, a matrix arrangement is used. This allows the number of port pins to be reduced to seven for twelve keys, for example. The software scans the rows and columns and thus determines which key is pressed. However, sometimes only a small microcontroller with just a few port pins is available, so even this economical matrix method cannot be used.
Using a trick, the same problem can be solved using only four port pins. This requires the use of four extra diodes and the possibility of individually configuring the pins as either inputs or outputs via software. Four column lines (1- 4) are arranged in a matrix with the four-row lines (A-D) that are connected to the microcontroller, with each row line connected to a column line by a diode (1N4148).
The software can recognize a pressed key by applying a voltage to each row in turn while observing the states of the remaining port pins, which are configured as inputs. Thanks to the diodes, a voltage will be detected on only one of the inputs, depending on which key is pressed, and the software can assign the appropriate action to this event.
The 1N4148 diode is a reliable semiconductor that engineers have relied upon for years. However, Vishay Intertechnology no longer offers this diode for new applications. Instead, an alternative component, the 1N4148W–which is RoHS compliant and AEC-101 stress test qualified–is recommended for new designs.
The 1N4148 datasheet should be supported with accurate CAD drawings to best utilize the diode for fast-switching applications. Ultra Librarian offers a vast library of data; such as access to datasheets, ECAD models, and simulation and testing information for your ECAD of an electronic component in one place. In addition, to avoid supply chain bottlenecks, you may check for component availability status, price, and models available from different vendors.