Interfacing Keypad with Arduino using TinkerCAD

Updated: Apr 10

Keypads are generally used as input devices that take input from the users and process it. Membrane keyboards are characterized by the use of keys that are pressure pads with symbols printed on them. This is in contrast to a mechanical keyboard, which features separate and individual keys. Because of their design, membrane keyboards are smaller and more compact than their mechanical counterpart.


Read this complete blog to learn - "how to connect 4x4 keypad to Arduino?"


A list of components required to implement the circuit both manually and using TinkerCAD is given below.

Hardware Requirements:


1. 4x4 Keypad:

4x4 membrane keypad

A 4x4 matrix keypad is used as an input device that takes inputs from the users. It consists of 16 pins in total with four rows and four columns. On pressing a key, a connection will be established between the corresponding row and column between which the switch is placed.


Check this project of 4*4 Keypad as well - Link.


2. Arduino UNO:

Arduino UNO

The Arduino is a programmable #microcontroller, it's an open-source electronics proto-type platform. It interacts with the user by receiving input with the aid of sensors and provides the output employing LED, buzzer, etc.,


In order to know more about the Arduino UNO, refer to this article.

Software Requirements:


TinkerCAD Software:

TinkerCAD sotware

It is an easy-to-use online simulation software that is equipped with all the essential components which are required to build the circuit and analyze it.


Visit the TinkerCAD website and learn how to use TinkerCAD.

Arduino Keypad Connection:


Circuit Diagram - Interfacing 4x4 Keypad with Arduino

Circuit connection involves the following steps :

  • The circuit connection involves very simple steps. In the keypad, there are 8 pins in total out of which 4 pins correspond to the Rows (viz., R1, R2, R3, R4) and the other four correspond to the Columns (viz., C1, C2, C3, C4).

  • The row pins are connected to 9, 8, 7, 6 Digital pins of the Arduino UNO.

  • The column pins are connected to 5, 4, 3, 2 Digital pins of the Arduino UNO.

Code Description:


Let us learn the code to interface the keypad with the Arduino UNO.

#include <Keypad.h>

The above line of code is to include the keypad library. This library is not generally installed in all Arduino applications. So we need to manually install this library. To install the library follow the steps mentioned goto sketch-> Include Library -> Manage Libraries now you will have a window pop up, in which we search for the keypad library. There will be many libraries with the name of Keypad, you can install the library by Mark Stanley and Alexander Brevig.

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

We declare two constants namely rows and cols, they are constant bytes because these 4 will not change in the entire code.

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

We declare a dimensional array with rows and columns named keys. The data type of this array is character. This is a 4x4 matrix with the elements mentioned.

byte rowPins[ROWS] = {9, 8, 7, 6}; 
byte colPins[COLS] = {5, 4, 3, 2};

We have given these numbers because, all the row pins are connected to 9, 8, 7, 6 and all the column pins are connected to 5, 4, 3, 2 accordingly.

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

We have created an object called a "keypad", in order to read the data and display it on the serial monitor.

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

We initiated the serial communication at the baud rate of 9600.

void loop(){
  char key = keypad.getKey();
  if (key){
    Serial.print("Key Pressed : ");
    Serial.println(key);
  }
}

Now in the loop, we read the input using the getkey() function and store it in the variable key. And if the key is pressed (i.e., if the variable key does not contain NULL) then we display the value stored in the key variable using serial.println function.


Arduino Keypad Interfacing Code:

#include <Keypad.h>

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

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}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

//Create an object of keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
}
  
void loop(){
  char key = keypad.getKey();// Read the key
  
  // Print if key pressed
  if (key){
    Serial.print("Key Pressed : ");
    Serial.println(key);
  }
}

Download the complete code:


interfacing keyboard with arduino
.docx
Download DOCX • 14KB

NOTE: To simulate the circuit in #TinkerCAD the default code present in the window needs to be removed and copy-paste the downloaded code.


Arduino - Keypad & LCD project working:

To start with first visit the TinkerCAD website. Create an account and move to the circuits section. By clicking on create a new circuit, you will be driven to a window where you can build the circuit. It will be equipped with all the components required and you can just drag the elements necessary and connections can be made using jumper wires.


To know more about TinkerCAD, you can just surf through the website or you can watch the video.

Upload the code in the code section and start simulating to check the output of your circuit.

The image below shows the output of the key we have pressed on the keypad.


Image showing the output - interfacing keypad with Arduino

Video by - Sri Harshitha

Simulation software plays a leading role in designing huge circuits which help to understand, analyze and provide outputs for a large set of input values which would be hectic doing it manually. It helps in avoiding any damage to the hardware by going beyond the rated value.


Validate your new circuit ideas and know the scope and boundaries of your circuit.

See Also -

1. How to interface a DC motor with Arduino UNO using TinkerCAD?

2.How to read a Digital Value from Arduino using Push Button? 3.Password Protected Security System project using Arduino, Keypad, Piezo Buzzer and LEDs on TinkerCAD


Follow us -


Please do follow us i.e #learnelectronicsindia to get daily updates about new blogs, videos, courses, quizzes, and contests.


Facebook | LinkedIn | Instagram | Youtube | Website | Gmail

  • Facebook
  • YouTube
  • Instagram
  • LinkedIn
LearnElectronics
Contact Us