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:

  1. Understand the working of a matrix keypad.

  2. Interface a 4×4 (or 4×3) keypad with Arduino in Tinkercad.

  3. Detect key presses and display them on the Serial Monitor.

  4. 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)

  1. The keypad is made of rows and columns forming a grid of switches.

  2. When a key is pressed, it connects a row line to a column line.

  3. The Keypad library scans rows and columns very fast to detect which key was pressed.

  4. Arduino receives the character and prints it on the Serial Monitor.

  5. 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

  1. What type of scanning technique does a keypad use?

  2. What is the purpose of separating row and column pins?

  3. Why do we use a library for keypads?

  4. What are the possible applications of keypad interfacing?

  5. 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



Comments

  1. 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.

    Best Regards
    NDIS Home Assistance

    ReplyDelete

Post a Comment

Popular posts from this blog