0% found this document useful (0 votes)
36 views

ELB Code

This document contains code to interface a 4x3 keypad and control a DC motor with an Arduino. It initializes the keypad and LCD screen, then reads key presses on the keypad and displays them. If the '1' key is pressed, it will turn on the motor, otherwise it will turn off the motor.

Uploaded by

abdolbaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

ELB Code

This document contains code to interface a 4x3 keypad and control a DC motor with an Arduino. It initializes the keypad and LCD screen, then reads key presses on the keypad and displays them. If the '1' key is pressed, it will turn on the motor, otherwise it will turn off the motor.

Uploaded by

abdolbaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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