4x3 Keypad stops working when connected with long wires

Hi

I'm building a door lock that has a 4x3 keypad for entering the lock password.
While prototyping it works great.
I tried to connect the keypad with long wires (1.5 meters) so I could mount the keypad outside the door but I strated getting wonky readings from the keypad if any.
I'm guessing the wires length messes up the reading.
What can I do to resolve/bypass this issue?

Thanks

1 Like

Which interface do you use? Serial, SPI or direct digital pins? A circuit diagram (not Fritzing) would be helpful.

1 Like

Have you connected wire directly to the pin or have you soldered wire in between, kindly share your circuit diagram

1 Like

Adding also small capacitors (2nF o 10nF) to ground at the arduino inputs could help

if it's not enough, the code uses the built-in pull-up capabilities (see Keypad/Keypad.cpp at 801285059681542c43d35fb56c3847c11ce0023f · Chris--A/Keypad · GitHub) of your board. This internal pull-up is between 20kΩ and 50kΩ.

The length of the wire has probably an impact on noise and you need to explore a lower value for the pullup resistors on the switches as a low resistor value is called a strong pull-up (as more current will flows) but this is more sensitive to noise. Don't go below 10kΩ as the combined pull-up

Pull-up Resistors - SparkFun Learn

1 Like

Direct digital pins.
I'm using a node mcu esp32 controller with off the shelf 4x3 keypad.
When I'm using standart dupon wires it works great.

1 Like

I crimped my own long wires with dupon connectors.
For prototyping I used short ready made wires.

1 Like

Have you run a continuity test to ensure the connections are solid?

1 Like

Yes, more than once.
The cable itself is ok.

1 Like

Connect it to the MCU
Turn on a pin going into the keypad
Press a button and measure the output voltage at the MCU side of the other wire
See if you are getting something close to 3.3V

1 Like

Have you tried with caps and resistors ?

1 Like

Just pinout the Keypad and try blinking LED with the long wire.
And tell have you tried with caps and resistors ?

1 Like

How exactly do I need to connect them?
I'm an experienced SW engineer but I'm new to electronics.

1 Like

You could also try slowing down the scan rate while reading the keypad,. Another option would be to move the node mcu to the keypad and run the long wires to the lock mechanism, that may be more reliable.

1 Like

For each row pin you add (in parallel to going to the keypad) a resistor and then go to 5V

        5V
        |
        |
        R2
        |
        |
Pin ————————— row of KeyPad

The equivalent resistor when the R1 built in pull-up resistor is activated will be
Req = R1 x R2 / (R1 + R2)

If R1 = 50K and R2=2.2 K Ohms then for example you have Req = ~2K

(If R1 is very large compared to R2 R1+R2 is almost like R1 and thus the formula is basically R2 ➜ that’s how an external resistor can overrule the internal pull-up)

The capacitor would be similar but go to ground

        5V
        |
        |
        R2
        |
        |
Pin ————————— row of KeyPad
       |
      === 2 to 10 nF
       |
      GND

It’s there to absorb electromagnetic perturbations that your long wire is likely submitted to (it’s like an antenna)

EFIT: it’s 5V if your arduino uses a 5V for the pins otherwise use 3.3V or whatever is suitable for the platform. This is important especially if your MCU’s pins are not 5V tolerant

1 Like

Thanks for the detailed replies, you're awsome!!

As a SW guy, I'm leaning more toward SW solutions...
I've found a tutorial that connects a keypad to a 8pin digital to I2C expander module and then useS the keypad_I2C library instead of the regular one.
Will the I2C protocol work with 1.5 meter wires?
It only need two wires instead of 7 the keypad currently uses.

Also, in one other post I read that you can use a cat6 ethernet cable that has 8 wires, twisted in pairs and it is shielded. Will that work?

Thanks again for the amazing help.

1 Like

I’m a software guy too but you can’t beat physics law :slight_smile:

2 Likes

In all the code samples using the keypad library I didn't see it defines the pins I pass to it as INPUT_PULLUP pins.
I haven't checked if this library itself explicitly defines it in the code.

1 Like

follow my link to the source code in post 4


void Keypad::scanKeys() {
	// Re-intialize the row pins. Allows sharing these pins with other hardware.
	for (byte r=0; r<sizeKpd.rows; r++) {
		pin_mode(rowPins[r],INPUT_PULLUP);
	}
…

So the rows are set as INPUT_PULLUP

Shielded cables are good against EMF - so this can’t hurt

I2C has been invented for communication between two Integrated Circuit - so usually close together. It’s known to work for longer distance and pull-ups are also part of the answer

2 Likes

1. What do we do? We simply buy a Keypad and connect it with the DPins of the UNO as per Fig-1. Do we connect any external pull-up/pull-down resistors? No!
keyPadPic
Figure-1:

There are two types of Keypads -- walking 0 and walking 1.

The Keypad.h Library supports walking 0 Keypad; where, the column lines are sequentially made LOW and then the row lines are sampled to detect the unique (x, y) position of a closed key.

Therefore, the row lines must be terminated to 5V so that when a LOW appears on a column line, the corresponding row line will assume LOW state upon closure of the key located across the said row-column (for example: R1-C1).

So, the row lines are indeed connected with internal pull-resistors and is done by the Keypad.h Library which has peen pointed in post #18 by @J-M-L.

2 Likes

wow, great detailed info.
I'll try a couple of thing:
First, I'll try using a CAT6 cable that is shielded and twisted.
Second, I'll try adding resistors to the row pins like suggested above.

Unfortunately, it will have to wait for the weekend as it's the only free time I have to play with this new hobby.

I will definitely keep you updated with the results.

I'll also explore the suggested option of moving the controller closer to the keypad, this will place the MCU in a hard to reach place and make maintenance harder but if the other options will fail I'll have no other choice.

Many thanks again.

1 Like