Arnov Sharma
Published © MIT

Custom 5x5 Keypad

Made a 5x5 keypad Matrix from scratch.

BeginnerFull instructions provided1 hour689
Custom 5x5 Keypad

Things used in this project

Hardware components

Raspberry Pi Pico
Raspberry Pi Pico
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Seeed Studio Fusion PCB/PCBA
Seeed Studio Fusion PCB/PCBA

Story

Read more

Schematics

WIRING

SCH

Code

code

C/C++
#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
}
}

Credits

Arnov Sharma
338 projects • 344 followers
Just your average MAKER
Contact

Comments

Please log in or sign up to comment.