Arduino Calculator Project Using Keypad and LCD | Makers’ Muse
Overview
A calculator is a device used to solve mathematical problems easily and in a fast way. This calculator can add, subtract, multiply, and Divide.Â
In this project, we have used a (4*4) keypad to take input and an LCD to show output. A potentiometer is also used to adjust the LCD to show the output. Keys usedÂ
A – Addition
B – Subtract
C – Multiplication
D – Divide
Hardware requiredÂ
- Arduino Uno R3
- Potentiometer
- Keypad 4*4
- Resistor
- LCD
- Jumper Wires
Schematic Diagram

Fig 1. Circuit Diagram
Arduino Code :Â
#include <LiquidCrystal.h>Â
#include <Keypad.h>Â
const byte ROWS = 4;Â
const byte COLS = 4;Â
char keys[ROWS][COLS] = {
  {‘1′,’2′,’3′,’A’},
  {‘4′,’5′,’6′,’B’},
  {‘7′,’8′,’9′,’C’},
  {‘*’,’0′,’#’,’D’}
};
byte rowPins[ROWS] = { 0, 1, 2, 3 };
byte colPins[COLS] = { 4, 5, 6, 7 };Â
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );Â
const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13;Â
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
 long Num1,Num2,Number;
 char key, action;
 boolean result = false;
void setup() {
  lcd.begin(16, 2);Â
  lcd.print(“Calculator”);Â
  lcd.setCursor(0, 1); Â
  lcd.print(“-Raghav”); Â
   delay(2000);Â
    lcd.clear();
}
void loop() {
key = kpd.getKey();Â
if (key!=NO_KEY)
DetectButtons();
if (result==true)
CalculateResult();
DisplayResult();Â Â Â
}
void DetectButtons()
{Â
     lcd.clear();
    if (key==’*’)Â
    {Serial.println (“Button Cancel”); Number=Num1=Num2=0; result=false;}
     if (key == ‘1’)Â
    {Serial.println (“Button 1”);Â
    if (Number==0)
    Number=1;
    else
    Number = (Number*10) + 1;Â
    }
     if (key == ‘4’)Â
    {Serial.println (“Button 4”);Â
    if (Number==0)
    Number=4;
    else
    Number = (Number*10) + 4;Â
    }
     if (key == ‘7’)Â
    {Serial.println (“Button 7”);
    if (Number==0)
    Number=7;
    else
    Number = (Number*10) + 7;Â
    }Â
    if (key == ‘0’)
    {Serial.println (“Button 0”);
    if (Number==0)
    Number=0;
    else
    Number = (Number*10) + 0;Â
    }
     if (key == ‘2’)Â
    {Serial.println (“Button 2”);Â
     if (Number==0)
    Number=2;
    else
    Number = (Number*10) + 2;Â
    }
     if (key == ‘5’)
    {Serial.println (“Button 5”);Â
     if (Number==0)
    Number=5;
    else
    Number = (Number*10) + 5;Â
    }
     if (key == ‘8’)
    {Serial.println (“Button 8”);Â
     if (Number==0)
    Number=8;
    else
    Number = (Number*10) + 8;Â
    }  Â
    if (key == ‘#’)
    {Serial.println (“Button Equal”);Â
    Num2=Number;
    result = true;
    }
     if (key == ‘3’)
    {Serial.println (“Button 3”);Â
     if (Number==0)
    Number=3;
    else
    Number = (Number*10) + 3;Â
    }
     if (key == ‘6’)
    {Serial.println (“Button 6”);Â
    if (Number==0)
    Number=6;
    else
    Number = (Number*10) + 6;Â
    }
     if (key == ‘9’)
    {Serial.println (“Button 9”);
    if (Number==0)
    Number=9;
    else
    Number = (Number*10) + 9;Â
    } Â
      if (key == ‘A’ || key == ‘B’ || key == ‘C’ || key == ‘D’)Â
  {
    Num1 = Number;   Â
    Number =0;
    if (key == ‘A’)
    {Serial.println (“Addition”); action = ‘+’;}
     if (key == ‘B’)
    {Serial.println (“Subtraction”); action = ‘-‘; }
     if (key == ‘C’)
    {Serial.println (“Multiplication”); action = ‘*’;}
     if (key == ‘D’)
    {Serial.println (“Division”); action = ‘/’;} Â
    delay(100);
  }
}
void CalculateResult()
{
  if (action==’+’)
    Number = Num1+Num2;
  if (action==’-‘)
    Number = Num1-Num2;
  if (action==’*’)
    Number = Num1*Num2;
  if (action==’/’)
    Number = Num1/Num2;Â
}
void DisplayResult()
{
  lcd.setCursor(0, 0); Â
  lcd.print(Num1); lcd.print(action); lcd.print(Num2);Â
  if (result==true)
  {lcd.print(” =”); lcd.print(Number);}Â
  lcd.setCursor(0, 1);  Â
  lcd.print(Number);Â
}
Precautions
- Connections should be done properly.
- Arduino is case sensitive, so code accordingly.
- Give different colours to the wires.
- Adjust the potentiometer to get output on the LCD.
Conclusion:
The Arduino Calculator Project, using a keypad and LCD, is a simple yet powerful way to understand embedded systems and electronics. It teaches how hardware and software work together to perform real-world applications like arithmetic operations. Projects like this spark creativity and problem-solving skills in learners.
At Makers’ Muse, we believe in empowering students through hands-on learning. Explore more innovative ideas and enhance your skills with coding schools to become a future-ready innovator.