Delivery throughout Europe

Ordered before 16:00 = Shipped today

Fast delivery with DHL

XNUMX days return *


Country

In this fun project you will learn how to make your own Arduino calculator can make.

You can use this calculator for simple calculations. These are plus, minus, times or divided by. So don't expect to be able to solve equations with it.

We do this using a 4X4 keypad and a 16X2 LCD screen. We connect the screen via I2C, so keep in mind that you need extra libraries. For the keypad you have to import the keypad library, more information about this can be found in the piezo piano project. For the I2C libraries you will find the information in the I2C LCD project.

  • Level - Medium 40% 40%
  • Duration - 20/25 Min 25% 25%
  • Costs - € 42.80 euros complete 40% 40%

Step 1: Requirements

1X Arduino UNO

12X Jumper wires

1X 4X4 Keypad

1X 16X2 LCD

Step 2: Building and Wiring

Now you are going to wire the Arduino calculator. We start with the screen. At the display we first connect the GND of the display to the GND of the Arduino, the VCC to the 5V of the Arduino, finally the SDA to A4 and SCL to A5. You connect the keypad in exactly the same way as can be seen on the fritzing. That means that if the buttons assign to you that the leftmost pin must go to I / O pin 4, the pin to the right of it goes to I / O pin 5, then the pin that is to the right of this pin to I / O pin 6. and the pin to the right of this to I / O pin 7. Repeat this for the other four pins only on I / O pins ot / m 3. This means again from left to right. It is important to note that if the keypad is not working properly, most likely a jumper wire is incorrectly connected. Once that is done, you have connected everything for your calculator.

Step 3: Programming

 

Now that you are programming, keep in mind that you need the Wire, Keypad and LiquidCrystal_I2C libraries.

During programming we define the * and the # as other symbols. The * is the clear function so C and the # is it is sign and is thus defined as =.

As soon as all the code is on it and you look at your Arduino, the screen first shows “electronics for your calculator”. Then the screen goes blank and you can start making calculations.

In case you already press the C sign before you have calculated a sum and you want to continue calculating, you will notice that it does not work. It is important that you first press the = sign if you do not do this because it does not work.

// the libraries we need

#include

#include

#include

// keypad definitions

const byte ROWS = 4;

const byte COLS = 4;

char keys [ROWS] [COLS] = {

  {'1', '2', '3', '+'},

  {'4', '5', '6', '-'},

  {'7', '8', '9', '*'},

  {'C', '0', '=', '/'}

};

byte rowPins [ROWS] = {0, 1, 2, 3};

byte colPins [COLS] = {4, 5, 6, 7};

 

Keypad ourKeypad = Keypad (makeKeymap (keys), rowPins, colPins, ROWS, COLS);

// initialize lcd

LiquidCrystal_I2C lcd (0x3F, 20,4);

 

// say here what these values ​​are

boolean firstNumState = true;

String firstNum = “”;

String secondNum = “”;

float answer = 0.0;

char oper = '';

 

void setup () {

  // here we turn on the screen

  lcd.begin (16,2);

  lcd.init ();

  lcd.init ();

  lcd.backlight ();

  lcd.setCursor (0,0);

  lcd.print (“Electronics”);

  lcd.setCursor (0,1);

  lcd.print (“For You”);

  delay (1500);

  lcd.clear ();

  lcd.setCursor (0,0);

  lcd.print (“calculator”);

  delay (1500);

  lcd.clear ();

}

void loop () {

  char newKey = ourKeypad.getKey ();

  // what to do when he gets a number

  if (newKey! = NO_KEY && (newKey == '1' || newKey == '2' || newKey == '3' || newKey == '4' || newKey == '5' || newKey = = '6' || newKey == '7' || newKey == '8' || newKey == '9' || newKey == '0 ′)) {

    if (firstNumState == true) {

      firstNum = firstNum + newKey;

      lcd.print (newKey);

    Else {}

      secondNum = secondNum + newKey;

      lcd.print (newKey);

    }

  }

  // what to do if he gets an operator

  if (newKey! = NO_KEY && (newKey == '+' || newKey == '-' || newKey == '*' || newKey == '/')) {

    if (firstNumState == true) {

      oper = newKey;

      firstNumState = false;

      lcd.print (oper);

    }

  }

  // here we say what happens when you

  // press #

  if (newKey! = NO_KEY && newKey == '=') {

    // what to do as your operator

    // + is

    if (oper == '+') {

      antw = firstNum.toFloat () + secondNum.toFloat ();

    }

    // what to do as your operator

    // - is

    if (oper == '-') {

      antw = firstNum.toFloat () - secondNum.toFloat ();

    }

    // what to do as your operator

    // * is

    if (oper == '*') {

      antw = firstNum.toFloat () * secondNum.toFloat ();

    }

    // what to do as your operator

    // divided by is

    if (oper == '/') {

      antw = firstNum.toFloat () / secondNum.toFloat ();

    }

    lcd.setCursor (0,0);

    lcd.print (firstNum);

    lcd.print (oper);

    lcd.print (secondNum);

    lcd.setCursor (0,1);

    lcd.print (“=”);

    lcd.print (antw);

    firstNumState = true;

  }

  if (newKey! = NO_KEY && newKey == 'C') {

    // here we say what happens when you

    // press *

    lcd.clear ();

    lcd.setCursor (0,0);

    firstNum = “”;

    secondNum = “”;

    answer = 0;

    oper = '';

  }

}

 

The rating of www.elektronicavoorjou.nl at WebwinkelKeur Reviews is 9.3/10 based on 4782 reviews.