Arduino Keypad 4×3 Basic Code Serial Monitor

Posted on

What is Arduino Keypad?

Arduino Keypad 4×3 – An Arduino keypad, also known as a button matrix or matrix keypad, is a device used to input numerical and/or alphanumeric data into an Arduino microcontroller. One common type of keypad is the 4×3 keypad, which has 4 rows and 3 columns of buttons.


Wiring

To use a 4×3 keypad with an Arduino, you will first need to connect the keypad to the Arduino board. The easiest way to do this is to use a keypad shield, which is a pre-made circuit board that connects directly to the Arduino board and has connectors for the keypad.

Arduino Keypad 4x3 Basic Code Serial Monitor
Arduino Keypad Wiring

If you do not have a keypad shield, you can also connect the keypad to the Arduino using jumper wires. Connect the rows of the keypad to digital pins on the Arduino, and connect the columns to other digital pins or to analog pins set to digital input.


Basic Code

Next, you will need to write code for the Arduino to read the keypad and respond to button presses. There are a few libraries available that can simplify this process, such as the Keypad library or the Matrix Keypad library. These libraries provide functions for reading the state of the keypad and determining which button, if any, has been pressed.


After the library has been added to the Arduino IDE, now please upload the program code below to your board. Then, open your serial monitor. Press the button on the keypad and see the results on your monitor serial.

#include <Keypad.h>

const byte ROWS = 4; // four rows
const byte COLS = 3; // three columns

char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
}

void loop(){
  char key = keypad.getKey();

  if (key){
    Serial.println(key);
  }
}

Finally, you can use the data from the keypad in your Arduino program to control other devices or to perform calculations. For example, you could use a keypad to enter a password to unlock a door, or to input data into a calculator program.

In summary, using a 4×3 keypad with an Arduino involves connecting the keypad to the board, using libraries to read button presses, and using the data in your program.

Read more:

Leave a Reply

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