## Introduction: Arduino Calculator Using 4X4 Keypad

In this tutorial we will build our own calculator with Arduino. The values can be sent in through a keypad (4×4 keypad) and result can be viewed on a LCD screen. This calculator could perform simple operations like Addition, Subtraction, Multiplication and Division with whole numbers. But once you understand the concept you can implement even scientific functions with Arduino’s built in functions.

Arduino Uno

16×2 LCD Display

Jumper Cables

Arduino Cable

## Step 3: Source Code :

```/*      © Techtronic Harsh

#include   <LiquidCrystal.h>LiquidCrystal lcd(0, 1, 2, 3, 4, 5);
const byte ROWS = 4;
const byte COLS = 4;char keys [ROWS] [COLS] = {
{'1', '2', '3', '+'},
{'4', '5', '6', '-'},
{'7', '8', '9', '*'},
{'C', '0', '=', '/'}
};
byte rowPins[ROWS] = {13,12,11,10};
boolean next = false;
boolean final = false;
String num1, num2;
char op;void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Techtronic Harsh");
lcd.setCursor(0,1);
lcd.print("   Calculator");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("    Like And");
lcd.setCursor(0,1);
lcd.print("  Subscribe Us"    );
delay(3000);
lcd.clear();
}void loop(){  char key = myKeypad.getKey();  if (key != NO_KEY && (key=='1'||key=='2'||key=='3'||key=='4'||key=='5'||key=='6'||key=='7'||key=='8'||key=='9'||key=='0'))
{
if (presentValue != true)
{
num1 = num1 + key;
int numLength = num1.length();
lcd.setCursor(15 - numLength, 0); //to adjust one whitespace for operator
lcd.print(num1);
}
else
{
num2 = num2 + key;
int numLength = num2.length();
lcd.setCursor(15 - numLength, 1);
lcd.print(num2);
final = true;
}
}  else if (presentValue == false && key != NO_KEY && (key == '/' || key == '*' || key == '-' || key == '+'))
{
if (presentValue == false)
{
presentValue = true;
op = key;
lcd.setCursor(15,0);
lcd.print(op);
}
}  else if (final == true && key != NO_KEY && key == '='){
if (op == '+'){
}
else if (op == '-'){
}
else if (op == '*'){
}
else if (op == '/'){
}
lcd.clear();
lcd.setCursor(15,0);
lcd.autoscroll();
lcd.noAutoscroll();
}
else if (key != NO_KEY && key == 'C'){
lcd.clear();
presentValue = false;
final = false;
num1 = "";
num2 = "";
op = ' ';
}

*/```

## Step 4: Working :

Make the connections as per circuit diagram and upload the code. If it shows error make sure you have added the library as per the instruction given above.

Character on Keypad and Assumption :