• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Need circuit help? Post them in the comments! I've answered over 50,000!

Blog | Categories | About | Contact | Calculators-online
You are here: Home / Arduino Projects / How to Make a Simple Math Calculator using Arduino

How to Make a Simple Math Calculator using Arduino

Last Updated on December 5, 2024 by Swagatam 2 Comments

In this post, I will show how to construct a calculator using Arduino, which can perform far complex arithmetical calculation than an ordinary calculator.

The motto of this post is not to make a calculator using Arduino, but to showcase the arithmetical capability of Arduino, which performs various complex data interpretations and calculations from the sensors and other peripherals.

For this fun project you just need a USB cable and Arduino of your choice. We are going to get the result of our calculations via serial monitor of Arduino IDE. If you are familiar with basics of C language this project is a piece of cake, and you can create your own programs which does even more complex arithmetical calculations. Here we are going to use a header file #include<math.h> which is inbuilt in the Arduino IDE compiler, so you don’t need to download any library.

We can even connect a LCD display and keyboard to Arduino and make a scientific calculator, but it is subject of another article. If you are familiar with “Turbo C++” one of our first programs will be addition of two numbers, all the arithmetical calculations are carried within the CPU of the computer. But here, all the arithmetical calculations are carried out in the Arduino microcontroller. Let’s start with addition, subtraction, division and multiplication.

Here is a program with two variable a and b, using these two variables we can do the above stated calculations using “ +, -, * / ” operators, which are addition, subtraction, multiplication, division respectively.

Program:

//-------------------Program Developed by R.Girish---------------//
#include<math.h>
float a = 500;
float b = 105.33;
float add;
float sub;
float divide;
float mul;
void setup()
{
Serial.begin(9600);
Serial.println("Simple Arduino Calculator:");
Serial.println("n");
Serial.print("a = ");
Serial.println(a);
Serial.print("b = ");
Serial.println(b);
Serial.println("n");
Serial.print("Addition: ");
Serial.print("a + b = "); // add
add=a+b;
Serial.println(add);
Serial.print("Multiplication: ");
Serial.print("a * b = "); // multiply
mul=a*b;
Serial.println(mul);
Serial.print("Division: ");
Serial.print("a / b = "); // divide
divide=a/b;
Serial.println(divide);
Serial.print("Subtraction: ");
Serial.print("a - b = "); // subtract
sub=a-b;
Serial.println(sub);
}
void loop() // we need this to be here even though its empty
{
}
//-------------------Program Developed by R.Girish---------------//

OUTPUT:

 

add 2

In the above program we are using “Float” which performs decimal functions, we are using “Serial.print();” for printing the values in serial monitor, rest of the program is self explanatory. You can change the variable a and b in the program with your own values.

Let’s move something more interesting, area of circle. The formula for area of circle is: pi * radius^2 or pi times radius square. Since the value of pi is constant, we need to assign it in the program using “float” since the value of pi is 3.14159 where decimal point comes to play.

Program:

//-------------------Program Developed by R.Girish---------------//
#include<math.h>
float pi = 3.14159;
float radius = 50;
float area;
void setup()
{
Serial.begin(9600);
Serial.println("Arduino Area Calculator:");
Serial.print("n");
Serial.print("Radius = ");
Serial.print(radius);
Serial.print("n");
area = pi*sq(radius);
Serial.print("The Area of circle is: ");
Serial.println(area);
}
void loop()
{
// we need this to be here even though it is empty
}
//-------------------Program Developed by R.Girish---------------//

OUTPUT:

 

Simple Math Calculator using Arduino

Again, you can change the values of your own in the program. We are using “sq()” which does squaring of the number with in the parenthesis. Now let’s move to next level. In this program we are going to use Pythagoras theorem for calculating the hypotenuse of a triangle. The formula behind this is: “hyp=sqrt(sq(base) + sq(height)); “ or square root of (base square + height square).

Program:

//-------------------Program Developed by R.Girish---------------//
#include<math.h>
float base = 50.36;
float height = 45.336;
float hyp;
void setup()
{
Serial.begin(9600);
Serial.println("Arduino Pythagoras Calculator:");
Serial.print("n");
Serial.print("base = ");
Serial.println(base);
Serial.print("height = ");
Serial.print(height);
Serial.print("n");
hyp=sqrt(sq(base) + sq(height));
Serial.print("The hypotenuse is: ");
Serial.print(hyp);
}
void loop()
{
// we need this to be here even though its empty
}
//-------------------Program Developed by R.Girish---------------//

OUTPUT:

 

phytho 1

You can change the values of base and height with your own values in the program. We used “sqrt()” which does square root function values within the parenthesis. Now let’s do a popular program which we would have learned in our beginning of C language course, Fibonacci series.

In a nutshell the Fibonacci series is addition of two previous numbers which gives next number and so on, it always starts with 0, 1. For example: 0, 1. So 0+1=1; next series is 0, 1, 1. So, 1+1=2. So next series is, 0, 1, 1, 2…..and so on. The program written here is to find the Fibonacci number for first nth digit. You can change the value of ‘n’ in the program to get the desired Fibonacci series.

Program:

