# Arduino Calculator Using 4×4 Keypad

Programming is amazing to work and Arduino is an amazing platform if you are a beginner at embedded programming. We have previously built a Boolean Algebraic Calculator using Arduino. In this article, we will learn to make our own mathematical calculator using Arduino. The values can be put in using a keypad (4×4 keypad) and the result will be shown on an LCD screen (16×2 dot-matrix display). This calculator could be used to do simple operations like addition, subtraction, multiplication and division with whole numbers. But once you have understood the concept, you can implement scientific functions parallelly with Arduino’s built-in functions.

When this project ends, you will learn to use a 16×2 LCD and keypad with Arduino and also know how easy it is to program using the already available Arduino IDE libraries. You will also get to know, how to program your Arduino to accomplish a specific task.

## Components Required

• Arduino Nano
• 16×2 LCD Display
• I2C LCD Module
• Connection Wires
• 5 Volt Power Supply

## Circuit Connection for Arduino Calculator

The complete circuit connection for this Arduino Calculator Project is shown above. The +5V and ground connection shown in the circuit diagram will be obtained from the 5V and ground pin of the Arduino. The Arduino will get its power from your laptop or through the DC jack which uses a 12V adapter or from a 9V battery.

We are running the LCD in a 4-bit system with Arduino so, only the last four data bits of the LCD are connected to Arduino. The keyboard has 8 output pins which we have to connect from pin 0 to pin 7 as mentioned in the diagram. You can also use the following connection table to recheck the connection with Arduino.

Some Arduino boards may show an error while uploading the program if there’s anything connected to pin 0 and pin 1, if you face any error just keep the keypad removed while uploading the program.

After your connections are done your hardware will be looking like this as mentioned shown below.

## Working Principle of Arduino Calculator

Link the connections according to the circuit diagram and upload the code mentioned below. If it’s showing an error cross check that you have added the library according to the instructions given above. You can also run the simulation to check if your hardware has any problems. If everything is okay as it’s supposed to be, then your project will be looking like this below with the LCD displaying this, as the keypad that we used here doesn’t have any specific markings on it, I have assumed the alphabet to be operated.

You should mark what each button actually represents, it will be much easier to interpret, after that’s done, you can directly start using the calculator. Type the number and it will appear on the second line, press the operand and type your second number finally press the “#” key to get the result.

## Arduino Calculator Program

The complete Arduino program of this project is added at the end of this project. The code is divided into tiny meaningful pieces and is explained below.

As mentioned above, we gonna interface an LCD and keypad with Arduino using libraries. So first thing to do is add them to our Arduino IDE. The library for LCD is already included in your Arduino by default so we don’t need to worry about it. For the Keypad library tap the link to download it from GitHub. You will get a ZIP file, add lib to Arduino by Sketch -> Include Library -> Add. ZIP file and direct the location to this downloaded file. After that is done, we are all set and ready to program.

Even if we have used a library to use a keypad we have to mention a few important details (shown below) about the keypad to the Arduino. The variable “Rows” and “Cols” will let you know how many rows and columns our keypad has and the keymap shows the order in which the keys are set on the keyboard. The keypad, I am using in this project looks like this below the keymap also looks the same.

Further below we have mentioned to which pins the keypad is connected using the variable array “rowPins” and “colPins“.

## Arduino Code

### 2 thoughts on “Arduino Calculator Using 4×4 Keypad”

1. Will be updated soon.

2. Hi
What about decimal point and backspace key???