2-Wire Keypad Interface Using a 555 Timer using pic microcontoller

2 Wire Keypad Interface

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.

2 Wire Keypad Interface

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.

Theory

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?

2 Wire Keypad Interface

Circuit diagram

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.

The values of R1 and C are 1 K and 0.01 uF. The following table shows the different values of R2 for each keys, the corresponding frequencies, and the number of times the Timer0 module overflows. Some of these resistors are made from combining two resistors together.

Frequency and Pulse outputs

There are two outputs in this circuit. One is the frequency output derived directly from pin 3 that is fed to the T0CKI (Timer0 input) pin of a PIC16F628A microcontroller for counting. The second one is the smoothed pulse output using a capacitor Cp at the output of 555. When a key is pressed, the train of pulses at the output of 555 is smoothed out to a single pulse by the capacitor. This pulse is to signal the microcontroller when a key is pressed. The Rp (3.6 K) resistor provides the discharge path for the capacitor when the key is released so that another pulse would appear for next key press. The diode (D1) isolates the two outputs.

 

Leave a Comment

Your email address will not be published. Required fields are marked *