How to Set Up a Keypad on an Arduino

In this tutorial, we are learning how to set up a keypad matrix with an Arduino. We use both type keypads i.e 4×3 keypad and 4×4 keypad. The output is shown in the serial monitor.

Keypads are used to giving outputs like passwords, menu navigation, gaming control, etc.

A 4×4 keypad has 4 rows and 4 columns whereas 4×3 keypad has 4 rows and 3 columns.

Must See:

Component Needed

  • Arduino
  • Keypad Matrix
  • Jumper Wires

Keypad Pinout

Keypad pinout

Working of Keypad Matrix

When we pressed a key it closes the switch and allows the current flow between column and row pin.

  • Normally when no button is pressed all the row pins are held LOW and all the column pins are held HIGH.
  • When the button is pressed the column is held at LOW.
  • Now Arduino knew the column button, its time to find the row from the button is. Now the row pins switched to HIGH
  • When the column pin rises again HIGH, Arduino finds the row pin that is connected to the button.

Pin Connection of Keypad with Arduino

Connect the Keypad pins with Arduino as follow. Skip the last one for the 4×3 keypad matrix.

Keypad PinsArduino Pins

Circuit Diagram of Keypad Matrix with Arduino

Circuit Diagram of Keypad Matrix

Code for 4×4 Keypad

Upload the below code and open the serial monitor. Now press keys and you can see the output key in the serial monitor.

Code for 4×3 Keypad Matrix

If you are using a 4×3 Keypad matrix than upload the below code.


output keypad with arduino

Some More Articles For You:

Scroll to Top