• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Get free circuit help 24/7

New Projects | Privacy Policy | About us | Contact | Disclaimer | Copyright | Videos 

You are here: Home / 324 IC Circuits / How to Interface 4×4 Keypad with Arduino

How to Interface 4×4 Keypad with Arduino

Last Updated on July 6, 2019 by Swagatam

In this post we are going to learn how to interface a 4x4 keypad with Arduino. We are going to see what is a keypad, how it is constructed and a how to program the Arduino to receive keystrokes form the keypad and print them in serial monitor.

What is a keypad?

A keypad is a portable keyboard in small form factor with sets of numbers, alphabets and special characters or combination of all three. In this project we are going to take a look at 4x4 matrix keyboard which has all the three types of keys specified above.

It is called 4x4 because it has 4 rows and 4 columns, arranged in matrix form. It has numbers from 0 to 9, special character “#” and “*” and alphabets from A to D. There are other types of keypad like 4x3, 8x8 etc. The most common types are 4x4 and 4x3.

For 4x4 keypad, four connections from rows and four connections columns are made for communicating with microcontroller, so totally there are 8 pins.

This may consume lots of I/O pins from Arduino and leave less number of I/O pins for other peripherals, there other methods to receive keystrokes by utilizing few pins of Arduino, which are not covered in this article.

 Construction Details:

The connection circuit is illustrated below:

caution electricity can be dangerous

As we can infer from the above diagram, each keys are connected to one row and one column. When any one of them are depressed, for instance number 1, R1 and C1 gets connected, this signal will be received by arduino or any microcontroller and determine which key is pressed, for each key, unique connections are made.

We can get 4x4 keypad from e-commerce website or local electronics retailer or you can make one from the diagram above. You just need 16 push buttons for 4x4 keypad and a general purpose PCB. The connections can be made from the above diagram and you made one for yourself.

Arduino Keypad circuit diagram and program:

How to Interface 4x4 Keypad with Arduino

Here is a prototype, where connections are made by using male to male header pins. The rest of the circuit is self explanatory.

Here's how it is connected to Arduino:

Note: care should be taken while connecting the pins from keypad to arduino, any improper connections or any wires interchanged, it can mess your whole project.

All the connections are made sequentially from pin #2 to pin #9 of Arduino and keypad. That’s all about hardware connections now let’s move to coding part.

Program Code:

//---------------Program developed by R.Girish------//
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9,8,7,6};
byte colPins[COLS]= {5,4,3,2};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}
void loop(){
char key = keypad.waitForKey();
delay(100);
Serial.print("You pressed: ");
Serial.println(key);
}
//---------------Program developed by R.Girish------//

Output:

 

Using the Keypad

In the program two dimensional array concept is utilized, as we can see the same layout is made in the program as in the keypad. The row pins are 9, 8, 7, 6 and the pins columns are 5, 4, 3, and 2.

We used a line “char key = keypad.waitForKey();” which means the programs will wait for a key to be pressed and the depressed key will get stored in a variable ‘key’. This variable is printed in the serial monitor using “Serial.print();.

If you are wondering where keypads are used? Well, here is the answer. It is used everywhere, where a user need to give input to any machine for example: the Smartphone or the computer you are using right now, ATM machines, vending machines, printers, controls on your TV remote etc.

By now, you know quite a bit about keypads and how to interface them with an Arduino, now it’s time to use your imagination to build your own projects.

You need to download and add the keypad library from the following link: github.com/Chris--A/Keypad . otherwise the above program won't compile

You'll also like:

  • 1.  Raspberry Pi Explained
  • 2.  4 Simple Li-Ion Battery Charger Circuits – Using LM317, NE555, LM324
  • 3.  Fading an LED ON/OFF – Arduino Basics
  • 4.  2 Simple Bidirectional Motor Controller Circuits Explored
  • 5.  Introduction to EEPROM in Arduino
  • 6.  Sinewave UPS using PIC16F72

About Swagatam

I am an electronic engineer (dipIETE ), hobbyist, inventor, schematic/PCB designer, manufacturer. I am also the founder of the website: https://www.homemade-circuits.com/, where I love sharing my innovative circuit ideas and tutorials.
If you have any circuit related query, you may interact through comments, I'll be most happy to help!

Have Questions? Please Comment below to Solve your Queries! Comments must be Related to the above Topic!!

2 Comments
Newest
Oldest
Inline Feedbacks
View all comments

Primary Sidebar

Categories

  • 3-Phase Power (15)
  • 324 IC Circuits (19)
  • 4017 IC Circuits (52)
  • 4060 IC Circuits (26)
  • 555 IC Circuits (99)
  • 741 IC Circuits (20)
  • Arduino Engineering Projects (83)
  • Audio and Amplifier Projects (115)
  • Battery Chargers (83)
  • Car and Motorcycle (94)
  • Datasheets (73)
  • Decorative Lighting (Diwali, Christmas) (33)
  • Electronic Components (101)
  • Electronic Devices and Circuit Theory (36)
  • Electronics Tutorial (120)
  • Fish Aquarium (5)
  • Free Energy (34)
  • Fun Projects (13)
  • GSM Projects (9)
  • Health Related (20)
  • Heater Controllers (29)
  • Home Electrical Circuits (103)
  • How to Articles (20)
  • Incubator Related (6)
  • Industrial Electronics (28)
  • Infrared (IR) (40)
  • Inverter Circuits (98)
  • Laser Projects (12)
  • LED and Light Effect (93)
  • LM317/LM338 (21)
  • LM3915 IC (25)
  • Meters and Testers (66)
  • Mini Projects (149)
  • Motor Controller (67)
  • MPPT (7)
  • Oscillator Circuits (26)
  • PIR (Passive Infrared) (8)
  • Power Electronics (34)
  • Power Supply Circuits (79)
  • Radio Circuits (10)
  • Remote Control (48)
  • Security and Alarm (61)
  • Sensors and Detectors (121)
  • SG3525 IC (5)
  • Simple Circuits (75)
  • SMPS (29)
  • Solar Controllers (61)
  • Timer and Delay Relay (53)
  • TL494 IC (5)
  • Transformerless Power Supply (8)
  • Transmitter Circuits (41)
  • Ultrasonic Projects (16)
  • Water Level Controller (45)

Calculators

  • AWG to Millimeter Converter
  • Battery Back up Time Calculator
  • Capacitance Reactance Calculator
  • IC 555 Astable Calculator
  • IC 555 Monostable Calculator
  • Inductance Calculator
  • LC Resonance Calculator
  • LM317, LM338, LM396 Calculator
  • Ohm’s Law Calculator
  • Phase Angle Phase Shift Calculator
  • Power Factor (PF) Calculator
  • Reactance Calculator
  • Small Signal Transistor(BJT) and Diode Quick Datasheet
  • Transistor Astable Calculator
  • Transistor base Resistor Calculator
  • Voltage Divider Calculator
  • Wire Current Calculator
  • Zener Diode Calculator

© 2023 · Swagatam Innovations

wpDiscuz