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:
- 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:
- 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.
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:
- 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.
- If you don't know How to use Arduino in Proteus then read Arduino Library for Proteus.
- I have also posted a detailed tutorial on How to Interface LCD with Arduino.
- Another tutorial you must read is How to get the Hex file from Arduino.
- 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:
- Now, when you press any button on the keypad it will also appear on the LCD as shown in below figure:
- In the above figure, I have pressed all the buttons on keypad in a row and you can see they are all appeared on the LCD.
- So, that's how we can design an Arduino keypad Interfacing.
- If you are working on PIC Microcontrolelr, then you should read Interfacing of keypad with PIC Microcontroller.
- I have also posted a tutorial on Interfacing of Keypad with 8051 Microcontroller in Proteus ISIS.