৪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.
সার্কিট ডায়াগ্রাম · Circuit diagram
যা যা লাগবে · Parts you need
- 1 × Arduino Uno Arduino Uno
- 1 × Keypad 4x4 কিপ্যাড ৪x৪
- 1 × LCD 16x2 with I2C LCD ১৬x২ (I2C)
- 12 × Jumper wires জাম্পার তার
তার লাগানো · 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
- ESP32 MQTT সেন্সর নোড (তাপমাত্রা publish করে)ESP32 MQTT sensor node (publishes temperature)
- দুই জয়স্টিকে চলা ৪-DOF রোবোটিক আর্ম4-DOF robotic arm controlled by two joysticks
- ওজন মাপার স্কেল: লোড সেল + HX711 (tare ও গ্রাম)Weight scale: load cell + HX711 (tare and grams)
- MPU6050 টিল্ট কন্ট্রোলার (৪টা LED দিক দেখায়)MPU6050 tilt controller (4 LEDs show the direction)