DESCRIPTION
The Kimat One Wire Keypad module instantly simplifies the implementation of a 4×4 or 3×4 keypad matrix. It uses just one analog pin as opposed to 7 or 8 pins without this module. It utilizes an array or resistors carefully chosen to allow unique voltage output for each keypress. It is then read by the
microcontroller/Arduino ADC (analog) pins for decoding.

FEATURES and SPECIFICATIONS
> Simplifies Connections. One 3 lines required: an analog line, a 5V and a Ground line
> Saves 6-7 IO pins
> Plugs directly into the keypad.
> Supports the common dome matrix 4×4 and 3×4 keypads
> Arduino Compatible
> Simple analog voltage output with distinct level for each key
> Library available
| Kimat One Wire Keypad Module Pin | Module Pin Function |
| VCC | Connects to the 5V pin of the Arduino |
| AN | The analog voltage output. Connects to an analog input pin (ADC) |
| GND | Ground |
| KEYPAD 1-8 | Connects to the keypad matrix |

LIBRARY
We have adopted Andrew Mascolo Jr’s OnewireKeypad library:
https://github.com/AndrewMascolo/OnewireKeypad
We have tweaked the example to work specifically for the Kimat One Wire Keypad Module:
Example Code Using Library
#include <OnewireKeypad.h>
char KEYS[] = {
'1', '2', '3', 'A',
'4', '5', '6', 'B',
'7', '8', '9', 'C',
'*', '0', '#', 'D'
};
Kimat One Wire Keypad Module
User Guide
OnewireKeypad <Print, 16 > KP2(Serial, KEYS, 4, 4, A0, 4700, 1000, 10000, ExtremePrec );
void setup () {
Serial.begin(115200);
// This method is set in the constructor with a default value of 5.0
// You only need to include this method if your Arduino is not supplying 5v to
// the keypad. ie. ~4.7v or even with 3.3v Arduino boards too.
//KP2.SetKeypadVoltage(5.0);
KP2.SetKeypadVoltage(4.95);
}
void loop()
{
if ( char key = KP2.Getkey() ) {
switch (KP2.Key_State()) {
case PRESSED:
Serial << "Key: " << key << " State: ";
Serial.println("PRESSED");
break;
case RELEASED:
Serial << "Key: " << key << " State: ";
Serial.println("RELEASED");
break;
case HELD:
Serial << "Key: " << key << " State: ";
Serial.println("HOLDING");
break;
}
}
}
Example Code with 16×2 LCD (I2C)
EXAMPLE CODE WITH 16x2 LCD
Kimat One Wire Keypad Module
User Guide
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OnewireKeypad.h>
char KEYS[] = {
'1', '2', '3', 'A',
'4', '5', '6', 'B',
'7', '8', '9', 'C',
'*', '0', '#', 'D'
};
LiquidCrystal_I2C lcd(0x3F,16,2);
OnewireKeypad <Print, 16 > KP2(Serial, KEYS, 4, 4, A0, 4700, 1000, 10000, ExtremePrec );
void setup () {
Serial.begin(115200);
lcd.init();
lcd.backlight();
// This method is set in the constructor with a default value of 5.0
// You only need to include this method if your Arduino is not supplying 5v to
// the keypad. ie. ~4.7v or even with 3.3v Arduino boards too.
//KP2.SetKeypadVoltage(5.0);
KP2.SetKeypadVoltage(4.95);
lcd.setCursor(0,0);lcd.print(" LAYAD CIRCUITS ");
lcd.setCursor(0,1);lcd.print("LC 1-WIRE KEYPAD");
delay(2000);
lcd.clear();
}
void loop()
{
if ( char key = KP2.Getkey() ) {
switch (KP2.Key_State()) {
case PRESSED:
lcd.clear();
lcd.setCursor(0,0);lcd.print("LC 1-WIRE KEYPAD");
lcd.setCursor(2,1);lcd.print(key);
lcd.setCursor(4,1);lcd.print(": PRESSED");
Serial.print(key);
Serial.println(" PRESSED");
break;
case RELEASED:
lcd.clear();
lcd.setCursor(0,0);lcd.print("LC 1-WIRE KEYPAD");
lcd.setCursor(2,1);lcd.print(key);
lcd.setCursor(4,1);lcd.print(": RELEASED");
Serial.print(key);
Serial.println(" RELEASED");
break;
case HELD:
lcd.clear();
lcd.setCursor(0,0);lcd.print("LC 1-WIRE KEYPAD");
lcd.setCursor(2,1);lcd.print(key);
lcd.setCursor(4,1);lcd.print(": HOLDING");
Serial.print(key);
Serial.println(" HOLDING");
break;
}
}
}
Example Using Raw ADC values
Note: ADC values should be tuned on every individual circuit
const bool LC_KIMAT1WIRE_4x4 = 0;
const bool LC_KIMAT1WIRE_3x4 = 1;
const bool kpsize = LC_KIMAT1WIRE_3x4; // LC_KIMAT1WIRE_4x4 for 4x4 or LC_KIMAT1WIRE_3x4 for 3x4
const unsigned int KIMAT1WIRE_PIN = A1; // define the Arduino pin connected to AO
unsigned int rawadc;// ADC value
char key; // last key pressed
char lastkey; // previous key
void setup() {
Serial.begin(9600);
Serial.println(F("Press a Key to Print raw ADC value and decoded key"));
}
void loop() {
rawadc = 0;
for(byte i=0;i<10;i++)
{
rawadc += analogRead(KIMAT1WIRE_PIN);
}
rawadc /= 10;
if(kpsize == LC_KIMAT1WIRE_4x4) // 4x4 keypad
{
// adjust the ADC raw values below according to your reading
if(rawadc >= 1008) { key = '1'; }
else if(rawadc >= 875) { key = '2'; }
else if(rawadc >= 820) { key = '3'; }
else if(rawadc >= 760) { key = 'A'; }
else if(rawadc >= 683) { key = '4'; }
else if(rawadc >= 620) { key = '5'; }
else if(rawadc >= 590) { key = '6'; }
else if(rawadc >= 560) { key = 'B'; }
else if(rawadc >= 510) { key = '7'; }
else if(rawadc >= 490) { key = '8'; }
else if(rawadc >= 465) { key = '9'; }
else if(rawadc >= 442) { key = 'C'; }
else if(rawadc >= 425) { key = '*'; }
else if(rawadc >= 400) { key = '0'; }
else if(rawadc >= 380) { key = '#'; }
else if(rawadc >= 375) { key = 'D'; }
else
{
key = NULL;
}
}
else // 3x4 keypad
{
if(rawadc >= 1009) { key = '1'; }
else if(rawadc >= 865) { key = '2'; }
else if(rawadc >= 820) { key = '3'; }
else if(rawadc >= 680) { key = '4'; }
else if(rawadc >= 620) { key = '5'; }
else if(rawadc >= 590) { key = '6'; }
else if(rawadc >= 510) { key = '7'; }
else if(rawadc >= 485) { key = '8'; }
else if(rawadc >= 470) { key = '9'; }
else if(rawadc >= 420) { key = '*'; }
else if(rawadc >= 395) { key = '0'; }
else if(rawadc >= 380) { key = '#'; }
else
{
key = NULL;
}
}
if(key && (key != lastkey))
{
Serial.print(F("Raw Value="));
Serial.print(rawadc);
Serial.print(F("\tDecoded Key="));
Serial.println(key);
}
lastkey = key;
}
