• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Need circuit help? Post them in the comments! I've answered over 50,000!

Blog | Categories | About | Contact | Calculators-online
You are here: Home / Arduino Projects / How to Interface 4×4 Keypad with Arduino

DIY Circuits | Learn Basics | Arduino Coding




How to Interface 4×4 Keypad with Arduino

Last Updated on December 5, 2024 by Swagatam 2 Comments

In this post I have explained 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:

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:

  • schematic 1Color Detector Circuit with Arduino Code
  • P 20160912 005857 2How to Send and Receive SMS Using GSM Modem
  • speaker schemPlaying a Melody Using Arduino
  • Basic2Bjoystick 1How to Control Servo Motor Using Joystick

Filed Under: Arduino Projects Tagged With: 4x4, Arduino, Interface, KeyPad

About Swagatam

I am an electronics engineer and doing practical hands-on work from more than 15 years now. Building real circuits, testing them and also making PCB layouts by myself. I really love doing all these things like inventing something new, designing electronics and also helping other people like hobby guys who want to make their own cool circuits at home.

And that is the main reason why I started this website homemade-circuits.com, to share different types of circuit ideas..

If you are having any kind of doubt or question related to circuits then just write down your question in the comment box below, I am like always checking, so I guarantee I will reply you for sure!

Previous Post: « How to Generate Electricity from Piezo
Next Post: Sunrise Sunset Simulator LED Circuit »

Reader Interactions

Comments

GR says:
September 6, 2016 at 1:32 pm

Hi davis,

I am going to do something similar for the upcoming articles. so, stay tuned….

Regards

Reply
Davis Kakumba says:
September 6, 2016 at 8:44 am

its nice . now my request is how can i go about coding using arduino and that keypad to make a password door lock en unlock through pressing those digits on keypad , which makes a door open when certain digits a pressed and closes when other digits are pressed. great thanks

Reply

Need Help? Please Leave a Comment! We value your input—Kindly keep it relevant to the above topic! Cancel reply

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

Primary Sidebar

circuit simulator image



Subscribe to get New Circuits in your Email



Categories

  • Arduino Projects (95)
  • Audio and Amplifier Projects (133)
  • Automation Projects (18)
  • Automobile Electronics (103)
  • Battery Charger Circuits (87)
  • Datasheets and Components (109)
  • Electronics Theory (149)
  • Energy from Magnets (27)
  • Games and Sports Projects (11)
  • Grid and 3-Phase (20)
  • Health related Projects (27)
  • Home Electrical Circuits (13)
  • Indicator Circuits (16)
  • Inverter Circuits (95)
  • Lamps and Lights (159)
  • Meters and Testers (71)
  • Mini Projects (28)
  • Motor Controller (68)
  • Oscillator Circuits (28)
  • Pets and Pests (15)
  • Power Supply Circuits (91)
  • Remote Control Circuits (50)
  • Renewable Energy (12)
  • Security and Alarm (64)
  • Sensors and Detectors (106)
  • SMPS and Converters (34)
  • Solar Controller Circuits (60)
  • Temperature Controllers (43)
  • Timer and Delay Relay (49)
  • Voltage Control and Protection (42)
  • Water Controller (37)
  • Wireless Circuits (31)





Other Links

  • Privacy Policy
  • Cookie Policy
  • Disclaimer
  • Copyright
  • Videos
  • Sitemap



People also Search

555 Circuits | 741 Circuits | LM324 Circuits | LM338 Circuits | 4017 Circuits | Ultrasonic Projects | SMPS Projects | Christmas Projects | MOSFETs | Radio Circuits | Laser Circuits | PIR Projects |

Social Profiles

  • Twitter
  • YouTube
  • Instagram
  • Pinterest
  • My Facebook-Page
  • Stack Exchange
  • Linkedin



Recent Comments

  • Duff Kindt on Door Security Alarm Circuit for Alerting if Door was Opened
  • Swagatam on Arduino 2-Step Programmable Timer Circuit
  • Swagatam on How to Manufacture Automobile Electronic Parts and Earn a Handsome Income
  • Ghulam Mohio Din on Arduino 2-Step Programmable Timer Circuit
  • Swagatam on Door Security Alarm Circuit for Alerting if Door was Opened

© 2026 · Swagatam Innovations