Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat menggunakan Arduino fungsinya untuk menyimpan uang atau seperti halnya celengan elektronik, alat ini dikhususkan untuk orang yang ingin menabung dan tabungannya bisa dipantau dan juga terdapat target tabungan sehingga jika saldo belum melebihi target maka uang tidak bisa diambil karena belum memenuhi target, namun jika telah mencapai target maka uang bisa diambil. pengunci alat ini menggunakan motor servo yang diberikan pengait agar bisa mengunci kotak uang. untuk lebih jelasnya berikut adalah skema dan programnya.
a.Arduino Uno
b. Keypad Matrik 4x4
c. Motor Servo
d. LCD 16x2
e. Program Arduino IDE
#include <Keypad.h>
#include <Wire.h>
#include <EEPROM.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'D', 'C', 'B', 'A'},
{'#', '9', '6', '3'},
{'0', '8', '5', '2'},
{'*', '7', '4', '1'}
};
byte rowPins[ROWS] = {2,3,4,5};
byte colPins[COLS] = {6,7,8,9};
int x = 0;
int nilaisetmax = 0;
int nilai;
int saldox;
int tabungan;
int valuesal;
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
Servo myservo1;
Servo myservo2;
void setup()
{
lcd.begin();
lcd.clear();
lcd.noCursor();
myservo1.attach(10);
myservo2.attach(11);
myservo1.write(100);
myservo2.write(100);
}
void loop()
{
customKey = customKeypad.getKey();
if(x == 0){
lcd.setCursor(0,0);
lcd.print("1.SET MAX ");
}
if(x == 1){
lcd.setCursor(0,0);
lcd.print("2.NABUNG ");
}
if(x == 2){
lcd.setCursor(0,0);
lcd.print("3.CEK SALDO ");
}
if(nilaisetmax >= saldox){
//myservo1.write(150);
myservo2.write(150);
}
if(nilaisetmax < saldox){
//myservo1.write(100);
myservo2.write(100);
}
switch(customKey)
{
case '0' ... '9':
break;
case '#':
break;
case '*':
break;
case 'A':
x++;
break;
case 'B':
x--;
break;
case 'C':
break;
case 'D':
if(x == 0){
lcd.clear();
nilai = 0;
setmax();
}
if(x == 1){
lcd.clear();
tabungan = 0;
nabung();
}
if(x == 2){
lcd.clear();
saldo();
}
break;
}
if(x > 2){
x = 0;
}
if(x < 0){
x = 2;
}
}
void setmax(){
lcd.setCursor(0,0);
lcd.print("SET MAX TABUNGAN ");
customKey = customKeypad.getKey();
if(customKey >= '0' && customKey <= '9')
{
nilai = nilai * 10 + (customKey - '0');
lcd.setCursor(0,1);
lcd.print(nilai);
}
if(customKey == '*'){
lcd.clear();
delay(1000);
nilaisetmax = nilai;
x = x + 2;
return;
}
#include <Wire.h>
#include <EEPROM.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'D', 'C', 'B', 'A'},
{'#', '9', '6', '3'},
{'0', '8', '5', '2'},
{'*', '7', '4', '1'}
};
byte rowPins[ROWS] = {2,3,4,5};
byte colPins[COLS] = {6,7,8,9};
int x = 0;
int nilaisetmax = 0;
int nilai;
int saldox;
int tabungan;
int valuesal;
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
Servo myservo1;
Servo myservo2;
void setup()
{
lcd.begin();
lcd.clear();
lcd.noCursor();
myservo1.attach(10);
myservo2.attach(11);
myservo1.write(100);
myservo2.write(100);
}
void loop()
{
customKey = customKeypad.getKey();
if(x == 0){
lcd.setCursor(0,0);
lcd.print("1.SET MAX ");
}
if(x == 1){
lcd.setCursor(0,0);
lcd.print("2.NABUNG ");
}
if(x == 2){
lcd.setCursor(0,0);
lcd.print("3.CEK SALDO ");
}
if(nilaisetmax >= saldox){
//myservo1.write(150);
myservo2.write(150);
}
if(nilaisetmax < saldox){
//myservo1.write(100);
myservo2.write(100);
}
switch(customKey)
{
case '0' ... '9':
break;
case '#':
break;
case '*':
break;
case 'A':
x++;
break;
case 'B':
x--;
break;
case 'C':
break;
case 'D':
if(x == 0){
lcd.clear();
nilai = 0;
setmax();
}
if(x == 1){
lcd.clear();
tabungan = 0;
nabung();
}
if(x == 2){
lcd.clear();
saldo();
}
break;
}
if(x > 2){
x = 0;
}
if(x < 0){
x = 2;
}
}
void setmax(){
lcd.setCursor(0,0);
lcd.print("SET MAX TABUNGAN ");
customKey = customKeypad.getKey();
if(customKey >= '0' && customKey <= '9')
{
nilai = nilai * 10 + (customKey - '0');
lcd.setCursor(0,1);
lcd.print(nilai);
}
if(customKey == '*'){
lcd.clear();
delay(1000);
nilaisetmax = nilai;
x = x + 2;
return;
}
setmax();
}
void nabung(){
lcd.setCursor(0,0);
lcd.print("Nabung Berapa?");
customKey = customKeypad.getKey();
if(customKey >= '0' && customKey <= '9')
{
tabungan = tabungan * 10 + (customKey - '0');
lcd.setCursor(0,1);
lcd.print(tabungan);
}
if(customKey == '*'){
saldox = saldox + tabungan;
lcd.clear();
myservo1.write(150);
//myservo2.write(150);
lcd.setCursor(0,0);
lcd.print("Masukkan Uangnya");
delay(5000);
myservo1.write(100);
//myservo2.write(100);
x++;
lcd.clear();
return;
}
nabung();
}
void saldo(){
lcd.setCursor(0,0);
lcd.print("MAX=");
lcd.print(nilaisetmax);
lcd.setCursor(0,1);
lcd.print("SLD=");
lcd.print(saldox);
customKey = customKeypad.getKey();
if(customKey == '*'){
lcd.clear();
delay(1000);
return;
}
saldo();
}
f. VIDEO HASILNYA