Controling keypad without <Keypad.h> library

Hi everyone, Are there any way to programing an sketch to read the keys from a keypad and do not use the Kaypad.h library???

thanks and sorry for my english, I am new in the Arduino.

You arduino LCD Keypad sheild ; Where you can use the keypad & LCD screen together.It wont required keypad.h library.

http://www.dfrobot.com/wiki/index.php?title=Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009)
Example code is avilable here.

Let us know why you dont want use keypad.h. it standard library works fine all over. Share us code if any facing problem

A keypad is just any number of crosspoint switches arranged in a matrix. There are a number of ways to read them. The most apparent reason for not using the library would be conserving i/o pins. Some methods that i have used:

  • Using analog input pins and having the keypad configured as a voltage divider
  • Having capacitors on the rows and resistors on the columns and measuring the time constant. No need for analog pins

Using these methods you can read a 4x4 keypad with 4 pins or 3 if you use a analog multiplexer

Well obviously, whoever wrote the keypad library managed it. You could do something similar.

Set the column pins to INPUT_PULLUP.  Set the row pins to INPUT.
For each row:
    Set that row pin to OUTPUT and write LOW.
    For each column:
          If the column pin reads LOW the button that connects row and column is pressed.
    Set the row pin back to INPUT.

You could also do it with external pull-down resistors on the column pins:

Set the column pins to INPUT.  Set the row pins to OUTPUT and write LOW.
For each row:
    Write the row pin HIGH.
    For each column:
          If the column pin reads HIGH the button that connects row and column is pressed.
    Write the row pin LOW.

johnwasser thanks for your answer, you talk about this code or I think, the problem is when you push the button It does several numbers for example: you push the number one or two.......etc. and prints : 1111111222223333333355555555555......

How you can fix that???

const int fa = 2;
const int fb = 3;
const int fc = 4;
const int fd = 5;
const int c1 = 6;
const int c2 = 7;
const int c3 = 8;

void setup(){
  Serial.begin(9600);
  Serial.println("Inicio de Programa");
  pinMode(fa,OUTPUT);
  pinMode(fb,OUTPUT);
  pinMode(fc,OUTPUT);
  pinMode(fd,OUTPUT);
  pinMode(c1,INPUT_PULLUP);
  pinMode(c2,INPUT_PULLUP);
  pinMode(c3,INPUT_PULLUP);  
}

void loop(){
  leerpad();
}

void leerpad(){
  digitalWrite(fa,LOW) ;
  if (digitalRead(c1) == LOW) Serial.println("1");
  if (digitalRead(c2) == LOW) Serial.println("2");  
  if (digitalRead(c3) == LOW) Serial.println("3");
  digitalWrite(fa,HIGH);
  digitalWrite(fb,LOW);
  if (digitalRead(c1) == LOW) Serial.println("4");
  if (digitalRead(c2) == LOW) Serial.println("5");
  if (digitalRead(c3) == LOW) Serial.println("6");
  digitalWrite(fb,HIGH);
  digitalWrite(fc,LOW);
  if (digitalRead(c1) == LOW) Serial.println("7");
  if (digitalRead(c2) == LOW) Serial.println("8");
  if (digitalRead(c3) == LOW) Serial.println("9");
  digitalWrite(fc,HIGH);
  digitalWrite(fd,LOW);
  if (digitalRead(c1) == LOW) Serial.println("*");
  if (digitalRead(c2) == LOW) Serial.println("0");
  if (digitalRead(c3) == LOW) Serial.println("#");
  digitalWrite(fd,HIGH);
  delay(15);
}

The code is straight forward, here is the logic you need. It is important to see a release of the button in your loop or a change of button, before you do a serial print again.

Something along the lines
looks like you have 4 rows and 3 columns
set-up a scan loop with no print functionality, and package each of the 4 columns into a byte, this is your first array A (or think of it as the previous scan)

init your A array to [10000111, 01000111, 00100111, 0001011] all button are high; therefore, no key press

delay(15)
execute the scan loop - it will return an new array - lets call this one B (or current scan)
10000XXX - First row and its 3 column bits (0 = low, 1 =high)
01000XXX - 2nd row and its 3 columns bits
00100XXX - 3rd row and its 3 column bits
00010XXX - 4rth row and its 3 columns bits
do a compare between the elements in A and B
if A(prev)=B(cur) then
do nothing
else
something changed in the keypad data
figure out which key you need to send and send it
Set A=B (the current down key in now held in memory)

Wait for you next scan interval to expire and then repeat

I believe this will work - you will only send the data only once on a new key input.
The other benefit is that you can determine a stuck key in this case and take a different action in your code. You can add a counter in the A=B that if it is exceed you do something - the no key down state (your init A arrray) will reset this counter.

EJTR:
the problem is when you push the button It does several numbers for example: you push the number one or two.......etc. and prints : 1111111222223333333355555555555......

How you can fix that???

The problem is that you are detecting that the button is down and displaying the digit. You are not keeping track of whether the button was already down so you can display the digit once for each press. You may also want to implement debounce for each key. Those are features the Keyboard library can take care of for you.