# Problem in using matrix keypad with one pin

I found a code for using matrix keypad with a single analog pin.

int thresholds[16] =  {930, 912, 894, 877, 852, 837, 822, 808, 787, 774, 761, 749, 731, 719, 708, 698};
char keypad[16] =  {'1', '2', '3', 'A', '4', '5', '6', 'B', '7', '8', '9', 'C', '*', '0', '#', 'D'};
void setup() {
Serial.begin(9600);
}
void loop() {
for (int i = 0; i < 16; i++)
{
if ( abs(value - thresholds[i]) < 5 )
}
}
}

Currently I am trying it on Tinkercad.
Problem is, after running it, it only detects the first press of any key, then it stops working or doesn’t show any further press. I couldn’t detect what is the problem going on.

My guess would be that the program is stuck in this while loop

{
delay(100);
}

Print the value of analogRead(A0) within the loop to prove it. Does the value ever go above 1000 ?

The value doesn’t go more than 930, so it always remains below 1000.
But if I change the code to this:

which means if I lower the value from 1000 to 100, it detects more button press, but if I press a button for single time, it detects that: ‘several time the button has been pressed’, so result looks like this:

I couldn’t figure out how precisely it could be done

You need to arrange that the input pin is pulled HIGH when no button is pressed so that the value returned by analogRead() is above 1000

Can you please provide a link to where you got the code and circuit diagram ?

Can you please provide a circuit diagram of your setup. A photo of a hand drawn circuit is all that is required. Make sure that it shows your actual circuit rather than what you meant to build

I solved my problem, and the code is working fine.

int thresholds[16] =  {930, 912, 894, 877, 852, 837, 822, 808, 787, 774, 761, 749, 731, 719, 708, 698};
char keypad[16] =  {'1', '2', '3', 'A', '4', '5', '6', 'B', '7', '8', '9', 'C', '*', '0', '#', 'D'};
void setup() {
Serial.begin(9600);
}
void loop() {
for (int i = 0; i < 16; i++)
{
if ( abs(value - thresholds[i]) < 5 )