Analog pins for keypad input?

I am running out of digital pins on my Pro Mini. However, I am not using any of the analog pins. Can anyone think of a reason why I could not use the analog pins for a keypad?

I can't think of any way to use them with a matrix keypad, but I should be able to connect up to 8 discrete buttons, no? Supply Vcc to one side of the button, and then read the analog input for voltage with a pulldown to pull the input low when the switch is open?

Or would it work better with pullups so the input is always in a known state (high when switch is open, low when it's closed)?

Why not use the analogue pins as digital pins?

I'm new to arduinos... How do I do that? Can you use them for output? That would solve a lot of issues.

You set the pinMode, just as you would for any other pin, and use the aliases "A0", "A1" etc for the pin numbers.

Or, A0 to A5 = D14 to D19
Enough pins for a 3x3 keypad.

If you have A6, A7, those are analog input only.

1 Like

Yes, sorry, I forgot that some boards (Nano and Micro?) have eight analogue inputs A0 to A7, but the last two A6 and A7 can only be used as analogue inputs, whereas all the others can be used as analogue inputs or digital inputs or outputs.

Or, use a Resistor chain and measure the voltage along the chain using analogRead:

Here my configuration for a 4x3 matrix keypad, i tryed to use only wide used resistences so it's quite easy to build this sistem.

ROW4 COL3

Ground----1k?-------ROW1 --- 300? --- ROW2 --- 470? --- ROW3 ROW4
| | |
Analog ----------------1k?------------------

COLON1 --- 220? --- COLON2 --- 100? --- COLON3 ---- 5V

Those are the output of the analog reading.

Button N°:1
822
Button N°:2
915
Button N°:3
1003
Button N°:4
651
Button N°:5
708
Button N°:6
760
Button N°:7
502
Button N°:8
534
Button N°:9
563
Button N°:*
398
Button N°:0
418
Button N°:#
436

breadboard

Reading analog inputs:

5v------10k---------Resistor------GND
|
Analog