Vidyasagar Academy Wishes a Very Happy, Healthy & Prosperous Diwali to all our Students & Teachers!
To work on this project, just connect Arduino UNO with data cable to your PC or laptop. Then upload the given program in it. Press Ctrl-Shift-M to open Serial Monitor window. Enter two numbers with required mathematical operator, and press Enter.
Examples
- Type 3+5 and press Enter to get the answer.
- Type 36/3 and press Enter to get the answer.
- Type 785*562348 and press Enter to get the answer.
- Type 574-394 and press Enter to get the answer.
Page Contents
show
Video Lecture with Demo
The Code
/* * Calculator using Arduino * Designed by Vidyasagar Academy, Akola * Date: 04.08.2020 * www.vsa.edu.in */ double first_number; // the first number variable in calculations double second_number; // the second number variable in calculations char math_operator; // create a char variable to store the calculated value double answer; // the answer of the calculation /* ***** IMPORTANT NOTE ***** * This calculator can calculate only the integer values. * This calculator can calculate only two numbers at its input, for example: * 2+2 is allowed, but 2+2+2+2 is not allowed. */ void setup() { Serial.begin(9600); // begins serial communications Serial.println("Welcome to my calculator...!"); Serial.println("Ready to Calculate..."); Serial.println(); } void loop() { while(Serial.available() > 1) { first_number = Serial.parseInt(); math_operator = Serial.read(); second_number = Serial.parseInt(); calculate(); // user defined function to perform the calculations Serial.print(first_number); Serial.print(" "); // create one space after first number Serial.print(math_operator); Serial.print(" "); // create one space after operator Serial.print(second_number); Serial.print(" = "); Serial.println(answer); // Prints the answer of the calculation delay(1000); Serial.println(); // creates one white space after each calculation Serial.println("Ready to calculate next..."); } } void calculate() { // Custom function that performs the calculations if (math_operator == '+') { answer = first_number + second_number; } else if (math_operator == '-') { answer = first_number - second_number; } else if (math_operator == '*') { answer = first_number * second_number; } else if (math_operator == '/') { answer = first_number / second_number; } }
More Advanced Arduino Projects
All these projects are password protected and paid projects. If you want construct these projects you will have to register and make online payment of Rs.1000/- For more details, contact us.
- Advanced Arduino Robotics Project #1, The project of Sanguinoscope Blood Group Typing Project
- Advanced Arduino Robotics Project #2, Arduino Advanced Calculator
- Advanced Arduino Robotics Project #3, Arduino Security System cum Door Bell using Piezo Sensor
You can also calculate the percentage by inserting following code in void calculate() function.
[php]
else if (math_operator == ‘%’)
{
answer = (first_number * 100) / second_number;
}
[/php]
An interesting discussion is worth comment. I think that you should write more on this topic, it might not be a taboo subject but generally people are not enough to speak on such topics. To the next. Cheers
This actually answered my problem, thanks!
Great project sir!