how do I interface with a 4x4 keypad/

Can I check with you on how do I determine what are columns and what are rows of my keypad?

The best way is to look up the data sheet.
Or you can look at how the PCB is wired up.

As Mike says...there is really no way to tell as you havent even told us what keypad you are using.. pictures...nothing. :fearful:

but using THIS code: (slightly different than Mikes edit..but more or less the same)

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 2, 3, 4, 5, };

// Connect keypad COL0, COL1, COL2 and COL3 to these Arduino pins.
byte colPins[COLS] = { 6, 7, 8,9 };

it would be wired as such:

Hi,

Thanks alot for your help. I am able to use the Keypad.
By the way if i want to use Arduino Uno R3 with the keypad and program as a calculator with simple calculations like addidtion only
is it possible? Where can I find the library or function for it?What do you advise?

if you already can communicate with the kaypad..

I would think any handling of your 'data' would/could be done internally..

grab the key1 data.. and add it to the key2 data..etc..

maybe set up some keys to set the operator..etc.. just some simple logic..

Yes but you need the suspended stored operation.
Get in one number.
Read the operation you want to perform, store it because you can't do that until you ..
Get the second number.

In that respect reverse polish calculators were great.

Sorry in this case, I just need to modify the source code from under the void loop function?
Is there any more advise on how to edit the program? Like some link or something?
As I am not too sure on how to start.

I just need to modify the source code

What source code?

Has anyone used a resistor network as a voltage divider and then read the key value off one of the analog input pins?

