Arduino Based Calculator using Keypad & LCD:
A simple Arduino Based Calculator using Keypad & LCD for Solving Mathematical Calculations can be easily implemented using Arduino, LCD, and Keypad. A simple mathematical calculation like Addition, Subtraction, Multiplication, and Division can easily do using this project.
A calculator is a machine that allows people to do math operations more easily. For example, most calculators will add, subtract, multiply, and divide.
The 16*2 LCD is capable of solving mathematical problems up to 16 digits without delay and fast processing. Even the Arduino program is easy and is almost like a simple C program, merely based on a simple formula for addition, subtraction, multiplication, and division. So let’s implement this simple Project.
Circuit Diagram and Requirements:
The circuit diagram is so easy as it can be made either by assembling the circuit directly on the Arduino board or by making the assembled circuit in PCB. The requirements for the circuit are as follows.
|
1 2 3 4 5 6 7 8 9 |
1. Arduino Uno Board 2. 16*2 LCD 3. 4*4 Membrane Matrix Keypad 4. 1 kilo ohm resister (2) 5. Reset Switch 6. On/Off Switch 7. 1 kilo ohm Potentiometer 8. 9 volt Battery 10. Bread Board & Connecting Wires |
Program & Source Code:
The programming is done in Arduino language taking Arduino Uno as reference. You need to add an extra Arduino library file for keypad as #include <Keypad.h >. So download this from adafruit library or just update the library file. After assembling, just upload the source code in Arduino Uno board and enjoy your Arduino Based Calculator
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
#include <Keypad.h> #include <LiquidCrystal.h> // 1. LCD Pins LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // 2. Keypad Pins 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] = {A2, A3, A4, A5}; byte colPins[Cols] = {2, 3, 4, 5}; Keypad customKeypad = Keypad(makeKeymap(keys), rowPins, colPins, Rows, Cols); // 3. Dot Button int dot = A0; int dotFlag = 0; int dotButton = 0; // 4. Calculator Operators float num1, num2, fraction; float total; char operation, button; // 5. Loading Setup char input[16]; int n = 1750; void setup() { // Initialize dot button as input to Arduino pinMode(dot, INPUT); // Initialize LCD Size lcd.begin(16, 2); // LCD Loading Setup Begin lcd.clear(); lcd.setCursor(3, 0); lcd.print(“LOADING…”); for (int i = 0; i < 16; i++) { lcd.setCursor(i, 1); lcd.write(255); delay(50); } lcd.clear(); lcd.setCursor(1, 0); lcd.print(“Simple Arduino”); lcd.setCursor(3, 1); lcd.print(“Calculator”); delay(n); lcd.clear(); lcd.setCursor(0, 0); lcd.print(“Designed By”); lcd.setCursor(2, 1); lcd.print(“Alex Newton”); delay(n); lcd.clear(); lcd.setCursor(1, 0); lcd.print(“Alex Newton”); lcd.setCursor(2, 1); lcd.print(“how2electronics.com”); delay(n); lcd.clear(); lcd.setCursor(1, 0); lcd.print(“Alex Newton”); lcd.setCursor(2, 1); lcd.print(“how2electronics.com”); delay(n); lcd.clear(); // LCD Loading Setup End } void loop() { // First while loop for num1. while (1) { dotButton = digitalRead(dot); button = customKeypad.getKey(); if (button == ‘C’) { dotFlag = 0; num1 = 0; num2 = 0; fraction = 0; total = 0; operation = 0; lcd.clear(); } else if (dotButton == LOW) { dotFlag = 1; } else if (button >= ‘0’ && button <= ‘9’) { if (dotFlag == 0) { num1 = num1 * 10 + (button – ‘0’); lcd.setCursor(0, 0); lcd.print(num1); } else if (dotFlag == 1) { fraction = (button – ‘0’); num1 = num1 + (fraction / 10); lcd.setCursor(0, 0); lcd.print(num1); dotFlag++; } else if (dotFlag == 2) { fraction = (button – ‘0’); num1 = num1 + (fraction / 100); lcd.setCursor(0, 0); lcd.print(num1); dotFlag++; } } else if (button == ‘-‘ || button == ‘+’ || button == ‘*’ || button == ‘/’) { operation = button; dotFlag = 0; lcd.setCursor(0, 1); lcd.print(operation); break; } } // Second while loop for num2. while (1) { dotButton = digitalRead(dot); button = customKeypad.getKey(); if (button == ‘C’) { dotFlag = 0; num1 = 0; num2 = 0; fraction = 0; total = 0; operation = 0; lcd.clear(); break; } else if (dotButton == LOW) { dotFlag = 1; } else if (button >= ‘0’ && button <= ‘9’) { if (dotFlag == 0) { num2 = num2 * 10 + (button – ‘0’); lcd.setCursor(1, 1); lcd.print(num2); } else if (dotFlag == 1) { fraction = (button – ‘0’); num2 = num2 + (fraction / 10); lcd.setCursor(1, 1); lcd.print(num2); dotFlag++; } else if (dotFlag == 2) { fraction = (button – ‘0’); num2 = num2 + (fraction / 100); lcd.setCursor(1, 1); lcd.print(num2); dotFlag++; } } if (button == ‘=’) { domath(); break; } } // Third while loop for ensuring C button is executed after while loop 2. while (1) { button = customKeypad.getKey(); if (button == ‘C’) { dotFlag = 0; num1 = 0; num2 = 0; fraction = 0; total = 0; operation = 0; lcd.clear(); break; } } } void domath() { switch (operation) { case ‘+’: total = num1 + num2; break; case ‘-‘: total = num1 – num2; break; case ‘/’: total = num1 / num2; break; case ‘*’: total = num1 * num2; break; } lcd.print(‘=’); if (operation == ‘/’ && num2 == 0) { lcd.print(“ERROR 0 DIV”); } else { lcd.print(total); } } |
Check few Arduino Based Projects Here: Arduino Projects








4 Comments
the pin 15 of the lcd should connect to 5V right? why in the pic the pin 15 is connected to ground?
It should be connected to 5V.
the pin 15 of the lcd should connect to 5V right? why in the schematic diagram the pin 15 of lcd is connected to the ground?
my lcd screen backlight lights up but not displaying the characters, do you know what goes wrong?