กลับไปหน้ารวมไฟล์
calculator-with-16x2-lcd-display-and-4x4-keypan-753fb1-en.md

When I was in school I needed a calculator but there were no more so I decided to make this. (btw to power your Arduino you can use a 9v battery)

This article will show you what a calculator consists of, from the input system (Keypad Matrix) to the calculation logic working behind the tiny controller.

🛠 Hardware Components

The design of this calculator emphasizes simplicity yet durability, using readily available components found in typical engineering labs, as follows:

  1. Microcontroller (Arduino Uno/Nano): Functions as the brain, processing commands, receiving input from buttons, and sending data for display.
  2. 4x4 Matrix Keypad: The primary input device, featuring numeric buttons 0-9 and basic operators (+, -, *, /), along with '=' and 'C' for clearing values.
    • In engineering terms: A matrix keypad saves Arduino I/O pins by using a row and column scanning technique instead of connecting one button per pin.
  3. LCD Display (16x2) with I2C module: A display screen with 2 lines and 16 characters.
    • Why I2C? Using I2C reduces the number of wires from 6-10 to just 4 (VCC, GND, SDA, SCL), making the internal wiring much neater.
  4. Power Source (9V Battery): For portability, power can be conveniently supplied via the DC Jack or the VIN pin of the Arduino.

💻 System Logic

For the calculator to function correctly, the internal program is designed with a State Machine logic to differentiate whether the user is typing the first number, selecting an operator, or waiting for a result.

1. Input Reception via Matrix Scanning

The program uses the Keypad.h library to continuously check which intersection between a Row and a Column has current flowing through it. When detected, the electrical signal is converted into a character (Char) as defined in our Keymap.

2. Processing Logic (Mathematical Flow)

  • Input Stage: When a number is pressed, the program stores the value in a String or Long variable to concatenate into larger multi-digit numbers (e.g., pressing 1 and then 2 will become 12).
  • Operator Stage: When an operator button (+, -, *, /) is pressed, the program moves the first number's value to a temporary variable (e.g., num1) and prepares to receive the second number (num2).
  • Calculation Stage: When the '=' button is pressed, the switch-case function in the Code determines which mathematical operation to perform on num1 and num2, then displays the result on the LCD screen.

3. Handling Decimals and Negative Numbers

A good calculator must be thorough. In this project, we use float or double variable types for calculations to support results with decimal points and non-integer divisions.

🔌 Wiring Diagram

  • Keypad (8 pins): Connects to Arduino's Digital pins (e.g., 2, 3, 4, 5, 6, 7, 8, 9)
  • I2C LCD:
    • VCC -> 5V
    • GND -> GND
    • SDA -> A4 (for Uno)
    • SCL -> A5 (for Uno)
  • Power: The positive terminal of the 9V battery connects to the VIN pin, and the negative terminal connects to GND.

🚀 Getting Started

  1. Assemble the components according to the wiring diagram.
  2. Install the necessary Libraries in Arduino IDE:
    • Keypad by Mark Stanley
    • LiquidCrystal_I2C by Frank de Brabander
  3. Upload the Source Code to the board.
  4. Connect the 9V battery and start using your calculator!

📝 Creator's Summary

Building this calculator was not just about solving the shortage of equipment in the classroom; it was also an excellent exercise in learning about Human-Machine Interface (HMI) and memory management in Embedded Systems.

If you are just starting to learn Arduino, this project will help you understand the relationship between Software and Hardware most clearly.

Note: For Source Code or installation images, please refer to the folders in this Repository.

ข้อมูล Frontmatter ดั้งเดิม

apps:
  - "1x Arduino IDE"
author: "randomnonsense"
category: ""
components:
  - "1x 4x4 keypad"
  - "1x Breadboard (generic)"
  - "1x Standard LCD - 16x2 White on Blue"
  - "1x Arduino UNO"
  - "1x Jumper wires (generic)"
description: "Calculator with extra steps."
difficulty: "Intermediate"
documentationLinks: []
downloadableFiles: []
encryptedPayload: "U2FsdGVkX1+z3eF+TVHOEDDgmnVO8/FI5BBxBJpivOoPPG7DRZzQeD24rC3jMtTP6l2e1T31TTVLNzXj55Y+lOy15ITUZzsJFyeyvLDGOvM="
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/calculator-with-16x2-lcd-display-and-4x4-keypan-753fb1_cover.jpg"
lang: "en"
likes: 0
passwordHash: "5322e0f0caf32086bba00799dcb0df2fd47a4d2bf1808bd61980bcb435f8bf12"
price: 1120
seoDescription: "Build a Calculator using Arduino with 16x2 LCD display and 4x4 keypad. Perfect for learning coding and electronics."
tags:
  - "lights"
  - "energy efficiency"
  - "smart appliances"
title: "Calculator with 16x2 LCD display and 4x4 keypan"
tools: []
videoLinks: []
views: 3087