You are on page 1of 3

#include <Keypad.

h>
#include <LiquidCrystal_I2C.h>

const int ROW_NUM = 4; // four rows


const int COLUMN_NUM = 3; // three columns

char keys*ROW_NUM+*COLUMN_NUM+ = ,
,'1','2','3'-,
,'4','5','6'-,
,'7','8','9'-,
,'*','0','#'-
-;

byte pin_rows*ROW_NUM+ = ,9, 8, 7, 6-; //


connect to the row pinouts of the keypad
byte pin_column*COLUMN_NUM+ = ,5, 4, 3-; //
connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys),
pin_rows, pin_column, ROW_NUM,
COLUMN_NUM);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Address 0x27
for a 16x2 LCD

const int motorPin = 11;

void setup() ,
lcd.begin(16, 2);
lcd.print("Arduino Keypad");

pinMode(motorPin, OUTPUT);
-

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

if (key) ,
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Key Pressed:");
lcd.setCursor(0, 1);
lcd.print(key);

// Control the DC motor based on the key


pressed
if (key == '1') ,
digitalWrite(motorPin, HIGH);
- else ,
digitalWrite(motorPin, LOW);
-

delay(500); // Debounce delay


-
-

You might also like