Single-Wire 4×4 Matrix Keypad Using AVR

Nitin Kisan Khaire has many years of experience in product development and software validation. He has worked for engraving machine development using CPLD, FPGA and microcontrollers


Compiling and programming

AVR Studio is an integrated development environment that includes an editor, assembler, etc. WinAVR is a GCC-based compiler for AVR. It also includes a program called Programmer’s Notepad that can be used to edit and compile ‘C’ programs. WinAVR setup file is available at the website.

Remember to install AVR Studio before installing WinAVR. First, launch AVR Studio from the desktop. You need to create a new project for the main.c code. Next, click ‘Build Rebuild All’ to compile the ‘C’ code.

If there is no error message, a file called Single_wire.hex will be generated. This file contains the machine code that is ready to be programmed into the ATmega32 microcontroller. The file is stored in sub-folder ‘\default’ of your project.

If there are error messages, check your ‘C’ code. Most often these are caused by some typo or syntax errors.

Burn the hex code into the chip using any standard AVR programmer. At EFY Lab, we used ProgISP programmer to burn the hex code into the AVR microcontroller.

Download source code

Construction and testing

An actual-size PCB layout of the single-wire 4×4 keypad is shown in Fig. 3 and its components layout in Fig. 4. After assembling the circuit, enclose it in a suitable box.
Connect the secondary of transformer X1 to connector CON1 and primary to the AC mains via power cord. Mount LCD1 on the PCB and put the assembled PCB in a small cabinet. Fix switch S17 on the front side of the cabinet to switch on the circuit.

PCB layout of the single-wire 4x4 keypad

Fig. 3: PCB layout of the single-wire 4×4 keypadComponents layout for the PCB

Fig. 4: Components layout for the PCB

Download PCB and component layout PDFs: click here

Testing is relatively simple and user-friendly. When you connect 9V power supply to the circuit via switch S17, LED1 glows, indicating the presence of power supply in the circuit. Wait for initialisation of LCD1 and microcontroller IC2. If everything is fine, you will see ‘No Key Press’ message on the LCD, as shown in Fig. 5.

Message on the LCD when the circuit is powered on

Fig. 5: Message on the LCD when the circuit is powered on

You can press any pushbutton. The corresponding value is displayed on the LCD. Fig. 6 shows the message on the LCD when pushbutton S13 is pressed.

Message on the LCD when pushbutton S13 is pressed

Fig. 6: Message on the LCD when pushbutton S13 is pressed

First, check proper power supply at test point TP1 with respect to TP0. The voltmeter should read 9V-12V. Next, check the voltage at TP2, which should be 5V. If you don’t get 5V, either 7805 is faulty or there is some connection problem (short or open) in the circuit.

At TP3, check 5V supply for LCD1. Vary LCD1 contrast control by turning the preset (VR1) wiper right or left till you get text characters displayed on LCD1. Now, press switch S1 and check the voltage between TP4 and TP0. It shall be approx 0.455V. Repeat the same steps for all the keys by referring to Table I.



Please enter your comment!
Please enter your name here