# Arduino Calculator

by | Mar 26, 2023 | Arduino, Basic Coding, Coding

Home » Coding » Arduino Calculator

## Introduction of the Project

Building a simple Arduino calculator is an excellent way to learn and practice programming and electronics skills. It involves a basic understanding of the Arduino platform, electronic components, and programming in C++. With an Arduino board, a few electronic components, and some programming knowledge, you can create a functional calculator that can perform various mathematical operations.

To build an Arduino calculator, you will need to know how to connect the electronic components and write the necessary code to make them work together. The components required include an Arduino board, an LCD display, a keypad, resistors, and connecting wires. The LCD display is used to show the input and output of the calculator, while the keypad is used to input numbers and perform mathematical operations.

The programming language used is C++, which is the language of choice for Arduino programming. You will need to know how to write code to read the input from the push buttons, perform the required mathematical operations, and display the results on the LCD display. You will also need to know how to handle errors and edge cases that may arise during the calculation process.

In this tutorial, we will provide step-by-step instructions on how to build a simple Arduino calculator. We will cover the necessary electronic components, wiring diagrams, and programming code required to make the calculator work. By the end of this tutorial, you will have a functional Arduino calculator that you can use for basic math calculations, and you will have gained valuable skills in electronics and programming.

## Supplies

To build this Arduino Calculator, we will use a keypad and LCD screen to perform basic maths operations.

## Circuit Diagram ## Steps To Make A DIY Arduino Calculator

Step 1: Gather all the necessary components on the Digital Board or Physical Table.

Step 2: Plug the LCD into the Breadboard.

Step 3: Connect Rows 1 to 4 and Columns 1 to 4 of the keypad to the 0 to 7 number pins of the Arduino, respectively, as shown in the figure.

LCD:

Step 4: Connect the Power & the LED anode terminal of the LCD to the 5V pin of the Arduino.

Step 5: Connect the Ground, Contrast, and Read/Write & LED cathode terminals of LCD to the GND pin of the Arduino, as shown in the circuit.

Step 6: Connect the Register Select, Enable, & DB4 to DB7 pins of LCD to the 8 to 13 number pins of the Arduino, respectively, as shown in the figure.

## Source Code

```#include <LiquidCrystal.h>
const byte rows = 4;
const byte columns = 4;
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte pinRows[rows] = {7, 6, 5, 4};
byte pinColumns[columns] = {3, 2, 1, 0};
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
void setup()
{
lcd.begin(16,2);
}

void loop()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Choose any one ");
lcd.setCursor(0, 1);
lcd.print(" Option ");
delay(2000);

lcd.clear();
lcd.setCursor(0, 0);
lcd.setCursor(0, 1);
lcd.print(" B = Subtraction ");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" C = Multiplication ");
lcd.setCursor(0, 1);
lcd.print(" D = Division ");
delay(2000);

lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Enter option:");
delay(2000);

lcd.setCursor(5, 1), lcd.print(key);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Enter Operand 1:");
delay(2000);

lcd.setCursor(0, 1);
lcd.setCursor(5, 1), lcd.print(operand1);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Enter Operand 2:");
delay(2000);

lcd.setCursor(0, 1);
lcd.setCursor(5, 1), lcd.print(operand2);
delay(2000);
lcd.clear();

if(key == 'A')
{
lcd.setCursor(0, 0);
lcd.print(operand1);
lcd.setCursor(2, 0);
lcd.print(" + ");
lcd.setCursor(7, 0);
lcd.print(operand2);

lcd.setCursor(10, 0);
lcd.print(" = ");
lcd.setCursor(14, 0);
lcd.print(operand1 + operand2);
delay(2000);
}

if(key == 'B')
{
lcd.setCursor(0, 0);
lcd.print(operand1);
lcd.setCursor(2, 0);
lcd.print(" - ");
lcd.setCursor(7, 0);
lcd.print(operand2);

lcd.setCursor(10, 0);
lcd.print(" = ");
lcd.setCursor(14, 0);
lcd.print(operand1 - operand2);
delay(2000);
}

if(key == 'C')
{
lcd.setCursor(0, 0);
lcd.print(operand1);
lcd.setCursor(2, 0);
lcd.print(" * ");
lcd.setCursor(7, 0);
lcd.print(operand2);

lcd.setCursor(10, 0);
lcd.print(" = ");
lcd.setCursor(14, 0);
lcd.print(operand1 * operand2);
delay(2000);
}

if(key == 'D')
{
lcd.setCursor(0, 0);
lcd.print(operand1);
lcd.setCursor(2, 0);
lcd.print(" / ");
lcd.setCursor(7, 0);
lcd.print(operand2);

lcd.setCursor(10, 0);
lcd.print(" = ");
lcd.setCursor(14, 0);
lcd.print(operand1 / operand2);
delay(2000);
}
}```

## Explanation of the Code

1. We first included two header files, “LiquidCrystal” for LCD & one for Keypad, respectively.

2. After that, we initialized class arrays and variables that will be required in the function.

3. Next, we created a setup function in which we declared the LCD as having 2 rows and 16 columns.

4. In the loop function, we display the options, then take the value from the keypad of operands and operator, and accordingly, using the if statement, we print the result.

## Output On starting the simulation, we will be able to see the display in LCD and perform basic operations of maths.

More Arduino Projects>>>