Arduino Based Simple Calculator with 16×2 LCD and Keypad

Arduino Based Simple Calculator with 16x2 LCD and Keypad
0
0
4 min read

Build a simple calculator using Arduino, 4×4 keypad, and 16×2 LCD display. Learn how to design, code, and expand this project from scratch with a complete guide and circuit diagram.


🧠 Introduction

What is it?

This project is a DIY digital calculator built using an Arduino Uno, a 4×4 matrix keypad, and a 16×2 LCD display. It can perform basic arithmetic operations like addition, subtraction, multiplication, and division.

What the project does

When powered on, the calculator takes two operands and an operator as input from the keypad. It processes the inputs using Arduino logic and displays the result on the LCD.

Real-world use case

This kind of project is a gateway to embedded systems design. The integration of keypad interfacing, LCD display control, and core arithmetic logic replicates fundamental elements of many consumer electronic devices.

Skill level and expected outcome

Level: Beginner to Intermediate
Outcome: You’ll learn keypad scanning, LCD interfacing, and code optimization for logical operations using Arduino.


📦 Components Required

ComponentQuantityDescriptionBuy Link
Arduino Uno R31Main micro controller boardBuy from Elecsynergy
4×4 Matrix Keypad1Input device for entering digits and operationsBuy from Elecsynergy
16×2 LCD Display1Display the input and resultBuy from Elecsynergy
10K Potentiometer1Adjust LCD brightnessBuy from Elecsynergy
Breadboard1Circuit prototypingBuy from Elecsynergy
Jumper Wires~20Electrical connectionsBuy from Elecsynergy
USB Cable (A to B)1Arduino programmingBuy from Elecsynergy
9V Battery + DC Connector1Optional portable powerBuy from Elecsynergy

🔌 Circuit Diagram + Explanation

Circuit Diagram

Key Connections:

  • LCD (16×2):
    • RS → Pin 7
    • E → Pin 6
    • D4 → Pin 5
    • D5 → Pin 4
    • D6 → Pin 3
    • D7 → Pin 2
    • VSS → GND
    • VDD → +5V
    • V0 → Middle terminal of potentiometer
    • RW → GND
    • A, K (Backlight) → +5V and GND
  • 4×4 Keypad:
    • Connect 8 pins to Digital Pins 8 to 13 and A0–A1

Explanation:

The keypad sends key presses to the Arduino. Based on these inputs, the Arduino processes operands and operators. The results are displayed on the LCD in real time.


💻 Arduino Code

#include <LiquidCrystal.h>
#include <Keypad.h>

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

// Keypad setup
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] = {8, 9, 10, 11};
byte colPins[COLS] = {12, 13, A0, A1};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

String input = "";
char operation;
float firstNum, secondNum;

void setup() {
  lcd.begin(16,2);
  lcd.print("Calc Ready");
  delay(1000);
  lcd.clear();
}

void loop() {
  char key = keypad.getKey();

  if (key) {
    if (key >= '0' && key <= '9') {
      input += key;
      lcd.print(key);
    } else if (key == '+' || key == '-' || key == '*' || key == '/') {
      firstNum = input.toFloat();
      operation = key;
      input = "";
      lcd.setCursor(0,1);
      lcd.print(operation);
    } else if (key == '=') {
      secondNum = input.toFloat();
      float result = 0;

      switch (operation) {
        case '+': result = firstNum + secondNum; break;
        case '-': result = firstNum - secondNum; break;
        case '*': result = firstNum * secondNum; break;
        case '/': result = secondNum != 0 ? firstNum / secondNum : 0; break;
      }

      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Result: ");
      lcd.print(result);
      delay(2000);
      lcd.clear();
      input = "";
    } else if (key == 'C') {
      input = "";
      lcd.clear();
    }
  }
}

⚙️ Working Explanation

The Arduino receives numeric and operational inputs via the 4×4 matrix keypad. The logic stored in the micro controller performs arithmetic operations based on button inputs.

  • Key Input: Captured as a string and converted to float.
  • Operator Detection: Triggers the transition from first to second operand.
  • Result Computation: Executes arithmetic logic and displays it on the LCD.

🎥 Demo / Output Preview


🛠️ Troubleshooting & Tips

IssueFix
LCD not showing anythingCheck contrast potentiometer and wiring
Wrong result on operationsEnsure float conversion and operator switch logic are intact
Keypad not responsiveRecheck wiring and debounce delays
LCD flickersAdd delays and use lcd.clear() strategically

🚀 Project Expansion Ideas

  • Add decimal point support
  • Use I2C LCD to reduce pin count
  • Add EEPROM storage for previous result
  • Integrate with a buzzer for sound feedback
  • Make it a scientific calculator using menus

Challenge Yourself: Try adding a memory button (M+) or square root function!


📚 Conclusion

This Arduino-based calculator project demonstrates a practical application of keypad scanning and LCD interfacing. It’s a stepping stone into more complex human-machine interfaces and digital electronics.

💬 Did you like this tutorial? Share your version on social media and tag us!


🛒 Buy the Full Kit from Elecsynergy

Ready to build? Save time and order the complete kit directly from our store:

👉 Buy Calculator Project Kit – Elecsynergy

Leave a Reply