Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Maker and IoT Ideas
Published © CC BY-NC-SA

Designing a "more reliable" matrix keypad - Part 1

This is a show and tell of how I went about designing a more reliable matrix keypad for use with my projects.

BeginnerWork in progress2 hours191
Designing a "more reliable" matrix keypad - Part 1

Things used in this project

Hardware components

PCBWay Custom PCB
PCBWay Custom PCB
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Code

Demonstration Code

Arduino
This is some sample code, to test the operation of the KEYPAD using an Arduino UNO or similar
/* @file CustomKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates changing the keypad size and key values.
|| #
*/
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1','4','7','*'}, 
  {'2','5','8','0'}, 
  {'3','6','9','#'},
  {'A','B','C','D'}
};
byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8,9}; //connect to the column pinouts of the keypad
/*
 * Due to libraries being written by different peopple, and our definitions about
 * what a row and a column are, is different, note that the rows in the code
 * is actually the columns on my PCB. This becomes true, due to the fact that my
 * PCB has Diodes on each switch, and that thus makes current flow in only one
 * direction///
 * 
 * it also has the "side affect" that keys are layout in a strange "mirrored" and 
 * rotated way in the firmware. 
 * it does however NOT affect correct operation of the Kepyad Module at all
 * 
*/

const int LEDPin = LED_BUILTIN;
int ledState = LOW;
unsigned long prevmillis = 0;
const long interval = 1000;

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
  Serial.begin(115200);
  pinMode(LEDPin,OUTPUT);
}
  
void loop(){
  unsigned long currentMillis = millis();
  if (currentMillis - prevmillis >= interval) {
    prevmillis = currentMillis;
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }
    digitalWrite(LEDPin,ledState);
  }
  char customKey = customKeypad.getKey();
  
  if (customKey){
    Serial.println(customKey);
  }
}

Credits

Maker and IoT Ideas
97 projects • 25 followers
I design custom PCB solutions, usually with an IoT or Automation twist, to solve problems in my daily life. Sometimes also for other people.

Comments