2-Wire Keypad Interface Using a 555 Timer using pic microcontoller
Keypads are a very commonly used input device in microcontroller-based systems. In a keypad, multiple switches are arranged in rows and columns so that they could be interfaced to a microcontroller with a minimum number of I/O pins. For example, a 12-key keypad is arranged in a 4×3 format, which allows to interface the 12 keys to a microcontroller with only 7 connections. The location of each key on the keypad is defined by two coordinates: the row and the column. When a key is pressed, it connects its row with its column. The microcontroller must scan all the rows and columns to find out which key has been pressed. This is the most common way of interfacing a keypad to a microcontroller. There are tons of resources on the internet regarding this technique and so I am not going to discuss it here.
Today, I am going to share with you about a new keypad interfacing technique that uses only two I/O pins of a microcontroller: one for signalling the microcontroller when a key is pressed, and the other is to read the key information. It is based on a 555 timer IC which is configured as an astable multivibrator. I am not sure if anybody has ever tried using a 555 IC for keypad interfacing, but this technique really works. I am going to demonstrate this with a 4×3 keypad (a standard telephone dial pad). A PIC16F628A microcontroller will read the output of a 555 timer IC, determine what key has been pressed, and display it on a character LCD module.
This technique is based on a very simple principle. The output frequency of a 555 astable multivibrator is defined by two resistors and a capacitor, as shown below.
If we fix R1 and C, the frequency can be varied by varying R2. In this technique, each key on the keypad connects a different R2 resistor when it is pressed, and therefore, generates a different output frequency. The microcontroller can then read the output frequency and determine which key was pressed. At first it does seem more complex as it may require floating point math regarding the frequency calculations. Besides, the frequency may not be precisely stable all the time. But this can be simplified with the proper selection of resistors and the use of the timer module inside the microcontroller. So here’s how it works:
When a key is pressed, a certain value of R2 resistor is connected between pins 7 (Discharge) and 6 (Threshold) of the 555 timer, completing the astable multivibrator circuit. The output pulses are counted for 100 ms through a timer module (used as counter) in the microcontroller. The microcontroller determines the pressed key from the number of times the timer has overflown. If the timer module overflows 5 times, the pressed key is 5. Similarly, if 0 key is pressed, the timer doesn’t overflow in the 100 ms window. Isn’t it simple now?
The figure below shows how the 12 keys are connected to the 555 timer IC to generate 12 different frequencies. R0 through R# are 12 different resistors corresponding to those frequencies. You can see when a key is pressed, the corresponding resistor is connected between pins 6 (Threshold) and 7 (Discharge) and the astable multivibrator circuit is completed.
We recommend EasyEDA for electronic circuit design.
From Schematic to PCB Production, Just Need One Tool
Free Circuit Design Software: learn to use Editor quickly and easily
Cheapest PCB: 10pcs 2-layers 10cm×10cm only $8.21, 3-day build time, 100% E-test
Current Project / Post can also be found using:
- keypad interfacing using 555