Arduino keypad with 1 Analog pin

Here is my circuit design for Arduino keypad, using only 1 analog pin (instead of 7 serial pins), 6 resistors (can be reduced to 5) and 1 capacitor:


And now for the full story:

I decided it’s time to add a keypad to my Arduino playground. Usually, those simple keypads come with 7 pins (actually 9, but 2 are not connected to anything on 3×4 keypads) which are connected to Arduino like this:

I wanted to use less pins as possible, so I thought of getting 74hc165, but then I decided it’s time for a new challenge – resistors, and I went with something more like this:

As you can see it this diagram (and others found on the web), one can connect his keypad via 1 analog pin, using all kind of resistors schemes. I decided to build my own with the resistors I already have at home. My 1st setup worked fine, but resistors differentiation wasn’t enough and 2 keys (1 and 5) were showing same value when pressed. So I went along and fixed that, and the working result is the 1st diagram you saw in this post. Final shopping list follows:

Shopping List

Amount Part Type Properties
1 Ceramic Capacitor package 100 mil [THT, multilayer]; capacitance 0.01µF; voltage 5V
3 330 Ω Resistor package THT; tolerance ±5%; bands 4; resistance 330Ω; pin spacing 400 mil
2 2.2k Ω Resistor package THT; tolerance ±5%; bands 4; resistance 2.2kΩ; pin spacing 400 mil
1 4.7k Ω Resistor package THT; tolerance ±5%; bands 4; resistance 4.7kΩ; pin spacing 400 mil

Here is the Arduino code I’m using for my keypad. Check values to meet your own:

 * keypad example.

// analog pin connected to keypad
#define KEYPAD_PIN 0

// milliseconds to wait, to make sure key is pressed
#define TIME_TO_WAIT 50

void setup()

void loop()
	// reading once
	int r1 = analogRead(KEYPAD_PIN) / 10 * 10;
	// waiting
	// reading 2nd time - to make sure key is pressed for at least TIME_TO_WAIT milliseconds
	int r2 = analogRead(KEYPAD_PIN) / 10 * 10;
	if (r1 == r2) {
		switch (r1) {
		case 350: Serial.println("0"); break;
		case 270: Serial.println("1"); break;
		case 360: Serial.println("2"); break;
		case 120: Serial.println("3"); break;
		case 210: Serial.println("4"); break;
		case 330: Serial.println("5"); break;
		case 0  : Serial.println("6"); break;
		case 240: Serial.println("7"); break;
		case 340: Serial.println("8"); break;
		case 50 : Serial.println("9"); break;
		case 250: Serial.println("*"); break;
		case 80 : Serial.println("#"); break;


  1. Hi, i would like to know how i do to put the right values in the cases, in my project just the number 4 worked.
    Thnks already.

    1. If you understand the logic, I recommend start playing with what you already got and see if you can create your own version – all you need is to create different resistance in the wires. If nothing works, then you’ll have to get capacitors like the ones I’ve used. G’luck.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s