Custom 5x5 Keypad

by Arnov Sharma in Circuits > Electronics

243 Views, 4 Favorites, 0 Comments

Custom 5x5 Keypad

09.gif
06.gif
IMG_1451.JPG

Hello everyone, and welcome back. Here's something fun and useful. The customized 5x5 button matrix board built from scratch.

Here, we create a simple 25-button matrix board using a simple row-and-column framework, with buttons arranged in five rows and five columns to form a button grid. When you press the button, it completes the circuit between a row and a column, which is detected by the microcontroller and shown on the OLED screen.

The purpose of developing this project was to work on a calculator project that required as many buttons as possible; thus, we created this matrix board to aid us in the tinkering phase of the calculator project.

This article is about the whole build process of this oroject, so let's get started with the built.

Supplies

These were the materials used in this project:

  1. Custom PCB (provided by Seeed Studio Fusion)
  2. Tacktile Buttons
  3. Male header pin connector CON10
  4. Breadboard
  5. SSD1306 OLED Screen
  6. Raspberry Pi PICO 2
  7. Jumper Wires

Keypad Design Process

SCH_page-0001.jpg
Screenshot 2025-01-10 164610.png
Screenshot 2025-01-10 164422.png

We started with our project by arranging all of the buttons in five rows and five columns.

We created a button matrix (inspired by a key matrix board) in which all buttons are placed in a grid of rows and columns, with each row and column connected to a CON10 header pin connector.

The microcontroller scans the matrix by setting each row high and then checking each column. Pressing the button completes the circuit between a row and a column. Knowing which row is high and which column reads the signal allows the microcontroller to determine which button is pressed.

This method decreases the amount of I/O pins required, as we are using 25 buttons, and a standard method would require 25 I/O pins for all buttons; however, this method allows us to utilize only 10 I/O pins overall.

By creating the schematic, we were able to export the netlist and develop the board design for this project, which included placing the buttons in the GRID configuration and linking the traces according to the schematic. We completed the board and then exported the gerber data, which will be shared with a PCB manufacturer to create samples.

Seeed Studio Fusion

IMG_1097.JPG
01.gif

Following the completion of the Gerber data, we uploaded the file to Seeed Fusion's website and placed an order for a white Solder mask with black silkscreen.

PCBs were received in a week, and their quality was super good considering the rate, which was also pretty low.

Seeed Fusion PCB Service offers one-stop prototyping for PCB manufacture and PCB assembly, and as a result, they produce superior-quality PCBs and fast turnkey PCBAs within 7 working days.

Seeed Studio Fusion PCB Assembly Service takes care of the entire fabrication process, from Seeed Studio Fusion Agile manufacturing and hardware customization to parts sourcing, assembly, and testing services, so you can be sure that they are getting a quality product.

After gauging market interest and verifying a working prototype, Seeed Propagate Service can help you bring the product to market with professional guidance and a strong network of connections.

PCB Assembly Process

02.gif
03.gif
04.gif
05.gif
06.gif
  1. The assembly process begins with placing all 25 switches in their respective pads on the Matrix PCB; we are utilizing 6x6 Tacktile buttons here, and we must ensure that all buttons are correctly added to their pads, as some of the buttons' pins bend when placed in the footprint.
  2. Next, we solder all of the switch pads on the bottom side of the board with a soldering iron.
  3. Following that, we place a CON10 male header pin in its place and solder its pads from the top side of the board.

Matrix Board is now assembled.

Raspberry Pi Pico Setup

SCHS.jpg
07.gif
IMG_1450.JPG
IMG_1451.JPG
  1. Using a PICO 2, an OLED display, a breadboard, a button matrix, and a few jumper wires, we create a basic setup by connecting all of the column pins from C1 to C5 with GPIO16, GPIO17, GPIO18, GPIO19, and GPIO20.
  2. GPIO0, GPIO1, GPIO2, GPIO3, and GPIO6 connect rows 1 through 5.
  3. The OLED screen's VCC is connected to PICO's VBUS, while the GND is connected to GND.
  4. The SDA of the OLED is linked to PICO's SDA Pin (GPIO4), and the SCL is attached to GPIO5, which is PICO's SCL Pin.

CODE

Here's a quick test drawing we created to see if all of the button mapping is right.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Define OLED display dimensions
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Initialize the OLED display with I2C address 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Swap rows and columns
const int rows = 5;
const int cols = 5;
const int colPins[cols] = {16, 17, 18, 19, 20}; // Now column pins
const int rowPins[rows] = {0, 1, 2, 3, 6}; // Now row pins
int lastButtonPressed = -1;
void setup() {
Serial.begin(115200);
// Initialize the OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
// Initialize row pins as inputs
for (int i = 0; i < rows; i++) {
pinMode(rowPins[i], INPUT_PULLUP);
}
// Initialize column pins as outputs
for (int i = 0; i < cols; i++) {
pinMode(colPins[i], OUTPUT);
digitalWrite(colPins[i], HIGH);
}
}
void loop() {
bool buttonPressed = false;
for (int row = 0; row < rows; row++) {
digitalWrite(rowPins[row], LOW); // Activate row
for (int col = 0; col < cols; col++) {
if (digitalRead(colPins[col]) == LOW) { // Button press detected
lastButtonPressed = (rows - row - 1) * cols + col + 1; // Reverse button order calculation
buttonPressed = true;
delay(50); // Further reduced debounce delay
}
}
digitalWrite(rowPins[row], HIGH); // Deactivate row
if (buttonPressed) {
break; // Exit the loop once a button press is detected
}
}
// Display the last button pressed only if there's an update
if (buttonPressed) {
display.clearDisplay();
display.setTextSize(2); // Set text size larger
display.setTextColor(WHITE);
display.setCursor(0, 10); // Center text vertically
display.print("Btn: ");
display.print(lastButtonPressed);
display.display(); // Update the display
}
}

This code initializes an OLED display and sets up a button matrix with swapped rows and columns to detect button presses. When a button is pressed, it identifies which button was pressed, displays the button number on the OLED screen, and updates the display accordingly.

We are using the Adafruit_SSD1306 Library in this sketch, which you need to download and install first before using this code.

Conclusion

09.gif
IMG_1452.JPG

Here's the end result of this small butlt, a DIY Keypad matrix that can be used to add multiple buttons to any project by using only a few I/O pins. In this case, we have a total of 25 buttons that would require 25 I/O pins if connected regularly, but this matrix allows the user to only use 10 I/O pins to control 25 buttons, which is ideal if the microcontroller being used has limited I/O pins.

The purpose of developing this matrix was to create a compact calculator with an OLED screen combined to a Raspberry Pi Pico and a button matrix.

Leave a comment if you need any help regarding this project. This is it for today, folks, and stay tuned for the calculator project update.

Special thanks to Seeed Studio Fusion Service for supporting this project. You guys can check them out if you need great PCB and stencil service for less cost and great quality.

And I'll be back with a new project pretty soon, peace.