# Calculator using Arduino Uno in proteus simulation

#### Calculator using Arduino Uno in proteus simulation

In this article we will learn how to Interface Calculator using Arduino Uno in proteus simulation.
In the last post we will learn how to Interface Arduino MCP23008 IO Expander circuit in proteus. You can visit our website,
I hope you appreciate my work, let’s discuss about today’s project.

#### Components:

1. Arduino Uno
2. LCD display
4. Push button
5. Jumper wires

#### Construction…

• Connect pin A of Keypad with pin 4 of Arduino Uno
• Connect pin B of Keypad with pin 5 of Arduino Uno
• Connect pin C of Keypad with pin 6 of Arduino Uno
• Connect pin D of Keypad with pin 7 of Arduino Uno
• Connect pin 1 of Keypad with pin 3 of Arduino Uno
• Connect pin 2 of Keypad with pin 2 of Arduino Uno
• Connect pin 3 of Keypad with pin A2 of Arduino Uno
• Connect pin 4 of Keypad with pin A3 of Arduino Uno
• Connect pin A1 of Arduino with one side of Push button
• Connect 2nd side of push button with GND
• Connect pin A0 of Arduino with one side of Push button
• Connect 2nd side of push button with GND
• Connect RW, VEE, VSS pins of LCD display with GND
• Connect VDD pin of LCD display with +ve
• Connect RS pin of LCD display with pin 13 of Arduino
• Connect E pin of LCD display with pin 12 of Arduino
• Connect D4 pin of LCD display with pin 11 of Arduino
• Connect D5 pin of LCD display with pin 10 of Arduino
• Connect D6 pin of LCD display with pin 9 of Arduino
• Connect D7 pin of LCD display with pin 8 of Arduino

#### Working…

Creating a basic calculator using an Arduino microcontroller involves connecting a keypad or other input device, a display, and writing code to perform arithmetic operations.

#### Applications…

1. Basic Arithmetic Calculator
2. Scientific Calculator
3. Graphing Calculator
4. Conversion Calculator
5. Matrix Calculator

1. Cost-Effective
2. Customization
3. Educational Tool
4. Open-Source
5. Multi-Purpose Device

#### Program code…

[dt_code]

#include <LiquidCrystal.h>

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] = {7, 6, 5, 4};

byte colPins[COLS] = {3, 2, A2, A3};

// Created instances

LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // Initialize the LCD on these pins

boolean firstNumState = true;

String firstNum = “”;

String secondNum = “”;

float result = 0.0;

char operatr = ‘ ‘;

const int squareButtonPin = A0; // Connect ‘Square’ button to analog pin A0

const int cubeButtonPin = A1;  // Connect ‘Cube’ button to analog pin A1

void setup() {

lcd.begin(16, 2);

lcd.setCursor(0, 0);

lcd.print(“Arduino Calculator”);

lcd.setCursor(0, 1);

delay(1000);

lcd.clear();

clr();

pinMode(squareButtonPin, INPUT_PULLUP);

pinMode(cubeButtonPin, INPUT_PULLUP);

}

void loop() {

if (newKey != NO_KEY && (newKey == ‘1’ || newKey == ‘2’ || newKey == ‘3’ || newKey == ‘4’ || newKey == ‘5’ || newKey == ‘6’ || newKey == ‘7’ || newKey == ‘8’ || newKey == ‘9’ || newKey == ‘0’)) {

if (firstNumState == true) {

firstNum = firstNum + newKey;

lcd.print(newKey);

}

else {

secondNum = secondNum + newKey;

lcd.print(newKey);

}

}

if (newKey != NO_KEY && (newKey == ‘+’ || newKey == ‘-‘ || newKey == ‘*’ || newKey == ‘/’)) {

if (firstNumState == true) {

operatr = newKey;

firstNumState = false;

lcd.setCursor(15, 0);

lcd.print(operatr);

lcd.setCursor(5, 1);

}

}

if (newKey != NO_KEY && newKey == ‘=’) {

if (operatr == ‘+’) {

result = firstNum.toFloat() + secondNum.toFloat();

}

if (operatr == ‘-‘) {

result = firstNum.toFloat() – secondNum.toFloat();

}

if (operatr == ‘*’) {

result = firstNum.toFloat() * secondNum.toFloat();

}

if (operatr == ‘/’) {

result = firstNum.toFloat() / secondNum.toFloat();

}

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(firstNum);

lcd.print(operatr);

lcd.print(secondNum);

lcd.setCursor(0, 1);

lcd.print(“=”);

lcd.print(result);

firstNumState = true;

}

if (newKey != NO_KEY && newKey == ‘C’) {

clr();

}

// ‘Square’ button is pressed

float num = firstNum.toFloat();

float square = num * num;

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(“Square of “);

lcd.print(num);

lcd.setCursor(0, 1);

lcd.print(“is”);

lcd.setCursor(5, 1);

lcd.print(square);

delay(2000);

clr();

}

// ‘Cube’ button is pressed

float num = firstNum.toFloat();

float cube = num * num * num;

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(“Cube of “);

lcd.print(num);

lcd.setCursor(0, 1);

lcd.print(“is”);

lcd.setCursor(5, 1);

lcd.print(cube);

delay(2000);

clr();

}

}

void clr() {

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(“1st: “);

lcd.setCursor(12, 0);

lcd.print(“op “);

lcd.setCursor(0, 1);

lcd.print(“2nd: “);

lcd.setCursor(5, 0);

firstNum = “”;

secondNum = “”;

result = 0;

operatr = ‘ ‘;

}

[/dt_code]