Lab set Program-12
Interfacing a Keypad Module to Record Keystrokes (Tinkercad Simulation)
Objective
To develop a program that interfaces a keypad module with Arduino and records the user’s keystrokes by displaying them on the Serial Monitor.
Learning Outcomes
By the end of this experiment, students will be able to:
-
Understand the working of a matrix keypad.
-
Interface a 4×4 (or 4×3) keypad with Arduino in Tinkercad.
-
Detect key presses and display them on the Serial Monitor.
-
Use keypad libraries to simplify row–column scanning.
Components (from Tinkercad Palette)
-
Arduino Uno
-
4×4 Keypad module (available in Tinkercad)
-
Breadboard (optional)
-
Jumper wires
Circuit Wiring (Exact)
The Tinkercad keypad has 8 pins arranged as:
-
Row pins (R1–R4)
-
Column pins (C1–C4)
Connect as follows:
| Keypad Pin | Arduino Pin |
|---|---|
| R1 | 2 |
| R2 | 3 |
| R3 | 4 |
| R4 | 5 |
| C1 | 6 |
| C2 | 7 |
| C3 | 8 |
| C4 | 9 |
(If you use a 4×3 keypad, ignore the last column.)
Arduino Sketch
This program uses the Keypad.h library included in Tinkercad.
#include <Keypad.h>
// Define keypad layout
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] = {2, 3, 4, 5}; // R1, R2, R3, R4
byte colPins[COLS] = {6, 7, 8, 9}; // C1, C2, C3, C4
// Create keypad object
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
}
void loop() {
char key = keypad.getKey(); // Read pressed key
if (key) { // If a key is pressed
Serial.print("Key Pressed: ");
Serial.println(key);
}
}
How It Works (Student Explanation)
-
The keypad is made of rows and columns forming a grid of switches.
-
When a key is pressed, it connects a row line to a column line.
-
The Keypad library scans rows and columns very fast to detect which key was pressed.
-
Arduino receives the character and prints it on the Serial Monitor.
-
Each key press is displayed as:
Key Pressed: 5 Key Pressed: A Key Pressed: 0
Common Mistakes & Quick Fixes
| Issue | Cause | Fix |
|---|---|---|
| No key registration | Wrong row/column wiring | Recheck R1–R4, C1–C4 connections |
| Random characters | Wiring order mismatch | Ensure keypad pins match rowPins & colPins arrays |
| Nothing in Serial Monitor | Forgot to start simulation or baud mismatch | Start simulation and ensure 9600 baud |
Viva / Check-Your-Understanding
-
What type of scanning technique does a keypad use?
-
What is the purpose of separating row and column pins?
-
Why do we use a library for keypads?
-
What are the possible applications of keypad interfacing?
-
How many keys can be supported in 4×4 keypad?
Extensions (Mini-Tasks)
-
Record a 4-digit password and check if it matches.
-
Display keystrokes on an LCD (16×2).
-
Play a buzzer tone whenever a key is pressed.
-
Build a simple security lock using keypad input.
Lab Record (Suggested Headings)
-
Title
-
Objective
-
Components Required
-
Circuit Diagram
-
Arduino Code
-
Output Observations
-
Learning Outcomes
-
Viva Questions
-
Result
It shows how to interface a keypad module with an Arduino in Tinkercad so you can record keystrokes and display them on the Serial Monitor using the Keypad library.
ReplyDeleteBest Regards
NDIS Home Assistance