Unexpected behaviour on 3x4 keypad on arduino UNO R4

I'm using a 4x3 membrane keypad and Arduino UNO R4 Wifi to test my keypad.

My R1-R4 was plugged into 7~10 and C1-C3 was plugged into 4~6

here is my code to test it

/* @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 static int ROWS = 4, COLS = 3;

static char KEYPAD[4][3] = {
    {'1', '2', '3'}, 
    {'4', '5', '6'}, 
    {'7', '8', '9'}, 
    {'*', '0', '#'}
};

// NOTE: Change the pins if physical pins are changed
static byte rowPins[ROWS] = {10,9,8,7};
static byte colPins[COLS] = {6,5,4};

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

void setup(){
  Serial.begin(9600);
}
  
void loop(){
  char customKey = customKeypad.getKey();
  
  if (customKey){
    Serial.println(customKey);
  }
}

However, since it start running,a bunch of random number just output in the serial and I even didn't press anything.
I try to pressed 1 and output is 777777777777777100000000000
what could the problem be? Does the membrane keypad requires a insulated platform?

I used your code in the simulator and it worked normally.
The simulator only has a 4x4 keyboard, but since I didn't use the fourth column, it's the same as your 4x3.
Check if there is any wrong connection or bad contact in the connections.

Simulated at: KeyPad - Wokwi ESP32, STM32, Arduino Simulator

Ps:
Sorry my answer. I think Arduino R3.

The following does not work right with the Uno R4 core:

  1. Uno R4 core is based on ArduinoAPI which defines INPUT_PULLUP as an enum, not a macro.
  2. Uno R4 core does not emulate AVR "write HIGH to an input pin to enable pullup".

This should fix it: change

#ifndef INPUT_PULLUP

to

#if !defined(INPUT_PULLUP) && !defined(ARDUINO_API_VERSION)
  1. Under wokwi.com >> diagram.json tab
  2. Find this line (search "keypad"):
{ "type": "wokwi-membrane-keypad", "id": "keypad1", "top": -40.4, "left": -71.2, "attrs": {} }
  1. Add this "columns" : "3" inside the empty braces of "attrs":{},:
{ "type": "wokwi-membrane-keypad", "id": "keypad1", "top": -40.4, "left": -71.2, "attrs": {"columns" : "3"} }
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.