keypad arduino code, keypad working with arduino, how keypad works,interface keypad with arduino, display keypad on LCD
Hello friends, hope you all are fine and having fun with your lives. In today's post we will have a look at How to interface keypad with Arduino in Proteus ISIS. Keypad is used almost in every engineering project. If you even look around you will find keypad in many electronic appliances. For example, a simple ATM machine has a keypad on it using which enter our pin code and give commands to the ATM machine. Similarly, calculator also has keypad on it. So, in short there are numerous applications of keypad. You should also read the Real Life examples of Embedded Systems and you will find Keypad in them as well.

Keypad is used where you need to used numerical buttons or you need to use lots of buttons for sending commands so like in some application I need to use 10 buttons so instead of using separate 10 buttons I would prefer to use keypad instead as it will save a lot of time both in hardware as well as programming. So today we will have a detailed look on How keypad works and How we can Interface keypad with Arduino in Proteus ISIS. Proteus also gives keypad component in its database using which we can easily simulate it in Proteus and can save our time. So first simulate it and then design the hardware. After today's post I will also share an Automatic Lock system project using keypad. Anyways let's get started with Interfacing of Arduino with keypad:

How keypad works ??

  • Keypad uses matrix system in order to work.
  • For example, I am using a keypad which has 12 buttons on it as shown in below figure:
keypad arduino code, keypad working with arduino, how keypad works,interface keypad with arduino, display keypad on LCD
  • Now you can see its a 12 button keypad so it has total 3 columns and 4 rows and similarly there are 7 pins to control these 12 buttons.
  • So, the simple formula is total number of pins = Number of Rows + Number of Columns.
  • Now if we look at the internal circuitry of this 12 button keypad then it will look something as shown in below figure:
keypad arduino code, keypad working with arduino, how keypad works,interface keypad with arduino, display keypad on LCD
  • Columns and rows are connected with each other now suppose I press button "1" on the keypad then first row and the first column will get short and I will get to know that button "1" is pressed.
  • Same is the case with other buttons, for example I press button "8" then second column and the third row will get short so this code will remain unique for each button.
  • In simple words, on each button press different column and row will get short we need to detect which one gets short in order to get the pressed button.
Quite simple, isn't it ?? You should also have a look at these Arduino Projects for Beginners. So that's how a keypad works, now let's have a look at How to Interface this keypad with Arduino in Proteus ISIS.

Interfacing of Keypad with Arduino in Proteus ISIS

  • So, now we are gonna interface this keypad with Arduino in Proteus ISIS which is as always my favorite simulator.
  • In Proteus design a circuit as shown in below figure:
keypad arduino code, keypad working with arduino, how keypad works,interface keypad with arduino, display keypad on LCD
  • So, we have an Arduino UNO board along with keypad and LCD.
  • So I have done the programming in such way that whenever you press any button on the keypad, it will get displayed on the LCD.
Note:
  • Now, copy the below code and paste it in your Arduino software and get the hex file from it.
#include <LiquidCrystal.h>
#include <Keypad.h>

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] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 12, 11}; //connect to the column pinouts of the keypad

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);
  lcd.setCursor(1,2);
  lcd.print("www.TheEngineering");
  lcd.setCursor(4,3);
  lcd.print("Projects.com");
  lcd.setCursor(0,0);
}

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

    if (key) {
        lcd.print(key);
    }
}
  • Now upload the hex file in your Arduino UNO in Proteus ISIS and hit the RUN button.
  • If everything goes fine then you will get something as shown in below figure:
keypad arduino code, keypad working with arduino, how keypad works,interface keypad with arduino, display keypad on LCD
  • Now, when you press any button on the keypad it will also appear on the LCD as shown in below figure:
keypad arduino code, keypad working with arduino, how keypad works,interface keypad with arduino, display keypad on LCD
That's all for today. In the coming post I am gonna share a small project in which we will design a automatic locking system using this keypad. So stay tuned and have fun. :)