Numeric keypad voltage programming

Hi all ,

I have a 12 button numeric keypad that i am wanting to interface with arduino (7 pin type (4 x 3 rows)).
I h ave read some instructions on how to use these with arduino by the use of 7 pin inputs to the chip, however i want reduce the amount of required pins to one, by using a series of resistors that give a different voltage, between 0 - 4.9v and set up the code so that arduino sees each voltage as a different number.

Can this be done, or do i need to use a shift register? i'm trying o keep the number of components to a minimum, and i learned this idea from installing an aftermarket radio to my car's steering wheel controls...

Thanks in advance for your help!

Mike

Hello,

See this and especially that :wink:

And even this.

Thank you! ;D

Hi everyone,

I have built all of the hardware, very few components indeed, consisting of the keypad itself, a bit of proto board, a few resistors,LED's and ATTINY85 and a 2n2222a transistor to drive a relay.
These keypads are all different in terms of pinout as it happens, so i had to spend considerable time working out how to wire up the resistor ladder!

My ultimate plan is to design a combination lock that takes in a number of pins "say four" and checks if they were entered correctly, if so, then turn on a green LED and drive a NC relay, if not, then continue displaying a red LED.
Also, I'd like to set up a password learning system, so that if I hold down a key for 10 seconds for example, both LED's will flash once per second, for it to prompt me to enter a new password, then start flashing once every 200mS for me to confirm the password before setting it.

Would anyone be kind enough to give me a few pointers here?
I have added two libraries to my IDE, #include <OnewireKeypad.h> and #include <Password.h>.

Borrowed from:
http://playground.arduino.cc/Code/OneWireKeyPad
http://playground.arduino.cc/Code/Password

Here is my code so far...

#include <Password.h>
Password password = Password( "1234" );

#include <OnewireKeypad.h>
#define Rows 4
#define Cols 3
#define Pin 2//ANALOG Input 1 (pin 7)on ATTINTY85
#define Col_Res 4700
#define Row_Res 1000

char KEYS[]= {
  '1','2','3',
  '4','5','6',
  '7','8','9',
  '*','0','#'
};
OnewireKeypad <Print, 12> KeyPad(Serial, KEYS, Rows, Cols, Pin, Col_Res, Row_Res );

int GreenLed = 0;//Unlocked Status LED
int RedLed = 1;//Locked Status LED
int Relay = 3;//Electrical System Disable Relay

void setup(){
pinMode (GreenLed,OUTPUT);//Set all as outputs
pinMode (RedLed,OUTPUT);
pinMode (Relay,OUTPUT);

password.append('1');//add 1 to the guessed password
password.append('2');//add 2 to the guessed password
password.append('3');//add 3 to the guessed password
password.append('4');//add 4 to the guessed password

password.reset(); //reset the guessed password to NULL
password.set("qwerty"); //set target password to qwerty

}
void loop(){

Any help would be greatly appreciated, I'm sure this has been done before, id like to also learn how to program in extra functions once i get this part up and running, including an LCD, however this one with the LED's is cheap to build and is effective, I want to put one in my car to disable the ignition when parked and also one for the door to my house!

Mike

You want something like this.

#include <OnewireKeypad.h>
#include <Password.h>

char KEYS[] = {
  '1', '2', '3', //'A',
  '4', '5', '6', //'B',
  '7', '8', '9', //'C',
  '*', '0', '#', //'D'
};

OnewireKeypad <Print, 12 > KP(Serial, KEYS, 4, 3, A0, 4700, 1000 );
Password password = Password( "1234" );

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

void loop()
{
  char Key;
  if (KP.Key_State() == PRESSED)
  {
    if ( Key = KP.Getkey() )
    {
      Serial.print("Pressed: ");
      Serial.println(Key);
      switch (Key) 
      {
        case '*': checkPassword(); break;
        case '#': password.reset(); break;
        default: password.append(Key);
      }
    }
  }
}

void checkPassword()
{
  if (password.evaluate())
  {
    Serial.println("Success");
    //Add code to run if it works
  }
  else
  {
    Serial.println("Wrong");
    //add code to run if it did not work
  }
}

Thank You Hazards! will give it a go in the weekend and report back!

Hi HazardsMind,

I needed a keyboard with an analog output to interface to my Arduino and found your OneKeyPad library.

However, when I built the circuit you propose I found out that the voltage dividers are not dimensioned correctly and the separation between the output volatges becomes smaller and smaller until for the last keys there is almost no separation between output voltages.
At first I thought I had done something wrong. So I did my math and indeed the voltage dividers proposed will not provide good separation between keys.

How did you get it to work for all the keys? Did I miss something?

Screenshot Analog Keyboard.png

I haven't used my OWKP in a while but I think I had planned to add precision to where it averages the values.

I dont have my hardware with me and I wont have it for a good while, but I may add it in some time soon.

Hi HM,

With due respect, I would like to check your circuit values again.

I built the proposed circuit and it didn't work. I did my math again and even theoretically - not accounting for resistor tolerances - the output voltage steps of the keypad get so close to each other for the upper keys that you can't differentiate them.

It could very well be that I'm missing something, but what? The readings of my digital multimeter confirm the math.

Rgds,

P