#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
Servo servoPintu;
Servo servoJamu1;
Servo servoJamu2;
Servo servoJamu3;
Servo servoJamu4;
Servo servoJamu5;
Servo servoJamu6;
Servo servoPengaduk;
int pos = 90;
LiquidCrystal_I2C lcd(0x27, 20, 4);
const int buzzerPin = 3;
const int proximitySensorPin = 2;
const int hotWaterPumpPin = 38;
const int coldWaterPumpPin = 40;
const int WaterPumpPin = 42;
const int MotorPegaduk = 22;
const int MotorJamu1 = 24;
const int MotorJamu2 = 26;
const int MotorJamu3 = 28;
const int MotorJamu4 = 30;
const int MotorJamu5 = 32;
const int MotorJamu6 = 34;
const int LedRGB = 36;
// Definisi pin untuk tombol-tombol
const int buttonPin1 = 23;
const int buttonPin2 = 25;
const int buttonPin3 = 27;
const int buttonPin4 = 29;
const int buttonPin5 = 31;
const int buttonPin6 = 33;
const int buttonPinAir1 = 35;
const int buttonPinAir2 = 37;
const int buttonPinAir3 = 39;
void setup() {
servoPintu.attach(4);
servoJamu1.attach(5);
servoJamu2.attach(6);
servoJamu3.attach(7);
servoJamu4.attach(8);
servoJamu5.attach(9);
servoJamu6.attach(10);
servoPengaduk.attach(11);
pinMode(buzzerPin, OUTPUT);
pinMode(proximitySensorPin, INPUT);
pinMode(hotWaterPumpPin, OUTPUT);
pinMode(coldWaterPumpPin, OUTPUT);
pinMode(MotorPegaduk, OUTPUT);
pinMode(MotorJamu1, OUTPUT);
pinMode(MotorJamu2, OUTPUT);
pinMode(MotorJamu3, OUTPUT);
pinMode(MotorJamu4, OUTPUT);
pinMode(MotorJamu5, OUTPUT);
pinMode(MotorJamu6, OUTPUT);
pinMode(LedRGB, OUTPUT);
// Set pin tombol sebagai input
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(buttonPin4, INPUT_PULLUP);
pinMode(buttonPin5, INPUT_PULLUP);
pinMode(buttonPin6, INPUT_PULLUP);
pinMode(buttonPinAir1, INPUT_PULLUP);
pinMode(buttonPinAir2, INPUT_PULLUP);
pinMode(buttonPinAir3, INPUT_PULLUP);
lcd.clear();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" Selamat Datang");
lcd.setCursor(0, 1);
lcd.print("Vending Machine Jamu");
lcd.setCursor(0, 2);
lcd.print(" Tradisional Madura");
lcd.setCursor(0, 3);
lcd.print(" Silakan Pilih Menu");
}
void loop() {
// Sekarang lanjutkan dengan pemilihan produk
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Pilih produk");
lcd.setCursor(0, 1);
lcd.print("1. Jamu A 4. Jamu D");
lcd.setCursor(0, 2);
lcd.print("2. Jamu B 5. Jamu E");
lcd.setCursor(0, 3);
lcd.print("3. Jamu C 6. Jamu F");
int selectedProduct = -1;
// Pembeli memilih produk
while (selectedProduct == -1) {
if (digitalRead(buttonPin1) == LOW) {
selectedProduct = 0;
} else if (digitalRead(buttonPin2) == LOW) {
selectedProduct = 1;
} else if (digitalRead(buttonPin3) == LOW) {
selectedProduct = 2;
} else if (digitalRead(buttonPin4) == LOW) {
selectedProduct = 3;
} else if (digitalRead(buttonPin5) == LOW) {
selectedProduct = 4;
} else if (digitalRead(buttonPin6) == LOW) {
selectedProduct = 5;
}
}
// Pembeli memilih air dingin atau panas
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Pilih Jenis AIR:");
lcd.setCursor(0, 1);
lcd.print("1. Air Hangat ");
lcd.setCursor(0, 2);
lcd.print("2. Air Dingin ");
lcd.setCursor(0, 3);
lcd.print("3. Air Biasa ");
int airSelection = 0;
while (airSelection != 1 && airSelection != 2 && airSelection != 3) {
if (digitalRead(buttonPinAir1) == LOW) {
airSelection = 1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Anda memilih: Air Hangat");
delay(2000);
} else if (digitalRead(buttonPinAir2) == LOW) {
airSelection = 2;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Anda memilih: Air Dingin");
delay(2000);
} else if (digitalRead(buttonPinAir3) == LOW) {
airSelection = 3;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Anda memilih: Air Biasa");
delay(2000);
}
}
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(" Masukkan Gelas");
lcd.setCursor(0, 2);
lcd.print(" Di Bawah");
digitalWrite(buzzerPin, LOW);
servoPintu.write(0);
digitalWrite(LedRGB, LOW);
delay(1000);
// Sensor proximity mendeteksi gelas
while (digitalRead(proximitySensorPin) == HIGH) {
// Tunggu sampai gelas terdeteksi
delay(100);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("--------------------");
lcd.setCursor(0, 1);
lcd.print(" Tunggu Proses");
lcd.setCursor(0, 2);
lcd.print(" Penyeduhan Jamu!");
lcd.setCursor(0, 3);
lcd.print("--------------------");
digitalWrite(buzzerPin, HIGH);
servoPintu.write(pos);
digitalWrite(LedRGB, HIGH);
delay(1000);
digitalWrite(LedRGB, LOW);
// Mengendalikan servo jamu
switch (selectedProduct) {
case 0:
servoJamu1.write(0);
digitalWrite(MotorJamu1, LOW);
delay(296);
servoJamu1.write(pos);
digitalWrite(MotorJamu1, HIGH);
break;
case 1:
servoJamu2.write(0);
digitalWrite(MotorJamu2, LOW);
delay(296);
servoJamu2.write(pos);
digitalWrite(MotorJamu2, HIGH);
break;
case 2:
servoJamu3.write(0);
digitalWrite(MotorJamu3, LOW);
delay(296);
servoJamu3.write(pos);
digitalWrite(MotorJamu3, HIGH);
break;
case 3:
servoJamu4.write(0);
digitalWrite(MotorJamu4, LOW);
delay(296);
servoJamu4.write(pos);
digitalWrite(MotorJamu4, HIGH);
break;
case 4:
servoJamu5.write(0);
digitalWrite(MotorJamu5, LOW);
delay(296);
servoJamu5.write(pos);
digitalWrite(MotorJamu5, HIGH);
break;
case 5:
servoJamu6.write(0);
digitalWrite(MotorJamu6, LOW);
delay(296);
servoJamu6.write(pos);
digitalWrite(MotorJamu6, HIGH);
break;
}
digitalWrite(hotWaterPumpPin, LOW);
delay(3173);
digitalWrite(hotWaterPumpPin, HIGH);
servoPengaduk.write(0);
delay(2000);
digitalWrite(MotorPegaduk, LOW);
delay(2000);
digitalWrite(MotorPegaduk, HIGH);
servoPengaduk.write(pos);
// Mengendalikan water pump
if (airSelection == 1) {
digitalWrite(hotWaterPumpPin, LOW);
delay(15865);
digitalWrite(hotWaterPumpPin, HIGH);
} else if (airSelection == 2) {
digitalWrite(coldWaterPumpPin, LOW);
delay(15865);
digitalWrite(coldWaterPumpPin, HIGH);
} else if (airSelection == 3) {
digitalWrite(WaterPumpPin, LOW);
delay(15865);
digitalWrite(WaterPumpPin, HIGH);
}
servoPengaduk.write(0);
delay(2000);
digitalWrite(MotorPegaduk, LOW);
delay(2000);
digitalWrite(MotorPegaduk, HIGH);
servoPengaduk.write(pos);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("--------------------");
lcd.setCursor(0, 1);
lcd.print(" Jamu Telah Siap");
lcd.setCursor(0, 2);
lcd.print(" Ambil Gelas!");
lcd.setCursor(0, 3);
lcd.print("--------------------");
digitalWrite(buzzerPin, LOW);
servoPintu.write(0);
delay(100);
// Sensor proximity mendeteksi gelas diambil
while (digitalRead(proximitySensorPin) == LOW) {
// Tunggu sampai gelas diambil
delay(1000);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Selamat Datang");
lcd.setCursor(0, 1);
lcd.print("Vending Machine Jamu");
lcd.setCursor(0, 2);
lcd.print(" Tradisional Madura");
lcd.setCursor(0, 3);
lcd.print(" Silakan Pilih Menu");
servoPintu.write(pos);
digitalWrite(LedRGB, HIGH);
digitalWrite(buzzerPin, HIGH);
}