#include <HX711.h> // Library untuk sensor load cell HX711
#include <Keypad.h> // Library untuk keypad
#include <LiquidCrystal_I2C.h> // Library untuk LCD
// Inisialisasi pin sensor load cell
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 4;
// Inisialisasi pin keypad
const byte ROWS = 4; // Jumlah baris pada keypad
const byte COLS = 4; // Jumlah kolom pada keypad
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {10, 9, 8, 7}; // Pin baris keypad terhubung ke pin digital 9, 8, 7, 6
byte colPins[COLS] = {6, 5, 11, 3}; // Pin kolom keypad terhubung ke pin digital 5, 4, 12, 11
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Inisialisasi pin LCD
const int LCD_ADDRESS = 0x27; // Alamat I2C LCD
const int LCD_COLUMNS = 16; // Jumlah kolom pada LCD
const int LCD_ROWS = 2; // Jumlah baris pada LCD
LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_COLUMNS, LCD_ROWS);
// Inisialisasi pin solenoid valve
const int SOLENOID_PIN = 12;
// Konfigurasi nilai kalibrasi
const float CALIBRATION_FACTOR = 150.0; // Sesuaikan dengan nilai kalibrasi load cell
// Inisialisasi objek sensor load cell
HX711 scale;
// Variabel global
float gasPrice = 15000.0; // Harga gas per kilogram
float gasWeight = 0.0; // Berat gas yang diisi
void setup() {
Serial.begin(9600); // Inisialisasi komunikasi serial
lcd.begin(LCD_COLUMNS, LCD_ROWS); // Inisialisasi LCD
lcd.print("Pengisian LPG"); // Tampilkan pesan awal di LCD
delay(2000);
lcd.clear();
scale.begin(2, 4); // Mulai sensor load cell
scale.set_scale(CALIBRATION_FACTOR); // Set faktor kalibrasi
scale.tare(); // Lakukan tare pada timbangan (set nilai awal menjadi 0)
pinMode(12, OUTPUT); // Atur pin solenoid valve sebagai OUTPUT
digitalWrite(12, LOW); // Matikan solenoid valve awal
}
void loop() {
char key = keypad.getKey(); // Membaca tombol yang ditekan pada keypad
if (key != NO_KEY) {
// Jika tombol yang ditekan adalah tombol angka (0-9)
if (isdigit(key)) {
Serial.print("Angka: ");
Serial.println(key);
lcd.setCursor(0, 0);
lcd.print("Angka: ");
lcd.print(key);
}
// Jika tombol yang ditekan adalah tombol A (contoh)
else if (key == 'A') {
float weight = scale.get_units(); // Baca nilai berat dari sensor
// Tampilkan nilai berat pada Serial Monitor
Serial.print("Berat: ");
Serial.print(weight);
Serial.println(" kg");
float gasKg = weight / 100.0; // Konversi berat ke kilogram
lcd.setCursor(0, 1);
lcd.print("Berat: ");
lcd.print(gasKg, 2);
lcd.print(" Kg");
// Hitung harga total gas
float totalPrice = gasKg * gasPrice;
lcd.setCursor(0, 0);
lcd.print("Harga: Rp ");
lcd.print(totalPrice, 2);
// Aktifkan solenoid valve untuk mengisi gas
digitalWrite(12, HIGH);
delay(2000); // Waktu pengisian gas (2 detik)
digitalWrite(12, LOW);
}
// Tambahkan logika untuk tombol lain sesuai kebutuhan Anda
}
// Tambahkan logika tambahan untuk pengisian gas jika diperlukan
}