Tahu ga sih fungsi lain dari keypad selain untuk texting?
Jadi, ternyata Keypad dapat digunakan untuk membuat kalkulator loh Fanbot. Keypad yang digabungkan dengan lcd dapat dibuat menjadi kalkulator yang hasil perhitungannya ditampilkan pada layar LCD, sehingga akan lebih mudah untuk mengetahui kalkulator bekerja atau tidak.
[membership level=”0,1,2.4″]
1. Alat / Bahan
- Arduino IDE
https://www.arduino.cc/en/Main/Software - Library I2C LCD
https://www.dropbox.com/s/jt621pjfjw2xfqr/LiquidCrystal_I2C-1.1.2.zip?dl=0 - Library Keypad
https://www.dropbox.com/s/zn6b8ebvw2smife/Keypad.zip?dl=0 - Arduino Uno 1 Buah
- Keypad 1 Buah
- I2C 1 Buah
- LCD 1 Buah
Untuk mendapatkan komponen elektronik di atas silahkan temukan di sini.
Baca Juga : Penerapan Langsung Lampu Otomatis saat Ada Manusia dengan Sensor PIR
2. Skema Rangkaian

Gambar Rangkaian Kalkulator Arduino dengan Keypad 4×4
Keterangan:
- 5V – VCC I2C
- GND – GND I2C
- SDA – SDA I2C
- SCL – SCL I2C
- D2 – Pin 1 keypad
- D3 – Pin 2 keypad
- D4 – Pin 3 keypad
- D5 – Pin 4 keypad
- D6 – Pin 5 keypad
- D7 – Pin 6 keypad
- D8 – Pin 7 keypad
[/membership]
3. Langkah Kerja
- Pertama Siapkan alat dan bahan yang akan digunakan
- Kedua Lakukan proses wiring dengan menggunakan Gambar skematik rangkaian diatas
- Ketiga Buka software Arduino IDE yang telah terinstal pada laptop/komputer
- Kemudian Unduh semua library di atas dan masukkan libray tersebut dengan cara buka Arduino IDE pilih Sketch->Include Library->Add.Zip Library
- Selanjutnya Ketikkan sketch program pada halaman Arduino IDE
- Setelah itu Masukan alamat I2C LCD pada sketch program, untuk mengetahui alamat I2C pelajari materi berikut : https://premium.indobot.co.id/mencari-tahu-alamat-i2c-pada-modul-i2c/
- Segera Lakukan proses uploading program
4. Sketch Program
Dapatkan segera akses ratusan video tutorial dan pembelajaran dengan registrasi melalui tombol di bawah!
/* Program Kalkulator Arduino dengan Keypad 4x4 dibuat oleh Indobot */
#include <Keypad.h> //Library keypad
#include <LiquidCrystal_I2C.h> //Library LCD I2C
LiquidCrystal_I2C lcd(0x27,16,2); //Masukkan type dan alamat I2C
const byte ROWS = 4; //Inisialisasi jumlah baris
const byte COLS = 4; //Inisialisasi jumlah kolom
char Keys[ROWS][COLS] = { //Map tombol keypad
{'1','2','3','+'},
{'4','5','6','-'},
{'7','8','9','*'},
{'C','0','=','/'}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; //Deklarasi pin baris
byte colPins[COLS] = {6, 7, 8, 9}; //Deklarasi pin kolom
Keypad customKeypad = Keypad( makeKeymap(Keys), rowPins, colPins, ROWS, COLS); //input parameter keypad
char customKey; //Variabel untuk menampung input keypad
long first = 0; //Variabel angka pertama
long second = 0; //Variabel angka kedua
double total = 0; //Variabel total
void setup() {
lcd.init (); //Mulai LCD
lcd.setBacklight(HIGH); //Set backlight HIGH
}
void loop() {
customKey = customKeypad.getKey(); //Baca input keypad
switch(customKey){ //Jika
case '0' ... '9': //Nilai 0 - 9, maka
lcd.setCursor(0,0);
first = first * 10 + (customKey - '0');
lcd.print(first); //Tampilkan angka
break;
case '+': //Jika input +, maka
first = (total != 0 ? total : first); //Jalankan prosedur penjumlahan
lcd.setCursor(3,0);
lcd.print("+");
second = SecondNumber();
total = first + second;
lcd.setCursor(0,1);
lcd.print(total);
first = 0, second = 0;
break;
case '-': //Jika input -, maka
first = (total != 0 ? total : first); //Jalankan prosedur pengurangan
lcd.setCursor(3,0);
lcd.print("-");
second = SecondNumber();
total = first - second;
lcd.setCursor(0,1);
lcd.print(total);
first = 0, second = 0;
break;
case '*': //Jika input *, maka
first = (total != 0 ? total : first); //Jalankan prosedur perkalian
lcd.setCursor(3,0);
lcd.print("*");
second = SecondNumber();
total = first * second;
lcd.setCursor(0,1);
lcd.print(total);
first = 0, second = 0;
break;
case '/': //Jika input /, maka
first = (total != 0 ? total : first); //Jalankan prosedur pembagian
lcd.setCursor(3,0);
lcd.print("/");
second = SecondNumber();
lcd.setCursor(0,1);
second == 0 ? lcd.print("Invalid") : total = (float)first / (float)second; //Jika nilai angka ke-2 0, maka tampilkan "Invalid"
second != 0 ? lcd.print(total):
first = 0, second = 0;
break;
case 'C': //Jika input C, maka
total = 0; //Hapus semua angka dan reset tampilan
first = 0, second = 0;
lcd.clear();
break;
}
}
long SecondNumber() //Prosedur penampilan angka ke-2
{
while( 1 )
{
customKey = customKeypad.getKey();
if(customKey &amp;amp;gt;= '0' &amp;amp;amp;&amp;amp;amp; customKey &amp;amp;lt;= '9')
{
second = second * 10 + (customKey - '0');
lcd.setCursor(5,0);
lcd.print(second);
}
if(customKey == '=') break; //return second;
}
return second;
}
Baca Juga : Palang Pintu Otomatis Arduino Uno
Kesimpulan:
Program bekerja dengan mendeteksi tombol keypad yang di tekan dan melakukan perhitungan sesuai perintah.







Warning: Undefined variable $req in /www/wwwroot/blog.indobot.co.id/wp-content/themes/generatepress/functions.php on line 162
Warning: Undefined variable $commenter in /www/wwwroot/blog.indobot.co.id/wp-content/themes/generatepress/functions.php on line 163
Warning: Trying to access array offset on value of type null in /www/wwwroot/blog.indobot.co.id/wp-content/themes/generatepress/functions.php on line 163
Warning: Undefined variable $aria_req in /www/wwwroot/blog.indobot.co.id/wp-content/themes/generatepress/functions.php on line 163
Warning: Undefined variable $req in /www/wwwroot/blog.indobot.co.id/wp-content/themes/generatepress/functions.php on line 167
Warning: Undefined variable $commenter in /www/wwwroot/blog.indobot.co.id/wp-content/themes/generatepress/functions.php on line 168
Warning: Trying to access array offset on value of type null in /www/wwwroot/blog.indobot.co.id/wp-content/themes/generatepress/functions.php on line 168
Warning: Undefined variable $aria_req in /www/wwwroot/blog.indobot.co.id/wp-content/themes/generatepress/functions.php on line 169