//-------------------Program Developed by R.Girish---------------//
#include<math.h>
int n=6;
int first = 0;
int Second = 1;
int next;
int c;
void setup()
{
Serial.begin(9600);
Serial.print("Fibonacci series for first ");
Serial.print(n);
Serial.print(" numbers are:nn");
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + Second;
first = Second;
Second = next;
}
Serial.println(next);
}
}
void loop()
{
// put your main code here, to run repeatedly:
}
//-------------------Program Developed by R.Girish---------------//

 OUTPUT:

 

fib 1

So, this would have given enough doses to your brain and confused that something designed to control hardware peripherals is doing some nonsense math calculation, if so, you are not alone.

The math plays a major role in electronics that’s why our textbook is full of mathematical equations, that we don’t even understand and that point where calculators come to rescue us and here it is.

If you any queries regarding this simple calculator circuit using Arduino, you can express them through ever valuable comments.

You'll also like:

  • 1.  Mobile Phone Controlled Robot Car Using DTMF Module
  • 2.  Make this 7 Segment Digital Clock with Beep Alert Circuit
  • 3.  Introduction to I2C LCD Adapter Module
  • 4.  Arduino Automatic School/College Bell System
  • 5.  Electronic Voting Machine with SD Card Module
  • 6.  Blinking an LED with Delay – Arduino Basics

About Swagatam

I am an electronics engineer with over 15 years of hands-on experience. I am passionate about inventing, designing electronic circuits and PCBs, and helping hobbyists bring their projects to life. That is why I founded homemade-circuits.com, a website where I share innovative circuit ideas and tutorials. Have a circuit related question? Leave a comment.... I guarantee a reply!

Previous Post: « 0-60V LM317HV Variable Power Supply Circuit Diagram
Next Post: How to Generate Electricity from Piezo »

Reader Interactions

Comments

  1. Ruf Ent says

    September 2, 2016 at 2:45 pm

    I am one the regular follower of your blog and must commend you for a good job.
    please, I am working on a serious project "12vdc to 230vac,
    500w-1000w, transformerless inverter". And among all the wealth of
    circuits on your website, this very design is missing. please help me
    with it,
    it's urgent. I will appreciate it if you reply me soon. please if possible, can you share your direct number…….. please.
    regards.

    Reply
    • Swagatam says

      September 3, 2016 at 3:22 am

      that's impossible, unless huge capacitors and diodes are involved

      Reply

Need Help? Please Leave a Comment! We value your input—Kindly keep it relevant to the above topic! Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Subscribe to New Circuit Ideas

Categories

  • Arduino Projects (87)
  • Audio and Amplifier Projects (132)
  • Automation Projects (17)
  • Automobile Electronics (101)
  • Battery Charger Circuits (82)
  • Datasheets and Components (102)
  • Electronics Theory (143)
  • Free Energy (37)
  • Games and Sports Projects (11)
  • Grid and 3-Phase (19)
  • Health related Projects (25)
  • Home Electrical Circuits (12)
  • Indicator Circuits (14)
  • Inverter Circuits (87)
  • Lamps and Lights (142)
  • Meters and Testers (69)
  • Mini Projects (46)
  • Motor Controller (64)
  • Oscillator Circuits (27)
  • Pets and Pests (15)
  • Power Supply Circuits (108)
  • Remote Control Circuits (50)
  • Security and Alarm (64)
  • Sensors and Detectors (100)
  • Solar Controller Circuits (59)
  • Temperature Controllers (42)
  • Timer and Delay Relay (49)
  • Transmitter Circuits (29)
  • Voltage Control and Protection (37)
  • Water Controller (36)

Calculators

  • Battery Back up Time Calculator
  • Capacitance Reactance Calculator
  • IC 555 Astable Calculator
  • IC 555 Monostable Calculator
  • Inductance Calculator
  • LC Resonance Calculator
  • LM317, LM338, LM396 Calculator
  • Ohm’s Law Calculator
  • Phase Angle Phase Shift Calculator
  • Power Factor (PF) Calculator
  • Reactance Calculator
  • Transistor Astable Calculator
  • Transistor base Resistor Calculator
  • Voltage Divider Calculator
  • Wire Current Calculator
  • Zener Diode Calculator
  • Filter Capacitor Calculator
  • Buck Converter Calculator
  • Boost Converter Calculator
  • Solar Panel, Inverter, Battery Calculator
  • Wire Current Calculator
  • SMPS Transformer Calculator
  • IC SG3525, SG3524 Calculator
  • Inverter LC Filter Calculator

People Also Search

555 Circuits | 741 Circuits | LM324 Circuits | LM338 Circuits | 4017 Circuits | Ultrasonic Projects | SMPS Projects | Christmas Projects | MOSFETs | Radio Circuits | Laser Circuits | PIR Projects |

Recent Comments

  • Swagatam on Simple Delay Timer Circuits Explained
  • Swagatam on The Role of Inductor Coil in SMPS
  • Swagatam on 7 Modified Sine Wave Inverter Circuits Explored – 100W to 3kVA
  • Swagatam on 7 Modified Sine Wave Inverter Circuits Explored – 100W to 3kVA
  • Victor on 7 Modified Sine Wave Inverter Circuits Explored – 100W to 3kVA

Company

  • Privacy Policy
  • Cookie Policy
  • About Me
  • Contact
  • Disclaimer
  • Copyright
  • Videos
  • Sitemap

Social Profiles

  • Twitter
  • YouTube
  • Instagram
  • Pinterest
  • My Facebook-Page
  • Quora
  • Stack Exchange
  • Linkedin
  • © 2025 · Swagatam Innovations