In this tutorial I will be sharing how you can use 4x4 matrix keypad and 16x2 LCD with Arduino and use it to make a simple Arduino Calculator.
So lets get started...
Hardware Requirements :-
Software Requirements :-
That's all you gonna need for this project.
So to use keypads first you have to understand how the keypad works.
Keypad is nothing but a buttoned matrix with nxn number of rows and columns. The Rows are horizontal and Columns are vertical.
In 4x4 matrix there are 4 Rows and 4 columns and in 4x3 there are 4 Rows and 3 Columns.
Each button in a row is connected to all the other buttons in the same row. Same with columns.
Pressing a button closes the switch between a column and a row trace, allowing current to flow between a Column pin and a Row pin. This is how arduino finds which button is pressed.
I don't want to dive deep into it and make the tutorial boring so if you wish to learn the working of keypad in depth you can check out this post.
Let's move on to the next step...
1. Solder wires to the keypad. Solder header pins to another end.
2. Refer to the diagram to and make connections as follows :-
3. LCD connections are fairly simple too.
where, D2, D3,.....,D13 are Digital i/o pins of arduino.
Once the connections are made. We can move on to the coding step...
Before you can start coding you have to install a library to us the keypad and LCD.
To download the library, open IDE and goto :-
Now copy the code below and paste it in the IDE. Upload it to arduino. (Code for 4x3 can be downloaded from below) :-
This code will help you check the working of Keypad, It shows the button pressed on Serial monitor.
/*Code for 4x4 keypad*/ #include<keypad.h> const byte ROWS = 4; const byte COLS = 4; char keys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; byte rowPins[ROWS] = {5, 4, 3, 2}; byte colPins[COLS] = {9, 8, 7, 6}; Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); void setup() { Serial.begin(9600); } void loop() { char key = keypad.getKey(); if (key) { Serial.println(key); } }
With this you can get started with keypad with arduino, The code for calculator is in next step..
Once you have tested the keypad, and it works fine. you can move on to making a simple calculator.
You can download the code from the file given below.
To use the calculator simply upload the code, The Alphabets are used as follows :-
A = + (Addition)
B = - (Subtraction)
C = * (Multiplication)
D = / (Division)
Symbol * and # are used as 'Cancel' and 'Equals to' Respectively.
That's all for this tutorial. Hope you like it.
Thank you.