HUM: MEMBRANE KEYBOARD 4 X 1
You are a beginner with Dasduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by soldered where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect the module with Dasduino and the basic code. Everything else is left to your imagination.
INTRODUCTION
You have a project in which you need to enter certain values into your program, but you do not know how to do it? Continue reading and you will learn everything about a simple input module.
It is about a membrane keypad that consists of 4 keypads and it is very easy-to-use, and in smaller projects, it is quite sufficient. The keyboard has 4 keypads in one row and works on the same principle as the 4×4 membrane keyboard, but it is smaller and more convenient to use where it is not necessary to have 16 keypads.
Sensor characteristics:
- Upper part size: 7 x 2cm
- Cable length: 9cm, flexible
- Connector: 5-pin
HOW DOES IT WORK?
This keyboard uses 4 keypads with one end connected to the row and the other end to the column. Since we have one keypad in each column, we simply have each keypad connected to one output pin. Keypads simply connect one pin to another, i.e. in our case, they connect the row and column in which they are located, as you can see in the image below.
HOW TO CONNECT IT?
The keyboard can be easily connected to Dasduino because on the keyboard, we have female headers, just like on Dasduino, so we can use male to male cables. The keyboard is connected serially to Dasduino’s digital pins, and the image above shows which pin is which on the keyboard so that we could adjust the given connection scheme to our own projects.
ARDUINO CODE
In order to be able to use the keyboard with our Dasduino, we need to download the Keypad library, and if you do not know how to install a library, read our tutorial.
The library contains examples of how to use the keyboard, so we can also use them to get acquainted with the keyboard’s work principle and the library’s functions which can help us. For starters, we will only print the pressed keypad on the Serial monitor.
#include "Keypad.h" //including the Keypad library
const
byte RED = 1;
//defining the number of rows
const
byte STUPAC = 4;
//defining the number of columns
//defining the symbols that are to be displayed when we press the key
char
NasiZnakovi[RED][STUPAC] = {
{
'1'
,
'2'
,
'3'
,
'4'
}
};
byte redPin[RED] = {6};
//defining to which Croduino pins we have connected the rows
byte stupacPin[STUPAC] = {4,5,2,3};
//defining to which Croduino pins we have connected the columns (1 > pin4, 2 > pin5, 3 > pin2, 4 > pin3)
//initialization of the NewKeypad class to which we submit NasiZnakovi, pins to which the rows and columns are connected and the number of rows and columns
Keypad Tipkovnica1 = Keypad( makeKeymap(NasiZnakovi), redPin, stupacPin, RED, STUPAC);
void
setup
(){
Serial.begin(9600);
//starting serial communication
}
void
loop
(){
char
pritisnutiZnak = Tipkovnica1.getKey();
//to the pritisnutiZnak variable, we save the key which is pressed
// we get the key we have pressed using the getKey() function
if
(pritisnutiZnak){
Serial.println(pritisnutiZnak);
//checking whether the keypad is pressed, and if it is, we display it on the Serial monitor
}
}
The second example shows us how to use the keyboard to unlock the door. Connect the green LED to pin 12 and connect the red LED to pin 13, both through the resistor of the appropriate value. Connect the keyboard as in the previous example, enter the desired password and length of the password in the program, and we can use the program. When we enter the incorrect password the red diode flashes, and when the password is correct, the green diode turns on for two seconds. In the part of the code where the green diode turns on, we can add the relay or transistor that is connected to the door and can unlock them to also turn on. If necessary we can also increase the time for how long the door is unlocked if we change the value in the delay function that is now set to 2 seconds.