Halaman 5
Alat Pemupuk dan Penyiram
Data Lama Tugas Akhir
List Program TA Alat Pemupuk dan Penyiram.
---------------------------------------------------------------------------------
// Program alat penyiram dan pemupuk tanaman dimulai
// tambahan menu jadwal pupuk
String
kondisi="jalan"; int j,j2,m,m2,m3,d,d2,hk,bl,tg,th;
int jj1,jj2,mm1,mm2,jadwal;
int np=1;int ns=1; int jd[50];
boolean aturpupuk; int lamasiram,lamapupuk;
#include <EEPROM.h>
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527
#include <LiquidCrystal.h>
const int rs = 32, en = 34, d4 = 38, d5 = 40, d6 = 42, d7 =
36;
LiquidCrystal lcd(rs, en, d4,
d5, d6, d7);
void setup(){
Wire.begin();
lcd.begin(16,2);
pinMode (3,INPUT); pinMode (5,INPUT); pinMode (7,INPUT);
pinMode (9,INPUT); pinMode (17,OUTPUT); pinMode (13,OUTPUT);
pinMode (15,OUTPUT);
// Membaca nilai EEPROM dan disimpan di variabel
for (int jj=1;
jj<50; jj++) { jd[jj]=EEPROM.read(jj);}
lamapupuk=
(jd[41]*100) + jd[42]; lamasiram=
(jd[43]*100) + jd[44]; }
void
loop(){
if (kondisi == "jalan" ){
// Mengakses waktu dari modul RTC
Wire.beginTransmission (DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
d =
bcdToDec(Wire.read()); // Detik
m =
bcdToDec(Wire.read()); // Menit
j =
bcdToDec(Wire.read() & 0b111111); //24 hour time
hk =
bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
bl =
bcdToDec(Wire.read()); // Bulan
tg =
bcdToDec(Wire.read()); // Tanggal
th =
bcdToDec(Wire.read()); delay (90); // Tahun
if (d != d2){ d2=d;
int dd1=d/10; int dd2=d%10; int mm1=m/10;
int mm2=m%10; int j1=j/10; int j2=j%10;
lcd.clear(); lcd.setCursor (0,0);
lcd.print( "Jam : " ); lcd.print
( j1 ); lcd.print
( j2 ) ; lcd.print
( ":");
lcd.print(mm1); lcd.print(mm2); lcd.print(":");
lcd.print(dd1); lcd.print(dd2);
lcd.setCursor (0,1);
lcd.print("Jalan Otomatis"); }
// Hasil Tampilan
// Jam : 1:01:55
// Jalan Otomatis
if ( digitalRead(3) == HIGH ) kondisi = "aturpupuk"; // tombol 1ditekan
if ( digitalRead(5) == HIGH ) kondisi = "atursiram"; // tombol 2
if ( digitalRead(7) == HIGH ) kondisi= "aturjam" ; // tombol 3
if ( digitalRead(9) == HIGH ) kondisi= "manual"; // tombol 4
delay (133);
if (m!=m3) { m3=m;
// Membandingkan menit jadwal dengan menit di jam yg ada
boolean jeda= false;
if ((m ==jd[11]
&& j ==jd[1]) || (m ==jd[12] && j ==jd[2])
|| ( m
==jd[13]&&j ==jd[3] ) || (m ==jd[14] && j ==jd[4] )
|| ( m ==jd[15]
&&j ==jd[5])|| ( m ==jd[16] && j ==jd[6] )
|| ( m ==jd[17]
&& j ==jd[7]) || (m ==jd[18] && j ==jd[8])
|| (m ==jd[19]
&& j ==jd[9])|| (m ==jd[20] && j ==jd[10]) ) {
// jika jam dan menit cocok maka proses memupuk dimulai
lcd.clear(); lcd.setCursor (0,0); lcd.print( "Pemupukan
");
lcd.setCursor (0,1);
lcd.print( "Dilaksanakan " );
digitalWrite (13,1);digitalWrite (17,1); delay
(lamapupuk*1000);
digitalWrite (13,0);digitalWrite (17,0) ;
jeda = true; }
// Membandingkan menit jadwal dengan menit di jam yg ada
if ( (m ==jd[31]
&& j ==jd[21]) || (m ==jd[32] && j ==jd[22]) ||
(m ==jd[33]
&& j ==jd[23]) || (m ==jd[34] && j ==jd[24] ) ||
( m ==jd[35]
&& j ==jd[25]) || (m ==jd[36] && m ==jd[26])
|| (m ==jd[37]
&& j ==jd[27]) || (m ==jd[38] && j ==jd[28])||
( m
==jd[39]&&j ==jd[29] ) || (m
==jd[40] && j ==jd[30] )) {
if (jeda == true ) {
lcd.clear(); lcd.setCursor (0,0); lcd.print("Waktu Jeda ");
lcd.setCursor (0,1);
lcd.print("1 Detik "); delay (1000) ;
}
// jika jam dan menit cocok maka proses memupuk dimulai
lcd.clear(); lcd.setCursor (0,0); lcd.print( "Penyiraman
" );
lcd.setCursor (0,1);
lcd.print( "Dilaksanakan " );
digitalWrite (15,1);digitalWrite (17,1); delay
(lamasiram*1000);
digitalWrite (15,0);digitalWrite (17,0) ; }
else jeda = false;
}// akhir cek jadwal
}// akhir mode ootomatis
// Bagian Mengatur Jam Alat / RTC
if ( kondisi ==
"aturjam") {
jj1=j/10; jj2=j%10 ; mm1=m/10; mm2=m%10;
lcd.clear(); lcd.setCursor (0,0); lcd.print("Rubah Jam:"); lcd.print(jj1); lcd.print(jj2);lcd.print(":"); lcd.print(mm1);
lcd.print(mm2);
lcd.setCursor (0,1);
lcd.print("1= + 2= - 4=Ok"); delay (200);
if (digitalRead (3)
== HIGH ) {j=j+1; if (j> 23) j = 0; delay(200);}
if (digitalRead (5)
== HIGH ) {j=j-1; if (j<0)
j = 23; delay(200); }
if (digitalRead (9)
== HIGH ) { kondisi ="aturjam2"; delay (200);}
delay (100) ; }
if ( kondisi ==
"aturjam2") {
mm1=m/10; mm2=m%10;
lcd.clear();
lcd.setCursor (0,0); lcd.print ("Rbh
Menit:"); lcd.print(jj1); lcd.print(jj2); lcd.print(":")
; lcd.print(mm1); lcd.print
(mm2);
lcd.setCursor (0,1);
lcd.print ("1= + 2= - 4=Ok"); delay (100);
if (digitalRead (3)
== HIGH ) {m=m+1 ; if (m>59) m=0;delay(200);
}
if (digitalRead (5)
== HIGH ) {m=m-1 ; if (m<0) m=59;delay(200);
}
// tombol 4 itekan maka jam akan disimpan
if (digitalRead (9)
== HIGH ) { kondisi="jalan";
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
//stop Oscillator
Wire.write(decToBcd(50));
Wire.write(decToBcd(m));
Wire.write(decToBcd(j));
Wire.write(decToBcd(hk));
Wire.write(decToBcd(tg));
Wire.write(decToBcd(bl));
Wire.write(decToBcd(th));
Wire.write(zero);
//start
Wire.endTransmission(); delay(200); }}
// Bagian Pengaturan Pupuk
if (kondisi
=="aturpupuk") {
lcd.clear (); lcd.setCursor (0,0); lcd.print("Masuk Pengaturan");
lcd.setCursor (0,1);
lcd.print(" Pemupukan "); delay (1200);
kondisi="pupuk1" ; }
if (kondisi
=="pupuk1") {
lcd.clear(); lcd.setCursor (0,0); lcd.print("1.Jadwal 2.Lama");
lcd.setCursor (0,1);
lcd.print("Proses 4.Keluar"); delay (100);
if (digitalRead(3)==HIGH) { kondisi="pupuk2"; delay(200);
}
if (digitalRead(5)==HIGH) {kondisi="aturlamapupuk"; delay(200);}
if (digitalRead(9)==HIGH) {kondisi="jalan"; delay(200);
} }
if (kondisi ==
"pupuk2") {
lcd.clear(); lcd.setCursor (0,0); lcd.print("Pemupukan Ke ");lcd.print(np);
lcd.setCursor (0,1);
lcd.print("1= Atur 2= Tidak"); delay (100);
// jika memilih Tombol 2 .. tidak mengatur . maka akan masuk
ke mode jalan
if (digitalRead(5)
== HIGH) {
kondisi
="jalan";
for ( int jj=np ;
jj<11; jj++) {jd[jj]=88; EEPROM.write(jj,88);}
np=1; delay(200); }
// Tombol 1 .. memilih masuk pengaturan
if (digitalRead(3) == HIGH) {kondisi="pupuk3"; delay (150);}}
// pertama atur jam
if (kondisi
=="pupuk3") {
lcd.clear(); lcd.setCursor (0,0); lcd.print("Atur Jam:"); lcd.print(jd[np]);
lcd.print(":");lcd.print(jd[np+10]);
lcd.setCursor
(0,1); lcd.print("1(+) 2(-) 4(Ok)"); delay (200);
// Tombol 1 untuk tambah jam
if (digitalRead(3) == HIGH) {
jd[np]=jd[np]+1; if (jd[np] >23) jd[np]=0;}
// Tombol 4 untuk kurangi nilai jam
if (digitalRead(5) == HIGH) {
jd[np]=jd[np]-1; if (jd[np] <0 ) jd[np]=23;}
// Tombol 2 untuk tambah nilai menit
if (digitalRead(9)
== HIGH) {
EEPROM.write(np,jd[np]);
kondisi="pupuk4" ; delay(200); }}
if (kondisi
=="pupuk4") {
lcd.clear();
lcd.setCursor (0,0);
lcd.print("Atur
Menit:"); lcd.print(jd[np]); lcd.print(":");lcd.print(jd[np+10]);
lcd.setCursor
(0,1);
lcd.print("1(+)
2(-) 4(Ok)"); delay (200);
// Tombol 1 untuk kurangi menit
if (digitalRead(3) == HIGH) {
jd[np+10]=jd[np+10]+1; if (jd[np+10]
>59) jd[np+10]=0; }
// Tombol 2 untuk kurangi menit
if (digitalRead(5) == HIGH) {
jd[np+10]=jd[np+10]-1; if (jd[np+10]
<0) jd[np+10]=59; }
if (digitalRead(9) == HIGH) {
EEPROM.write(np+10,jd[np+10]); np=np+1;
kondisi="pupuk2" ;
delay(100);
if (np==11){np=1;
kondisi= "jalan" ; delay(200);}}}
if (kondisi ==
"aturlamapupuk") {
lcd.clear(); lcd.setCursor (0,0); lcd.print( "Mengatur" );
lcd.setCursor
(0,1); lcd.print(
"Lama Pemupukan" );
delay (1000); kondisi= "lamapupuk2"; }
if (kondisi == "lamapupuk2" ) {
lcd.clear(); lcd.setCursor (0,0); lcd.print("Lama=
"); lcd.print
(lamapupuk); lcd.print (" Detik");
lcd.setCursor
(0,1); lcd.print("1(+) 2(-) 4(Ok)" );
delay (150);
// Tombol 1 untuk
tambah detik
if (digitalRead(3) == HIGH) {
lamapupuk =
lamapupuk + 5 ;
if (lamapupuk>1200) lamapupuk=5;
delay (100); }
// Tombol 2 untuk kurangi detik
if (digitalRead(5) == HIGH) {
lamapupuk =
lamapupuk - 5 ;
if (lamapupuk < 5) lamapupuk = 1200;
delay (100); }
// Tombol 4 untuk
menyimpan data/ Oke
if (digitalRead(9) == HIGH) {
jd[41] = lamapupuk /
100; jd[42]=lamapupuk % 100 ;
EEPROM.write(41,jd[41]) ;
EEPROM.write(42,jd[42]) ;
kondisi=
"jalan" ;
delay (200); }}
// Bagian Pengaturan Penyiraman
if (kondisi == "atursiram"
) {
lcd.clear(); lcd.setCursor (0,0); lcd.print( "Masuk Pengaturan" );
lcd.setCursor (0,1);
lcd.print( " Penyiraman " ); delay (1200);
kondisi="siram1" ; }
if (kondisi
=="siram1") {
lcd.clear(); lcd.setCursor (0,0); lcd.print(
"1.Jadwal 2.Lama");
lcd.setCursor (0,1);
lcd.print( "Proses 4.Keluar"); delay (100);
if (digitalRead(3) ==HIGH) { kondisi= "siram2" ; delay(200);
}
if (digitalRead(5) ==HIGH) {kondisi= "aturlamasiram" ; delay(200);}
if (digitalRead(9) ==HIGH) {kondisi= "jalan" ; delay(200);}}
if (kondisi
=="siram2") {
lcd.clear();
lcd.setCursor (0,0); lcd.print( "Penyiraman Ke " );lcd.print(ns);
lcd.setCursor (0,1); lcd.print( "1=
Atur 2= Tidak" ); delay (100);
// Tombol 2 .. tidak mengatur
if (digitalRead(5) == HIGH) {
for ( int jj=ns+20 ;
jj<31; jj++) { jd[jj]=88; EEPROM.write(jj,88);}
kondisi="jalan"; ns=1; delay(200);
}
// Tombol 1 .. memilih masuk pengaturan
if (digitalRead(3) ==HIGH) kondisi="siram3";
delay (150); }
if (kondisi
=="siram3") {
lcd.clear(); lcd.setCursor (0,0);
lcd.print( "Atur Jam:"); lcd.print(jd[ns+20]);
lcd.print(":");lcd.print(jd[ns+30]);
lcd.setCursor
(0,1); lcd.print("1(+) 2(-) 4(Ok)"); delay (200);
// Tombol 1 untuk tambah jam
if (digitalRead(3) == HIGH) {
jd[ns+20]=jd[ns+20]+1; if (jd[ns+20]
>23) jd[ns+20]=0;}
// Tombol 2 untuk kurangi nilai jam
if (digitalRead(5) == HIGH) {
jd[ns+20]=jd[ns+20]-1; if (jd[ns+20]
<0 || jd[ns+20] > 24 ) jd[ns+20]=23;}
// Tombol 2 untuk tambah nilai menit
if (digitalRead(9) == HIGH) {
EEPROM.write(ns+20,jd[ns+20]);
kondisi="siram4" ; delay(100); }}
if (kondisi
=="siram4") {
lcd.clear(); lcd.setCursor (0,0);
lcd.print("Atur
Menit:"); lcd.print(jd[np+20]); lcd.print(":");lcd.print(jd[np+30]);
lcd.setCursor
(0,1); lcd.print("1(+) 2(-) 4(Ok)"); delay (200);
// Tombol 1 untuk kurangi menit
if (digitalRead(3) == HIGH) {
jd[ns+30]=jd[ns+30]+1; if (jd[ns+30]
>59) jd[ns+30]=0; }
// Tombol 2 untuk kurangi menit
if (digitalRead(5) == HIGH) {
jd[ns+30]=jd[ns+30]-1; if (jd[ns+30]
<0) jd[ns+30]=59; }
// Tombol 4 untuk
menyimpan data/ Oke
if (digitalRead(9) == HIGH) {
EEPROM.write(ns+30,jd[ns+30]); ns=ns+1;
kondisi= "siram2"
; delay(100);
if (ns==11) {np=1;
kondisi= "jalan"; }}}
if (kondisi == "aturlamasiram" ) {
lcd.clear(); lcd.setCursor (0,0); lcd.print( "Mengatur");
lcd.setCursor
(0,1); lcd.print(
"Lama Penyiraman");
delay (1000); kondisi= "lamasiram2"; }
if (kondisi == "lamasiram2") {
lcd.clear(); lcd.setCursor (0,0); lcd.print("Lama=
"); lcd.print
(lamasiram); lcd.print (" Detik");
lcd.setCursor
(0,1); lcd.print("1(+) 2(-) 4(Ok)" ); delay (150);
// Tombol 1 untuk
tambah detik
if (digitalRead(3) == HIGH) {
lamasiram = lamasiram + 5 ;
if (lamasiram>1200) lamasiram=0; delay (100);
}
// Tombol 2 untuk kurangi detik
if (digitalRead(5) == HIGH)
{ lamasiram = lamasiram - 5 ;
if (lamasiram < 5) lamasiram = 1200;
delay (100); }
// Tombol 4 untuk
menyimpan data/ Oke
if (digitalRead(9) == HIGH) {
jd[43] = lamasiram /
100; jd[44]=lamasiram % 100 ;
EEPROM.write(43,jd[43]) ;
EEPROM.write(44 ,jd[44]) ;
kondisi= "jalan"; delay (250);
}}
if (kondisi== "manual" ) {
lcd.clear(); lcd.setCursor (0,0); lcd.print( "Masuk Mode ");
lcd.setCursor
(0,1); lcd.print( "Jalan Manual");
delay(1100);
kondisi= "manual2"; }
if (kondisi == "manual2") {
lcd.clear(); lcd.setCursor (0,0); lcd.print("1.Pupuk 2.Siram");
lcd.setCursor
(0,1); lcd.print("3.
Stop 4. Keluar"); delay(150);
if (digitalRead(3) == HIGH) {kondisi = "pupukmanual"; delay(100); }
if (digitalRead(5) == HIGH) {
kondisi= "sirammanual"
;delay(100);}
if (digitalRead(9) == HIGH) {
kondisi= "jalan"; delay
(150); }}
if (kondisi == "pupukmanual" ){
digitalWrite(13,HIGH); digitalWrite(17,HIGH);
lcd.clear(); lcd.setCursor (0,0); lcd.print( "Pemupukan Jalan"
);
lcd.setCursor
(0,1); lcd.print("Tekan
3= Stop "); delay (100);
if (digitalRead(7) ==HIGH) {
digitalWrite(13,LOW); digitalWrite(17,LOW); delay(100);
kondisi="manual2";}}
if (kondisi
=="sirammanual"){
digitalWrite(15,HIGH); digitalWrite(17,HIGH);
lcd.clear(); lcd.setCursor (0,0); lcd.print("Penyiraman
Jalan");
lcd.setCursor
(0,1); lcd.print("Tekan
3= Stop "); delay (100);
if (digitalRead(7) == HIGH) {
digitalWrite(15,LOW); digitalWrite(17,LOW); delay(100);
kondisi= "manual2"; }}}
byte bcdToDec(byte val)
{
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10)
+ (val%16) ); }
byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16)
+ (val%10) ); }
--------------------------------------------------------------------------------
Komentar
Posting Komentar