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.


Arduino Calculator

Circuit Diagram

Arduino Calculator Circuit Diagram

Components Required

  • Arduino Nano
  • 16×2 LCD Display
  • I2C LCD Module
  • 4×4 Keypad
  • Connection Wires
  • Breadboard
  • 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.

PCB Design

After designing the schematic diagram of the Arduino Calculator System, the assembled components and wiring are too clumsy and looked very unprofessional. In fact, the wiring also has a chance of loose connection. To give it a clean and professional look and also to compress the size, I decided to build its PCB prototype using EasyEDA software as it is so simple to use. Now come to the main part, where we need to order our PCB prototype. I always prefer PCBWay for their quality assurance, fastest delivery and also for 24/7 customer support.

PCB View

Arduino Calculator 2D View
2D View
Arduino Calculator 3D View
3D View

Why I Choose PCBWay as My First Preference?

I’ve done several runs with PCBWay and am happy with the results, it’s good quality. The etching, solder mask, and hole sizes are all done well and that is what matters to me. It takes a few hours for a design to get approved and then a couple of days to finish and ship. With more than a decade in the field of PCB prototypes and fabrication, PCBWay has proved its assurance from time to time. They always look at the customer’s needs from different regions in terms of quality, on-time delivery, cost-effectiveness and any other demanding requests.

PCBWay Gold Finish
PCBWay Thickness

These PCBs were manufactured by PCBWay and the finish quality really impressive, especially with the gold finish path. If you want to finish your product faster you could also ask PCBWay to make a panelized order where you receive multiple PCBs in a single panel. Together with this, you will also receive SMT Stencil from PCBWay which will save you time and effort. All the orders are high quality and could select a lot of settings such as thickness, flexible PCB, the colour of the solder masks, the number of layers, material, surface finish and more.

PCBWay different types of solder masks

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”

Leave a Comment