You are on page 1of 14

4x3 Keypad and ARDUINO

Keypad
• Keypad is a library for using matrix style
keypads with the Arduino.
• As of version 3.0 it now supports multiple
keypresses.
Char Array
1 = pins 5,8 [0,0]
2 = pins 5,7 [0,1]
3 = pins 5,6 [0,2]
4 = pins 4,8 [1,0]
5 = pins 4,7 [1,1]
6 = pins 4,6 [1,2]
5 7 = pins 3,8 [2,0]
8 = pins 3,7 [2,1]
4
9 = pins 3,6 [2,2]
3 * = pins 2,8 [3,0]
0 = pins 2,7 [3,1]
2 # = pins 2,6 [3,2]
7582634
8 7 6
Arduino Pins
Constructors:
Keypad(makeKeymap(userKeymap), row[], col[], rows, cols)
const byte rows = 4; //four rows
const byte cols = 3; //three columns
char keys[rows][cols] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{‘*','0',‘#'}
};
byte rowPins[rows] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[cols] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

Instantiates a Keypad object that uses pins 5, 4, 3, 2 as row pins, and 8, 7, 6 as


column pins.
This keypad has 4 rows and 3 columns, resulting in 12 keys.
This program scans the input from the keypad and displays it in the serial
monitor.
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
SAMPLE PROGRAM

{'4','5','6'},
{'7','8','9'},
{‘*','0',‘#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}

void loop(){
char key = keypad.getKey();

if (key != NO_KEY){
Serial.println(key);
}
}
This program scans the input from the keypad. If the keypad input is 1, it
performs the blink() function and the input is 2, it executes the fade() function.
#include <Keypad.h>

int ledPin=9;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
//define the cymbols on the buttons of the keypads
char Keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
int keyDec;
//initialize an instance of class NewKeypad
Keypad Kpad = Keypad( makeKeymap(Keys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
}

void loop(){
char Key = Kpad.getKey();

if (Key !=NO_KEY){
Serial.println(Key);
keyDec= Key - '0';
switch(keyDec){
case 1: for(int x=1;x<=5;x++){
blink();
}
break;
case 2: fade();
break;
}
}
}
void blink(){
digitalWrite(ledPin,HIGH);
delay(500);
digitalWrite(ledPin,LOW);
delay(500);
}

void fade(){
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
analogWrite(ledPin, fadeValue);
delay(30);
}

for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {


analogWrite(ledPin, fadeValue);
delay(30);
}
}
Supplementary Problems(Mon)
1. Make a program and hardware that when you press the numeric
character in the keypad it serves as the number of times an LED
fades. When * is pressed, it displays “Welcome to Embedded!” in
the Serial Monitor but when # is pressed, it shows “Keypad is love.”
in the serial monitor. Delay between blink is 500ms.

Materials Needed: 1 pc. LED


Gizduino X

2. Make a program and hardware that when you press two numeric
character in the keypad a corresponding LED lights and take the
sum. The sum will serve as the number of blinks of an LED.
Materials Needed: 1 pc. LED
Gizduino X
Supplementary Problems(Wed)
1. Make a program and hardware that when you press the numeric character
in the keypad it serves as the number of times an LED blinks. Delay
between blink is 500ms.

Materials Needed: 1 pc. LED


Gizduino X

2. Make a program and hardware that when you press the numeric character
in the keypad a corresponding LED lights. All odd numeric keys should
perform the alternate() effect while even keys should perform the
blinkAll() effect. Note: You are going to use other I/O pins other than the
assigned pins for the keypad

Materials Needed: 9 pcs. LED


Gizduino X
Make a program and hardware that when you press
the numeric character in the keypad a
corresponding LED lights. All odd numeric keys
should perform the alternate() effect while even
keys should perform the blinkAll() effect. Note:
You are going to use other I/O pins other than the
assigned pins for the keypad

Materials Needed: 9 pcs. LED


Gizduino X
1. Make a program and hardware that when you
press the numeric character in the keypad it
serves as the number of times an LED fades.
When * is pressed, it displays “Welcome to
Embedded!” in the Serial Monitor but when # is
pressed, it shows “Keypad is love.” in the serial
monitor. Delay between blink is 500ms.

Materials Needed: 1 pc. LED


Gizduino X
Supplementary Problem
• Make a program and hardware that it counts
the number of presses you’ve done to a
particular key then after a delay it displays the
equivalent WORD of the number of presses.
When * is pressed, it displays “Welcome to
Embedded!” in the Serial Monitor but when #
is pressed, it shows “Keypad is love.” in the
serial monitor.