Arduino UNO in use
Connecting a single wire to A0 input to make working of keypad as a single IN
Here is the diagram
&
With this code below :
// Armuino --- Reading Membrane Keypad to Arduino with a Single Analog Wire ---
// Video - https://www.youtube.com/watch?v=N39EXI_F8uA
#include "OnewireKeypad.h" // OneWireKeypad Library
char KEYS[] = // Define keys' values of Keypad
{
'1', '2', '3', 'A',
'4', '5', '6', 'B',
'7', '8', '9', 'C',
'*', '0', '#', 'D'
};
/* Define Library :
OnewireKeypad <Print, #of buttons>
Keypad(Serial, Char values, #Rows, #Cols, Arduino Pin, Row_resistor, Columns_resistor) */
OnewireKeypad <Print, 16 > Keypad(Serial, KEYS, 4, 4, A0, 4700, 1000);
void setup ()
{
Serial.begin(9600);
}
void loop()
{
Keypad.SetHoldTime(100); // Key held time in ms
Keypad.SetDebounceTime(50); // Key Debounce time in ms
if ((Keypad.Key_State() == 3)) // not pressed = 0, pressed = 1, released = 2, held = 3
{
char keypress = Keypad.Getkey(); // put value of key pressed in variable 'keypress'
Serial.print("Keypad Key: ");
Serial.println(keypress); // Display value on Serial Monitor
while ((Keypad.Key_State())) {} // Stay here while Key is held down
}
}
I am getting output like :
On serial monitor
Pressing Key 1 shows A
Pressing Key 2 shows 3
Pressing Key 3 shows 2
Pressing Key A shows
