Professional Documents
Culture Documents
3
ARITHMETIC LOGIC UNIT USING ARDUINO and I/O COMPONENTS
OBJECTIVES:
1. To create a circuit which is capable of performing basic arithmetic operations using the
microcontroller Arduino and I/O components
2. To display the result of ALU operations performed by microcontroller
Materials Required:
1. Arduino Uno (Any version will work)
2. 16×2 LCD Display
3. 4×4 Keypad
4. 9V Battery
5. Breadboard and Connecting wires
Circuit Diagram:
PIN CONNECTIONS:
SKETCH
PIns the Keypad is connected using the variable array rowPins and colPins.
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); // Create the
Keypad
Pins of the Arduino the LCD is connected to. According to our circuit diagram the definitions
would be like below
Inside the setup function, display the name of the activity and then proceed to while loop where
the main program lies.
Basically, to check if anything is being typed on the keypad, if typed we have to recognize what
is being typed and then convert it to a variable when the “=” is pressed we have to calculate the
result and then finally display it on the LCD. This is exactly what is done inside
the loop function as shown below
if (key!=NO_KEY)
DetectButtons();
if (result==true)
CalculateResult();
DisplayResult();
FULL SKETCH
/*
*/
char keys[ROWS][COLS] = {
{'7','8','9','D'},
{'4','5','6','C'},
{'1','2','3','B'},
{'*','0','#','A'}
};
byte rowPins[ROWS] = { 0, 1, 2, 3 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to
these Arduino pins.
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); // Create the
Keypad
long Num1,Num2,Number;
char key,action;
void setup() {
void loop() {
if (key!=NO_KEY)
DetectButtons();
if (result==true)
CalculateResult();
DisplayResult();
void DetectButtons()
{
if (Number==0)
Number=1;
else
}
if (Number==0)
Number=4;
else
}
if (Number==0)
Number=7;
else
}
if (key == '0')
if (Number==0)
Number=0;
else
}
if (Number==0)
Number=2;
else
}
if (Number==0)
Number=5;
else
}
if (Number==0)
Number=8;
else
}
if (key == '#')
Num2=Number;
result = true;
}
if (Number==0)
Number=3;
else
}
if (Number==0)
Number=6;
else
}
Number=9;
else
}
if (key == 'A' || key == 'B' || key == 'C' || key == 'D') //Detecting Buttons
on Column 4
{
Num1 = Number;
Number =0;
if (key == 'A')
delay(100);
}
void CalculateResult()
if (action=='+')
Number = Num1+Num2;
if (action=='-')
Number = Num1-Num2;
if (action=='*')
Number = Num1*Num2;
if (action=='/')
Number = Num1/Num2;
void DisplayResult()
if (result==true)
Sample Outputs:
Greetings Animation
Activity Title
Addition
Subtraction
Multiplication
Division
Square
OBSERVATION:
We make a calculator of ALU (Arithmetic Logic Unit) operations using an Arduino Uno,
a 16x2 LCD display, and a 4x4 matrix keypad and we observed that in order to succeed in
building this we need to ensure that we have allocated the necessary pins for connecting the LCD
and keypad to the Arduino Uno. The LCD typically requires 6 digital pins for data and control
but since we used an I2C module we only need 4 pins, while the keypad required 8 pins for
reading the key inputs. We used appropriate libraries for the LCD and keypad to simplify the
programming and handling of input/output operations. Like the "LiquidCrystal" library for the
LCD and the "Keypad" library for the keypad. We made adjustments to the design like removing
the potentiometer since it’s already embedded in I2C and we iterate our code based on what’s
needed to enhance its performance as well as the output on the LCD.
CONCLUSION:
In creating a calculator of ALU operations using an Arduino Uno it would involve
connecting the hardware components correctly and utilizing libraries for easy interfacing. We
need to set up the LCD display, implement keypad scanning to get user input, define and perform
arithmetic and logic operations, handle errors, and display the results on the LCD. It's important
to test the functionality, and fix the code as needed. Additionally, consider breaking down the
overall system into smaller functions or modules to simplify development and debugging.