Tekko BDSimSimulatorProjects

৪x৪ কিপ্যাড দিয়ে ক্যালকুলেটর (LCD তে ফলাফল)Arduino Calculator with a 4x4 Keypad and LCD

Keypad library রো আর কলাম স্ক্যান করে কোন বাটন চাপা হলো ধরে। Sketch টা অঙ্ক জমায়, একটা operator (+ - / x) নেয়, = চাপলে হিসাব করে I2C LCD তে ফলাফল দেখায়। C চাপলে মোছা হয়।

The Keypad library scans rows and columns to catch each key. The sketch collects digits, takes one operator (+ - / x), then on = it works out the result and prints it on the I2C LCD. C clears.

▶ ফ্রি চালিয়ে দেখো / Run it free Parts অর্ডার করো (WhatsApp)

সার্কিট ডায়াগ্রাম · Circuit diagram

Arduino Calculator with a 4x4 Keypad and LCD circuit diagram — Arduino Uno, Keypad 4x4, LCD 16x2 with I2C, Jumper wires

যা যা লাগবে · Parts you need

তার লাগানো · Wiring

Keypad 4x4 R1→Arduino Uno D9
Keypad 4x4 R2→Arduino Uno D8
Keypad 4x4 R3→Arduino Uno D7
Keypad 4x4 R4→Arduino Uno D6
Keypad 4x4 C1→Arduino Uno D5
Keypad 4x4 C2→Arduino Uno D4
Keypad 4x4 C3→Arduino Uno D3
Keypad 4x4 C4→Arduino Uno D2
LCD 16x2 with I2C VCC→Arduino Uno 5V
LCD 16x2 with I2C GND→Arduino Uno GND
LCD 16x2 with I2C SDA→Arduino Uno A4
LCD 16x2 with I2C SCL→Arduino Uno A5

Code (Arduino C++)

#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// A working four-function calculator: type a number, an operator (+ - x /),
// another number, then '='. The LCD shows the answer. C clears.
// Tap the keys on the keypad part to use it.
LiquidCrystal_I2C lcd(0x27, 16, 2);
char keys[4][4] = { {'1','2','3','+'}, {'4','5','6','-'}, {'7','8','9','C'}, {'=','0','.','/'} };
byte rowPins[4] = {9, 8, 7, 6};
byte colPins[4] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, 4, 4);

String entry = "";
char op = 0;
float a = 0;

void show() {
  lcd.setCursor(0, 0); lcd.print(entry + (op ? String(op) : " ") + "      ");
}

void setup() {
  lcd.init();
  lcd.backlight();
  Serial.begin(9600);
  Serial.println("Calc: 12+34= or 7x8=");
}

void loop() {
  char k = keypad.getKey();
  if (!k) return;
  Serial.print(k);
  if (k >= '0' && k <= '9') { entry += k; show(); }
  else if (k == 'C') { entry = ""; op = 0; a = 0; lcd.clear(); }
  else if (k == '=') {
    if (op && entry.length()) {
      float b = entry.toInt();
      float r = op == '+' ? a + b : op == '-' ? a - b : op == '/' ? (b != 0 ? a / b : 0) : a * b;
      lcd.setCursor(0, 1);
      lcd.print("= "); lcd.print(r, 2); lcd.print("      ");
      Serial.print(" = "); Serial.println(r, 2);
      entry = ""; op = 0;
    }
  }
  else { a = entry.toInt(); op = k; entry = ""; show(); }
}

আরো project · More projects