Kabeh Flowchart
Kabeh Flowchart
Kabeh Flowchart
3 Perencanaan Sistem
#include <NewPing.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN
#include <OneWire.h>
int DS18S20_Pin = 11; //DS18S20 Signal pin on digital 2
OneWire ds(DS18S20_Pin); // on digital pin 2
float temperature=0;
#include <LiquidCrystal.h> //include the library code:
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);// initialize the library with the numbers of the
interface pins
byte customChar[8] = {
0b11000,
0b11000,
0b00111,
0b01000,
0b01000,
0b01000,
0b00111,
0b00000
};
#include <Servo.h>
Servo myservo;
int pos = 0;
#define relay_kompor
#define relay_servo
14
15
#define relay_strawberry 16
#define relay_coklat
#define relay_melon
#define relay_susu
17
18
19
#define ok 8
#define up 9
byte count_menu=0;
String rasa;
void setup(void) {
lcd.createChar(0, customChar);
pinMode(ok,INPUT_PULLUP);
pinMode(up,INPUT_PULLUP);
pinMode(relay_kompor,OUTPUT);
pinMode(relay_servo,OUTPUT);
pinMode(relay_strawberry,OUTPUT);
pinMode(relay_coklat,OUTPUT);
pinMode(relay_melon,OUTPUT);
pinMode(relay_susu,OUTPUT);
digitalWrite(relay_kompor,1);
digitalWrite(relay_servo,1);
digitalWrite(relay_strawberry,1);
digitalWrite(relay_coklat,1);
digitalWrite(relay_melon,1);
digitalWrite(relay_susu,1);
digitalWrite(relay_servo,1);
myservo.attach(10);
Serial.begin(9600);
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.print("welcome"); // Print a message to the LCD.
delay(1000);
lcd.clear();
}
void loop(void) {
lcd.setCursor(0,0);
lcd.print("stanby"); lcd.print("
");
temperature = getTemp();
Serial.println(temperature);
lcd.setCursor(0,1);
lcd.print("suhu :"); lcd.print(temperature);lcd.print("
");lcd.write((uint8_t)0);lcd.print(" ");
lcd.clear();
do{
temperature = getTemp();
lcd.setCursor(0,0);
lcd.print("kompor aktif");
lcd.setCursor(0,1);
lcd.print("suhu :"); lcd.print(temperature);lcd.print(" ");lcd.write((uint8_t)0);
lcd.print(" ");
digitalWrite(relay_kompor,0);
}while(temperature<62);
digitalWrite(relay_kompor,1);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("kompor mati");
delay(3000);
menu();
}
}
void menu(){
do{
if(digitalRead(up)==LOW){
do{
delay(50);
}while(digitalRead(up)==LOW);
Serial.println("up");count_menu++;
if(count_menu==3){count_menu=0;}}
if(count_menu==0){rasa="coklat";}
if(count_menu==1){rasa="melon";}
if(count_menu==2){rasa="strawberry";}
lcd.setCursor(0,0);
lcd.print("pilihan rasa");
lcd.setCursor(0,1);
lcd.print(rasa); lcd.print("
");
}while(digitalRead(ok)==HIGH);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("rasa yg dipilih");
lcd.setCursor(0,1);
lcd.print(rasa);
delay(3000);
lcd.clear();
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("isi rasa");
if(rasa=="coklat"){
digitalWrite(relay_servo,0);
myservo.write(95);
delay(500);
digitalWrite(relay_servo,1);
delay(1000);
//-----------------------------------------do{
digitalWrite(relay_coklat,0);
ambil_jarak();
lcd.setCursor(0,0);
lcd.print("tinggi pengisian");
lcd.setCursor(0,1);
lcd.print("rasa :");lcd.print(tinggi);lcd.print(" "); lcd.print("cm");
}while(tinggi<3); digitalWrite(relay_coklat,1);
digitalWrite(relay_susu,0);
do{
ambil_jarak();
lcd.setCursor(0,0);
lcd.print("tinggi pengisian");
lcd.setCursor(0,1);
lcd.print("susu :");lcd.print(tinggi);lcd.print(" ");lcd.print("cm");
}while(tinggi<9);
digitalWrite(relay_susu,1);
//-----------------------------------------}
if(rasa=="melon"){
digitalWrite(relay_servo,0);
myservo.write(65);
delay(500);
digitalWrite(relay_servo,1);
delay(1000);
//-----------------------------------------do{
digitalWrite(relay_melon,0);
ambil_jarak();
lcd.setCursor(0,0);
lcd.print("tinggi pengisian");
lcd.setCursor(0,1);
digitalWrite(relay_susu,0);
do{
ambil_jarak();
lcd.setCursor(0,0);
lcd.print("tinggi pengisian");
lcd.setCursor(0,1);
lcd.print("susu :");lcd.print(tinggi);lcd.print(" ");lcd.print("cm");
}while(tinggi<9);
digitalWrite(relay_susu,1);
//-----------------------------------------}
if(rasa=="strawberry"){
digitalWrite(relay_servo,0);
myservo.write(123);
delay(500);
digitalWrite(relay_servo,1);
delay(1000);
//------------------------------------------
do{
digitalWrite(relay_strawberry,0);
ambil_jarak();
lcd.setCursor(0,0);
lcd.print("tinggi pengisian");
lcd.setCursor(0,1);
lcd.print("rasa :");lcd.print(tinggi);lcd.print(" ");lcd.print("cm");
}while(tinggi<3); digitalWrite(relay_strawberry,1);
digitalWrite(relay_susu,0);
do{
ambil_jarak();
lcd.setCursor(0,0);
lcd.print("tinggi pengisian");
lcd.setCursor(0,1);
lcd.print("susu :");lcd.print(tinggi);lcd.print(" ");lcd.print("cm");
}while(tinggi<9);
digitalWrite(relay_susu,1);
//-----------------------------------------}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ready to drink");
delay(3000);
lcd.clear();
void ambil_jarak() {
delay(500);
// Wait 50ms between pings (about 20 pings/sec). 29ms
should be the shortest delay between pings.
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
jarak=uS / US_ROUNDTRIP_CM;
tinggi=14-jarak;
if(tinggi<0){ambil_jarak();}
}
float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
ds.reset_search();
return TemperatureSum;