14 pin 3x4 Velleman Keypad (NO MATRIXING)

Hello. I bought this keypad from Amazon and it appears to not have any matrixing. There are 14 pins. The first pin is COM (ground), the second is "/", and the other 12 are for each individual button. Pins 3-6 are the first column (*, 7, 4, 1), pins 7-10 are the second column (0, 8, 5, 2), and pins 11-14 are the third column (#, 9, 6, 3). I have the button pins all connected in a line from I/O pins 2-13 on an Arduino UNO.

#define PIN_NUM1 2
#define PIN_NUM2 3
#define PIN_NUM3 4
#define PIN_NUM4 5
#define PIN_NUM5 6
#define PIN_NUM6 7
#define PIN_NUM7 8
#define PIN_NUM8 9
#define PIN_NUM9 10
#define PIN_STAR 11
#define PIN_NUM0 12
#define PIN_HASH 13

unsigned int pins[12] = {PIN_NUM1, PIN_NUM2, PIN_NUM3, PIN_NUM4, PIN_NUM5, PIN_NUM6, PIN_NUM7, PIN_NUM8, PIN_NUM9, PIN_STAR, PIN_NUM0, PIN_HASH};
unsigned char buttons[12] = {'*', '7', '4', '1', '0', '8', '5', '2', '#', '9', '6', '3'};

void setup()
{
  // Set keypad pins
  pinMode(PIN_NUM1, INPUT);
  pinMode(PIN_NUM2, INPUT);
  pinMode(PIN_NUM3, INPUT);
  pinMode(PIN_NUM4, INPUT);
  pinMode(PIN_NUM5, INPUT);
  pinMode(PIN_NUM6, INPUT);
  pinMode(PIN_NUM7, INPUT);
  pinMode(PIN_NUM8, INPUT);
  pinMode(PIN_NUM9, INPUT);
  pinMode(PIN_STAR, INPUT);
  pinMode(PIN_NUM0, INPUT);
  pinMode(PIN_HASH, INPUT);

  Serial.begin(9600);
}

void loop()
{
  char key = getKey();
  if (key)  // Check for a valid key.
  {
    Serial.println(key);
  }
}

char getKey()
{
  for (int i = 0; i < 12; i++)
  {
    if (digitalRead(pins[i]) == LOW)
    {
      return buttons[i];
    }
  }
}

This is my code so far that I am testing. Whenever I compile, it just spams random-ish characters, usually astericks (*). I am trying to just make a functional keypad. Is there any way for me to make this functional or better?

Try setting the pinMode to INPUT_PULLUP, the inputs will be floating and give random HIGH/LOW readings.

I have tried that, it simply stopped me from inputting/there was no Serial output at all.

edit: I told it to print digitalRead(pins[i]) through every iteration (for debugging) and it continually prints "1" and occasionally an empty square ""

You need a return value from the getKey() function when no input is LOW. I would have thought the compiler would warn you about that.

Try

char getKey()
{
  for (int i = 0; i < 12; i++)
  {
    if (digitalRead(pins[i]) == LOW)
    {
      return buttons[i];
    }
  }
  return 0;
}

since you seem to have coded your test for a key as any non-zero value.

It is semi-working. When I used "INPUT_PULLUP" and attempted to press buttons, there was no response in the Serial console. When I reverted to "INPUT", in the Serial console it continually prints an asterisk like this:

image

...until I press/hold a number, at which point it prints like this:

image
In the above picture, I was holding "9".

Sometimes when I tap the keypad or move it, it will spit out random numbers in the mess of asterisks. Also, when I connect the pins with my fingers, it will sometimes print a number consistently. So it kinda works, but I just don't get why it doesn't actually work.

edit: @anon57585045 ^

Do you debounce the keys?

You need a pull-up of some type, either internal or external resistors.

Your code will continuously print any key that is held down, there is not detection of when the key goes from not pressed to pressed, only if it is pressed.

You could also try the Keypad library, it should support a 1x10 key matrix.

1 Like

How would I go about doing that? I've been researching for a while and no luck other than the Keypad library, which uses primarily matrixing.

Ahhh that makes more sense. Then the problem lies somewhere with my key detection, as when I have INPUT_PULLUP and attempt to press keys, I get absolutely nothing on my Serial monitor. I'll attempt the Keypad library, but would prefer to use the simplest method

I didn't notice the lack of state change detection, that is an additional problem. There is a State Change Detection example sketch with the IDE that you can reference.

The simplest debounce is just a 20ms delay after detecting a key state change.

Please provide an authentic schematic diagram.

Run the simulation at:

"KeyCode - Wokwi ESP32, STM32, Arduino Simulator

I have used this code:

#define PIN_NUM1 2
#define PIN_NUM2 3
#define PIN_NUM3 4
#define PIN_NUM4 5
#define PIN_NUM5 6
#define PIN_NUM6 7
#define PIN_NUM7 8
#define PIN_NUM8 9
#define PIN_NUM9 10
#define PIN_STAR 11
#define PIN_NUM0 12
#define PIN_HASH 13

unsigned int pins[12] = {PIN_NUM1, PIN_NUM2, PIN_NUM3, PIN_NUM4, PIN_NUM5, PIN_NUM6, PIN_NUM7, PIN_NUM8, PIN_NUM9, PIN_STAR, PIN_NUM0, PIN_HASH};
unsigned char buttons[12] = {'*', '7', '4', '1', '0', '8', '5', '2', '#', '9', '6', '3'};
char key = '\0';
bool flag = false;

void setup()
{
  // Set keypad pins
  pinMode(PIN_NUM1, INPUT_PULLUP);
  pinMode(PIN_NUM2, INPUT_PULLUP);
  pinMode(PIN_NUM3, INPUT_PULLUP);
  pinMode(PIN_NUM4, INPUT_PULLUP);
  pinMode(PIN_NUM5, INPUT_PULLUP);
  pinMode(PIN_NUM6, INPUT_PULLUP);
  pinMode(PIN_NUM7, INPUT_PULLUP);
  pinMode(PIN_NUM8, INPUT_PULLUP);
  pinMode(PIN_NUM9, INPUT_PULLUP);
  pinMode(PIN_STAR, INPUT_PULLUP);
  pinMode(PIN_NUM0, INPUT_PULLUP);
  pinMode(PIN_HASH, INPUT_PULLUP);

  Serial.begin(9600);
}
//---------------------------------------------------------------------
void loop()
{
  char key = getKey();
  if (key)                    // Check for a valid key.
  {
    if(flag == true)          // One time only
    {
    Serial.print("Key "); Serial.println(key);
    flag = false;
    }
  }
}
//---------------------------------------------------------------------
char getKey()
{
  for (int i = 0; i < 12; i++)
  {
    if (digitalRead(pins[i]) == LOW)
    {
      return buttons[i];
    }
  }
  delay(100);         // Debouncing
  flag = true;         // allows 1 print
  return '\0';        // Clear key
}
1 Like

So strange. It works in the simulator, but I just tried it in a sketch with my device and nothing. At this point, I'm suspecting a faulty device but honestly I don't know. I tested each pin with an Ohm meter and it read fine.

I don't have a full "blueprint" per se, but I bought it from Amazon here and I found someone else's basic pinout in this Google Drive folder. I found it from someone who used this Keypad and got it to work with a prop from CS:GO in this Reddit thread. They even gave their whole project file in that Google Drive folder, and I've looked at it multiple times and it appears that my code closely resembles it, but alas.

Then, make one.


Whipped this up in Illustrator. It should be accurate, I just traced the lines from the back of the keypad using a flashlight.

That's just the keypad. I was asking for a complete system schematic. I hope you can understand why. If not, the forum introductory guide explains it quite well.

Have you tried the Keypad library yet? You said in post #10 that you would.

full schematic

Here is the full schematic/pinout for the setup. It's just an Arduino UNO with each pin from the keypad in a line up the digital I/O pins starting at pin 2. The ground is jumped to the GND pin at the very top.

I looked into the Keypad library, which I have used before on a 4x4 matrix-based keypad which worked, but I'm not sure how to implement the library (which is built for matrixes) into a non-matrix keypad. I tried looking up "1x10" too but found nothing with the library.

Do the following test:
With the code I wrote,
disconnect the keyboard from the arduino.
Connect a jumper to GND.
With one side of the jumper connected to GND,
touch and remove the other side from pins 2 to 13.
So on each pin that touches a number will be printed on the serial monitor.
BTW, how is your serial monitor configured?

1 Like