I read a write up on something like this but it used resistors of odd values. ( Odd means I didn't have any )

The one I say was set up like a straight ladder and the input came off the mid-point. I thought that there might be a way to use 8-10 1K resistors in a network to accomplish the same thing.

Here is what you might have been thinking of.
http://tronixstuff.wordpress.com/2012/02/29/tutorial-analog-input-for-multiple-buttons-part-two/
Expand the network for the number of buttons you want to use.

CrossRoads:
Here is what you might have been thinking of.
http://tronixstuff.wordpress.com/2012/02/29/tutorial-analog-input-for-multiple-buttons-part-two/
Expand the network for the number of buttons you want to use.

I was actually looking at something like:
http://www.avr-asm-tutorial.net/avr_en/keypad/keyboard.html#adc

This one is for a 3X4 matrix and the math is a pain for selecting the resistor values. I was hoping some smarter folks than me figured out a way to use only 1 or 2 different values.

Hi,
I had already tried to interface with 4x4 keypad with arduino and it works... Currently I am thinking of modifying the source code so that
it can function as a calculator(Simple Calculator with just addition function). But I am not sure how to start with the advises given earlier.
Is it modifying in the void loop function?
Please Advise.

CustomKeypad1.ino (905 Bytes)

The whole thing is none trivial.

Start off by putting your key reading code into a function that returns a number.

This is a bit more difficult than you might think. It has to look at keys pressed and accumulate a number building it up from each key press. So the first number is the key, the second press you take the previous number, multiply it by 10 and add the next key pres to it. You continue to do this until you detect a none number key. You then return from the function with the number.

Then your top level loop consists of calling this function twice, and storing the number in a different variable each time. Finally add the numbers up and print out the result.

hi I am new in arduino too, and i want to display numbers 0 to 9, in a 7-segment display using keypads (4x4) and arduino, please let me know if somebody can help me thank you.

Sure, start here:
http://playground.arduino.cc/Code/Keypad
Once you can read the keys and display them correctly via the serial monitor, come back with more details of how you wish to connect to the 7-segment display, how many digits, etc.

One Analog Input to Arduino from a keypad.
I use it, and it works fine (but it's only 3x4 matrix keypad).

BR
GoranR

The link:

Goranr:
http://www.instructables.com/id/Arduino-3-wire-Matrix-Keypad/

is very similar to:

http://www.avr-asm-tutorial.net/avr_en/keypad/keyboard.html#adc

The second link also contains a spreadsheet for calculating resistor values. I modified the spreadsheet to calculate values for a 4x4 matrix.

The problem I have with this solution is that for the 3x4 matrix it uses 7 resistors of 6 different values. I would like to find a solution that uses 10 or 12 resistor of all the same value. Or maybe 5 or 6 resistors of one value and 5 or 6 of another value.

The reason I am thinking this might be a better solution is that while the component count is higher, the cost of resistors goes down with volume. Rather than buy 6 packages of 5 to 10 resistors each, it would be cheaper to by 1 package of 100 resistors.
Also, the tolerances are important. If I buy a 100 resistors they they were probably made at around the same time with the same material and if there is an error they are probably all off by about the same amount in the same direction. So if they are all low by 5% then the errors will probably cancel in a design that uses all the same value. Rather than 6-8 different values with some high and some low. Since I don't have a design, this is all assumption.

There may also be an inexpensive SIP or DIP package out there that contains the appropriate resistor network. I just haven't come across it.

hello im newbie but i can use thats code good, i test and working ok.

/*Program demonstrating 4x4 Numeric Keypad interfacing with Arduino UNO
Program Written by: Amit Biswal (Speaking Technology)
URL : http://amitbiswal.blogspot.com
*/
int r1=A5;
int r2=A4;
int r3=A3;
int r4=A2;

int c1=A1;
int c2=A0;
int c3=10;
int c4=11;

void setup()
{
Serial.begin(9600);

pinMode(r1,OUTPUT);
pinMode(r2,OUTPUT);
pinMode(r3,OUTPUT);
pinMode(r4,OUTPUT);

pinMode(c1,INPUT);
pinMode(c2,INPUT);
pinMode(c3,INPUT);
pinMode(c4,INPUT);

}
void loop()
{
int val;
//setting the columns as high initially
digitalWrite(c1,HIGH);
digitalWrite(c2,HIGH);
digitalWrite(c3,HIGH);
digitalWrite(c4,HIGH);

//checking everything one by one
//case 1: col1 =0 while other col as 1
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
digitalWrite(r4,HIGH);
//checking each column for row1 one by one
if(digitalRead(c1)==0)
{
Serial.println("key 1 pressed");
}
else if(digitalRead(c2)==0)
{
Serial.println("Key 2 pressed");
}
else if(digitalRead(c3)==0)
{
Serial.println("Key 3 pressed");
}
else if(digitalRead(c4)==0)
{
Serial.println("Key A pressed");
}

//case 2: col2 =0 while other col as 1
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(r3,HIGH);
digitalWrite(r4,HIGH);
//checking each column for row1 one by one
if(digitalRead(c1)==0)
{
Serial.println("key 4 pressed");
}
else if(digitalRead(c2)==0)
{
Serial.println("Key 5 pressed");
}
else if(digitalRead(c3)==0)
{
Serial.println("Key 6 pressed");
}
else if(digitalRead(c4)==0)
{
Serial.println("Key B pressed");
}

//case 3: col3 =0 while other col as 1
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,LOW);
digitalWrite(r4,HIGH);
//checking each column for row1 one by one
if(digitalRead(c1)==0)
{
Serial.println("key 7 pressed");
}
else if(digitalRead(c2)==0)
{
Serial.println("Key 8 pressed");
}
else if(digitalRead(c3)==0)
{
Serial.println("Key 9 pressed");
}
else if(digitalRead(c4)==0)
{
Serial.println("Key C pressed");
}

//case 1: col1 =0 while other col as 1
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
digitalWrite(r4,LOW);
//checking each column for row1 one by one
if(digitalRead(c1)==0)
{
Serial.println("key F pressed");
}
else if(digitalRead(c2)==0)
{
Serial.println("Key 0 pressed");
}
else if(digitalRead(c3)==0)
{
Serial.println("Key E pressed");
}
else if(digitalRead(c4)==0)
{
Serial.println("Key D pressed");
}
//giving delay between keypress
delay(200);

}

but i have proplem, why next code no working,i load arduino examples at net and test better code but compiler stop alltime const byte row (and many many other error have too.why no working because must be have arduino examples code :open_mouth: ????

this is examples code-->

/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
Serial.begin(9600);
}

void loop(){
char key = keypad.getKey();

if (key){
Serial.println(key);
}
}

i has change IDE version 1.01 to 1.03 before thats.

Rather than make a new thread, I decided to reuse this one since my question falls along these lines. I am am going to run a RGB LCD (16x2) at the same time as the keypad. I have an understanding of PWM (Arduino Forum), and am always triple checking here or google to ensure no complications come up. I have an ATMEGA 1280 with 54 digital pins (and the lower numbers have PWM). Will any pins in the digital range (PWM or not) be able to control the LCD or keypad (standard 4x4 from amazon that is compatible)?