IR Calculator without any calculator bugs
A simple calculator that you can control with your remote with no bugs.
Components and supplies
1
Standard LCD - 16x2 White on Blue
1
Resistor 220 ohm
1
IR receiver (generic)
2
Resistor 1k ohm
1
Arduino UNO
Project description
Code
IR Calculator with no bugs
IR Calculator with no bugs
arduino
1/* 2This is an IR Remote Controlled Calculator. 3I have tried to get 4 rid of all the bugs that I have seen 5in other calculators made using an arduino. 6 This calculator 7can be used like a normal calculator, you can make 8simultaneous 9 calculations with this, add points, etc. 10The LCD Display used here is a RG1602A, 11you 12 may refer to this article to understand how to use the display, 13https://create.arduino.cc/projecthub/najad/interfacing-lcd1602-with-arduino-764ec4 14All 15 you need to do is connect the wires in the corresponding 16pins written down below 17 and edit the IR Codes: 18|------#------Arduino Pins------LCD RG1602A--------------------| 19|----- 20 1 ---- GND ----- VSS,V0 (With 2K ohm),RW,K -----| 21|----- 2 ---- 5V 22 ----- VDD, A (With 220 ohm) -----| 23|----- 3 ---- 12 ----- 24 RS -----| 25|----- 4 ---- 11 ----- E -----| 26|----- 27 5 ---- 5 ----- D4 -----| 28|----- 6 ---- 4 29 ----- D5 -----| 30|----- 7 ---- 3 ----- D6 -----| 31|----- 32 8 ---- 2 ----- D7 -----| 33|--------------------------------------------------------------| 34|------#------Arduino 35 Pins------IR Transmitter-----------------| 36|----- 1 ---- 10 ----- Out 37 -----| 38|----- 2 ---- GND ----- GND -----| 39|----- 40 3 ---- 5V ----- Power -----| 41|--------------------------------------------------------------| 42Check 43 it out on Github: https://github.com/Jaagrav/IRcalculator/ 44*/ 45 46#include 47 <IRremote.h> 48#include <LiquidCrystal.h> 49#include <math.h> 50 51// Digital 52 Pin Connections to your LCD 53const int 54 rs = 12, 55 en = 11, 56 d4 57 = 5, 58 d5 = 4, 59 d6 = 3, 60 d7 = 2; 61 62LiquidCrystal lcd(rs, en, 63 d4, d5, d6, d7); 64 65// Digital Pin Connection to your IR Receiver 66IRrecv 67 irrecv(10); 68decode_results results; 69 70String 71 number1 = "0", 72 73 number2 = "0", 74 optr = "=", 75 sixteenString = " "; 76 77void 78 setup() { 79 Serial.begin(9600); 80 81 lcd.begin(16, 2); 82 irrecv.enableIRIn(); 83} 84 85void 86 loop() { 87 if (irrecv.decode(&results)) { 88 unsigned int result = results.value; 89 90 String val = String(result); 91 acceptInput(val.toInt()); 92 irrecv.resume(); 93 94 } 95 lcd.setCursor(0,0); 96 lcd.print(optr + " " + sixteenString.substring(number1.length() 97 + 3) + number1); 98 lcd.setCursor(0,1); 99 lcd.print(sixteenString.substring(number2.length()) 100 + number2); 101} 102 103void calculate(String op) { 104 double no1 = number1.toDouble(); 105 106 double no2 = number2.toDouble(); 107 double calcVal = 0.0; 108 109 if(optr 110 == "+") 111 calcVal = (no1 + no2); 112 else if(optr == "-") 113 calcVal 114 = (no1 - no2); 115 else if(optr == "x") 116 calcVal = (no1 * no2); 117 else 118 if(optr == "/") 119 calcVal = (no1 / no2); 120 121 number1 = toString(calcVal); 122 123 number2 = "0"; 124 optr = op; 125} 126 127String toString(double num) { 128 129 return String(num); 130} 131 132void function(String e) { 133 if(number1 != 134 "0" && number2 != "0") { 135 calculate(e); 136 } 137 else if(number1 == 138 "0") { 139 number1 = number2; 140 number2 = "0"; 141 } 142 optr = 143 e; 144} 145 146void concatNumbers(String num) { 147 if(optr == "=") 148 number1 149 = "0"; 150 if(num != "."){ 151 if(number2.length() == 1 && number2 == "0") 152 153 number2 = num; 154 else 155 number2 += num; 156 } 157 else 158 { 159 if(number2.charAt(number2.length()-1) != '.' && number2.indexOf('.') == 160 -1) 161 number2 += num; 162 } 163} 164 165void backSpace() { 166 number2 167 = number2.substring(0, number2.length() - 1); 168 if(number2 == "") 169 number2 170 = "0"; 171} 172 173/* 174In the below switch-case replace the numbers with the 175 IR codes 176from your remote. Make sure you write the code that gets printed 177in 178 your serial monitor from line 142. 179*/ 180 181void acceptInput(int character) 182 { 183 Serial.println(character); 184 switch(character) { 185 case 2222: 186 187 concatNumbers("1"); 188 break; 189 case -31092: 190 concatNumbers("2"); 191 192 break; 193 case 18888: 194 concatNumbers("3"); 195 break; 196 case 197 10000: 198 concatNumbers("4"); 199 break; 200 case -22203: 201 concatNumbers("5"); 202 203 break; 204 case 26666: 205 concatNumbers("6"); 206 break; 207 case 208 6333: 209 concatNumbers("7"); 210 break; 211 case -25537: 212 concatNumbers("8"); 213 214 break; 215 case 22222: 216 concatNumbers("9"); 217 break; 218 case 219 12222: 220 concatNumbers("0"); 221 break; 222 case 28888: 223 concatNumbers("."); 224 225 break; 226 case 255: 227 number1 = "0"; 228 number2 = "0"; 229 230 optr = "="; 231 break; 232 case 32222: 233 function("+"); 234 235 break; 236 case -28870: 237 function("-"); 238 break; 239 case 240 24444: 241 function("/"); 242 break; 243 case 8444: 244 function("x"); 245 246 break; 247 case 45555: 248 if(optr != "=") 249 calculate("="); 250 251 break; 252 case 4333: 253 backSpace(); 254 break; 255 default: 256 257 Serial.println("Invalid Input"); 258 } 259}
IR Calculator with no bugs
Downloadable files
Circuit Diagram for Calculator
Circuit Diagram for Calculator

Circuit Diagram for Calculator
Circuit Diagram for Calculator

Comments
Only logged in users can leave comments