0% found this document useful (0 votes)
6 views5 pages

Arduino Calculator Project

The document outlines a project to create a functional calculator using Arduino, a 4x4 keypad, and a 16x2 I2C LCD display. It includes a list of required components, detailed connection procedures, and the Arduino code necessary for operation. The completed calculator can perform basic arithmetic operations and displays results on the LCD screen.

Uploaded by

s6satya7119
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Arduino Calculator Project

The document outlines a project to create a functional calculator using Arduino, a 4x4 keypad, and a 16x2 I2C LCD display. It includes a list of required components, detailed connection procedures, and the Arduino code necessary for operation. The completed calculator can perform basic arithmetic operations and displays results on the LCD screen.

Uploaded by

s6satya7119
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Arduino Calculator Project

Aim

To design and implement a functional calculator using Arduino, a 4x4 keypad, and a 16x2 I2C
LCD display.

Apparatus

• Arduino Uno / Nano

• 4x4 Keypad

• 16x2 LCD Display with I2C module

• Jumper wires (Male-to-Male)

• Breadboard

• USB cable for Arduino

• Computer with Arduino IDE installed

Procedure

1. Connect the keypad pins to the Arduino as per pin mapping:

o Row pins → D7, D6, D5, D4

o Column pins → D3, D2, D1, D0

2. Connect the I2C LCD:

o VCC → 5V

o GND → GND

o SDA → A4

o SCL → A5

3. Install required libraries in Arduino IDE:

o Keypad

o hd44780 (by Bill Perry)

4. Upload the calculator code to the Arduino.

5. Power the Arduino and test the keypad by pressing numbers and operations.

6. The LCD will display the entered numbers, operator, and the calculated result.
Circuit Diagram

Code

#include <Keypad.h>

#include <Wire.h>

#include <hd44780.h>

#include <hd44780ioClass/hd44780_I2Cexp.h>

hd44780_I2Cexp lcd;

const int LCD_COLS = 16;

const int LCD_ROWS = 2;

String num1 = "";

String num2 = "";

char operation = 0;

bool opSelected = false;

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] = {7, 6, 5, 4};

byte colPins[COLS] = {3, 2, 1, 0};

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

void setup() {

int status = [Link](LCD_COLS, LCD_ROWS);

if (status) hd44780::fatalError(status);

[Link]("Calculator Ready");

delay(1000);

[Link]();

void loop() {

char key = [Link]();

if (key) {

[Link]();

if (key == 'C') {
num1 = "";

num2 = "";

operation = 0;

opSelected = false;

[Link]("Cleared");

delay(300);

[Link]();

return;

if (!opSelected && (key=='+' || key=='-' || key=='*' || key=='/')) {

if ([Link]() == 0) return;

operation = key;

opSelected = true;

[Link](num1);

[Link](operation);

return;

if (key == '=') {

if ([Link]() == 0 || [Link]() == 0) return;

double a = [Link]();

double b = [Link]();

double result = 0;

switch(operation) {

case '+': result = a + b; break;

case '-': result = a - b; break;

case '*': result = a * b; break;


case '/': if (b == 0) { [Link]("Error: Div0"); return; } result = a / b; break;

[Link]("Result=");

[Link](0,1);

[Link](result);

num1 = String(result);

num2 = "";

opSelected = false;

return;

if (key >= '0' && key <= '9') {

if (!opSelected) num1 += key;

else num2 += key;

[Link](num1);

if (opSelected) {

[Link](operation);

[Link](num2);

Result

The Arduino calculator successfully takes input from a 4x4 keypad and displays the input,
operator, and final calculated result on a 16x2 LCD screen. The calculator performs addition,
subtraction, multiplication, and division operations accurately.

You might also like