Ardiuno Calculator
Ardiuno Calculator
Objective:
The goal of this project is to create a straightforward calculator using an Arduino
microcontroller paired with a digital display. This calculator will be capable of executing
basic arithmetic operations such as addition, subtraction, multiplication, and division. Users
will input their calculations via buttons or a keypad, and the results will be shown in real-time
on the digital display.
By developing this project, we aim to illustrate how Arduino can be utilized to perform
essential computational tasks while also providing a clear visual interface for user interaction.
This hands-on experience will deepen our understanding of embedded systems, including
how to manage user inputs, process data, and display outputs effectively.
Ultimately, this project serves not only as a practical application of electronics and
programming but also as an educational tool that enhances familiarity with integrating
hardware and software in creating functional devices.
Circuit diagram:
1. Components Overview
Arduino Microcontroller: The heart of the system that executes the program, processes
inputs, and controls the display.
Digital Display: This can be a 7-segment display or an LCD that shows the numbers and
results.
Input Device: A keypad or set of buttons used for number and operation input.
Power Supply: Typically powered by USB or batteries to operate the entire system.
2. User Input
Input Mechanism: The user inputs numbers (0-9) and operations (addition, subtraction,
multiplication, division) using the buttons or keypad.
Button Press Detection: The Arduino reads the state of each button through its digital input
pins. Each button press corresponds to either a number or an operation.
3. Data Processing
After receiving input from the user, the calculator processes the data:
Input Storage: The Arduino temporarily stores the input values in variables for later
computation.
Operation Identification: The code determines which arithmetic operation is to be
performed based on the pressed operation button.
Execution of Calculations: The Arduino uses built-in functions to carry out the specified
arithmetic operation on the stored input values. For example, if the user inputs "5", then
selects "+", and then inputs "3", the Arduino calculates the result as "8".
Once the calculation is complete, the result needs to be presented to the user:
Result Formatting: The calculated result is formatted to be suitable for display. If using a 7-
segment display, each digit is prepared for representation.
Updating the Digital Display: The Arduino sends the formatted result to the digital display,
which illuminates the corresponding segments or characters to show the final output clearly.
5. Continuous Operation
6. Power Management
Power Source: It can be powered via USB or batteries, ensuring convenience and portability.
Energy Efficiency: The Arduino manages power consumption, allowing for extended usage
without frequent battery changes.
7. Software Implementation
Input Handling Code: This part of the code reads and debounces the button presses.
Logic for Operations: Conditional statements and loops manage the calculation process
based on user inputs.
Display Control Functions: Functions are written to update the display with the current
input and results, ensuring that users receive real-time feedback.
Conclusion
The Arduino-based calculator project successfully achieved its objectives, demonstrating the
capability to perform basic arithmetic operations. The following results were observed during
testing and implementation:
1. Functionality
The calculator was able to perform the following basic operations accurately:
Addition: The calculator correctly added two numbers and displayed the result. For
example, inputting "3", then selecting "+", followed by "5", resulted in "8".
Subtraction: When testing subtraction, the calculator subtracted the second number from
the first correctly. For instance, entering "10", then "-", and "4" yielded "6".
Multiplication: The multiplication function also worked as expected. For example, inputting
"7", then "×", and "6" produced "42".
Division: The division operation was accurate as well, with the calculator returning "2" when
"10" was divided by "5".
Input Handling: The calculator effectively managed user input through the keypad. Button
presses were registered promptly, with a negligible delay.
Real-time Display: The digital display updated in real time as the user entered numbers and
operations. Each button press resulted in immediate visual feedback, ensuring a user-
friendly experience.
3. User Interaction
User testing indicated that the interface was intuitive. Users were able to:
Correct Results: All arithmetic operations returned accurate results. This was verified
through multiple test cases for each operation.
Error Handling: The implemented error handling effectively addressed invalid operations,
such as division by zero. When users attempted to divide a number by zero, the display
showed an error message or a predefined notification, preventing confusion.
5. Observational Data
5+3 8 8
10 - 4 6 6
7×6 42 42
20 ÷ 5 4 4
6. Performance Metrics
Response Time: The calculator responded to inputs with a delay of less than 100
milliseconds, providing an efficient user experience.
Power Consumption: The system operated effectively on both USB and battery power,
demonstrating low power consumption suitable for portable use.
7. Conclusion
The Arduino-based calculator successfully meets its design goals, effectively performing
basic arithmetic operations while providing a user-friendly interface for input and output.
This project illustrates the integration of hardware and software, showcasing how an Arduino
can serve as a reliable platform for building functional electronic devices. The positive results
from testing highlight the potential for further enhancements, such as expanding the
calculator to handle more complex functions or incorporating additional features like memory
storage and scientific calculations. Overall, this project has provided valuable insights into
embedded system design and the practical applications of microcontrollers
Arduino code:
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
char keys[ROWS][COLS] = {
};
int answer = 0;
void setup() {
lcd.begin(16, 2);
lcd.backlight();
lcd.clear();
void loop() {
num1 += key;
lcd.setCursor(0, 0);
lcd.print(num1);
num2 += key;
lcd.setCursor(0, 1);
lcd.print(num2);
final = true;
else if (!presentValue && key != NO_KEY && (key == '/' || key == '*' || key == '-' || key ==
'+')) {
presentValue = true;
op = key;
lcd.setCursor(num1.length() + 1, 0);
lcd.print(op);
int n1 = num1.toInt();
int n2 = num2.toInt();
switch(op) {
case '/':
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Ans: ");
lcd.print(answer);
presentValue = false;
final = false;
num1 = "";
num2 = "";
op = ' ';
lcd.clear();
presentValue = false;
final = false;
num1 = "";
num2 = "";
answer = 0;
op = ' ';
}
Hardware picture: