+91-7834999925       contact@tacthub.in

Arduino Calculator

We can develop a calculator at home using arduino, display and a keypad.

Hardware Required

  • Arduino Uno
  • 16×2 LCD Display
  • 4×4 Keypad
  • 9V Battery
  • Breadboard and Connectingwires

 

Software Required

 

  • Arduino IDE


Connections

 

  • D0 to 1st pin of the keyboard
  • D1 to 2nd pin of the keyboard
  • D2 to 3rd pin of the keyboard
  • D3 to 4th pin of the keyboard
  • D4 to 5th pin of the keyboard
  • D5 to 6th pin of the keyboard
  • D6 to 7th pin of the keyboard
  • D7 to 8th pin of the keyboard
  • D8 to Register select pin of LCD (pin 4)
  • D9 to Enable pin of LCD (pin 6)
  • D10 to Data pin 4 of LCD (pin 11)
  • D11 to Data pin 3 of LCD (pin 12)
  • D12 to Data pin 2 of LCD (pin 13)
  • D13 to Data pin 4 of LCD (pin 14)
  • +5V Connected to Vdd pin of LCD (pin 2)
  • Groundto Vss, Vee and RW pin of LCD (pin 1, 3 and 5)

voidsetup() {

  lcd.begin(16, 2); //16*2 LCD display

  lcd.print("Calculator"); //intro message

  lcd.setCursor(0, 1);

   delay(2000);

    lcd.clear(); //clear message

}

 

voidloop() {

 

key=kpd.getKey(); //storing pressed key value in a char

 

if(key!=NO_KEY)

DetectButtons();

 

if(result==true)

CalculateResult();

 

DisplayResult();  

}

 

voidDetectButtons()

{

     lcd.clear(); //Then clean it

    if(key=='*') //If cancel Button is pressed

    {Serial.println("Button Cancel"); Number=Num1=Num2=0; result=false;}

   

     if(key=='1') //If Button 1 is pressed

    {Serial.println("Button 1");

    if(Number==0)

    Number=1;

    else

    Number=(Number*10) +1; //Pressed twice

    }

   

     if(key=='4') //If Button 4 is pressed

    {Serial.println("Button 4");

    if(Number==0)

    Number=4;

    else

    Number=(Number*10) +4; //Pressed twice

    }

   

     if(key=='7') //If Button 7 is pressed

    {Serial.println("Button 7");

    if(Number==0)

    Number=7;

    else

    Number=(Number*10) +7; //Pressed twice

    }

 

 

    if(key=='0')

    {Serial.println("Button 0"); //Button 0 is Pressed

    if(Number==0)

    Number=0;

    else

    Number=(Number*10) +0; //Pressed twice

    }

   

     if(key=='2') //Button 2 is Pressed

    {Serial.println("Button 2");

     if(Number==0)

    Number=2;

    else

    Number=(Number*10) +2; //Pressed twice

    }

   

     if(key=='5')

    {Serial.println("Button 5");

     if(Number==0)

    Number=5;

    else

    Number=(Number*10) +5; //Pressed twice

    }

   

     if(key=='8')

    {Serial.println("Button 8");

     if(Number==0)

    Number=8;

    else

    Number=(Number*10) +8; //Pressed twice

    }  

 

 

    if(key=='#')

    {Serial.println("Button Equal");

    Num2=Number;

    result=true;

    }

   

     if(key=='3')

    {Serial.println("Button 3");

     if(Number==0)

    Number=3;

    else

    Number=(Number*10) +3; //Pressed twice

    }

   

     if(key=='6')

    {Serial.println("Button 6");

    if(Number==0)

    Number=6;

    else

    Number=(Number*10) +6; //Pressed twice

    }

   

     if(key=='9')

    {Serial.println("Button 9");

    if(Number==0)

    Number=9;

    else

    Number=(Number*10) +9; //Pressed twice

    } 

 

      if(key=='A'||key=='B'||key=='C'||key=='D') //Detecting Buttons on Column 4

  {

    Num1=Number;   

    Number=0;

    if(key=='A')

    {Serial.println("Addition"); action='+';}

     if(key=='B')

    {Serial.println("Subtraction"); action='-'; }

     if(key=='C')

    {Serial.println("Multiplication"); action='*';}

     if(key=='D')

    {Serial.println("Devesion"); action='/';} 

 

    delay(100);

  }

 

}

 

voidCalculateResult()

{

  if(action=='+')

    Number=Num1+Num2;

 

  if(action=='-')

    Number=Num1-Num2;

 

  if(action=='*')

    Number=Num1*Num2;

 

  if(action=='/')

    Number=Num1/Num2;

}

 

voidDisplayResult()

{

  lcd.setCursor(0, 0);   // set the cursor to column 0, line 1

  lcd.print(Num1); lcd.print(action); lcd.print(Num2);

 

  if(result==true)

  {lcd.print(" ="); lcd.print(Number);} //Display the result

 

  lcd.setCursor(0, 1);   // set the cursor to column 0, line 1

  lcd.print(Number); //Display the result

}

Price: 7000 INR

Buy Now