Translate

Membuat Alat Monitor Water Flow Meter / Flow rate dan Water Level / Jarak HC-srf04 Bascom AVR interface Delphi 7

Membuat Alat Monitor Water Flow Meter / Flow rate dan Water Level / Jarak HC-srf04 Bascom AVR interface Delphi 7


              Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk mengukur ketinggian air dan juga mengukur kecepatan aliran air menggunakan mikrokontroller, alat ini dapat menampilkan data di LCD dan interface grafik pada laptop / komputer dengan software DELPHI 7. untuk lebih jelasnya berikut adalah skema dan programnya.



a. Minimum System ATmega16




b. Sensor Jarak HC-SFR04




c. Sensor Water Flow / Flow Rate




d. PL232 Modul






e. Program Bascom AVR

$regfile = "m16def.dat"
$crystal = 12000000
$baud = 9600

'Konfigurasi LCD
Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.1 , Db4 = Portc.2
Config Lcdpin = Pin , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Lcd = 16 * 2

Config Timer0 = Timer , Prescale = 256

Cls
Cursor Off


Config Portb.2 = Output
Config Pinb.1 = Input

Declare Sub Cek_jarak

Dim Data_jarak As Word
Dim Data_jarak_olah As Word
Dim Data_jarak_fix As Word

Triger1 Alias Portb.2
Pecho1 Alias Pinb.1


Ch Alias Pind.2

Config Pind.2 = Output

Config Ch = Input

Config Int0 = Falling
Const Debouncetime = 1

Dim Wtime As Byte
Dim Encounter As Integer
Dim Q As Integer

Set Ch

On Int0 Getencoder

Cls

Wtime = 100
Encounter = 0

Enable Interrupts
Enable Int0




Mulai:
Cls
Cursor Off

Do
Call Cek_jarak
  Data_jarak = Data_jarak
  Data_jarak_olah = Data_jarak * 100
  Data_jarak_fix = Data_jarak_olah / 256


Upperline
Lcd "Jarak= " ; Data_jarak_fix ; " cm      "

 Q = Encounter * 60
 Q = Q / 8.1
 Q = Q * 1

 Set Portd.6
  Waitms Wtime
  Lowerline
  Lcd "Flow= " ; Q ; "                  "
  Reset Portd.6
  Waitms Wtime

Waitms 200

Print Q ; "a"
Print Data_jarak_fix ; "b"

Encounter = 0

Waitms 1000
Loop


Sub Cek_jarak:
Reset Triger1
Waitus 10
Set Triger1
Waitus 20
Reset Triger1

Tcnt0 = 0
Bitwait Pecho1 , Set
Start Timer0

Do
If Pecho1 = 0 Then
Data_jarak = Tcnt0
Stop Timer0
Exit Do
End If

If Tifr.0 = 1 Then
Stop Timer0
Tifr.0 = 1
Data_jarak = &HFF
Exit Do
End If
Loop
Stop Timer0
Waitms 15
End Sub



Getencoder:
  Waitms Debouncetime
  If Ch = 0 Then
     Incr Encounter
  End If
  Gifr = 64
Return

End





f. Program Delphi 7



unit TA;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,strutils, TeeProcs, TeEngine, Chart, CPort, mmsystem,
  Series, Buttons;

type
  TForm1 = class(TForm)
    ComPort1: TComPort;
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Chart1: TChart;
    Shape1: TShape;
    Shape2: TShape;
    GroupBox2: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    Label7: TLabel;
    Label8: TLabel;
    BitBtn1: TBitBtn;
    Series1: TFastLineSeries;
    Series2: TFastLineSeries;
    Chart2: TChart;
    Series3: TFastLineSeries;
    Chart3: TChart;
    Series4: TFastLineSeries;
    Timer2: TTimer;
    Timer3: TTimer;
    procedure ComPort1RxChar(Sender: TObject; Count: Integer);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Timer3Timer(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var buff:string;
begin
comport1.ReadStr(buff,count);
memo1.Text:=memo1.Text+buff;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
comport1.ShowSetupDialog;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Timer2.Enabled := True;
Timer3.Enabled := True;
if button2.Caption='Connect' then
   begin
   button2.Caption:='Disconnect';
   comport1.Open;
   end
else if button2.Caption='Disconnect' then
   begin
   button2.Caption:='Connect';
   comport1.Close;
   end;

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Edit1.Color:=clwhite;
Edit2.Color:=clwhite;
edit1.text:='';
edit2.text:='';
memo1.Text:='';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ThousandSeparator:=',';
DecimalSeparator:='.';
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
label7.Caption:='Date  '+ FormatdateTime('d/mm/yyyy',Date);
label8.Caption:='Time  '+ FormatDateTime('hh:nn:ss',Time);
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
var
  F: TextFile;
begin
  AssignFile(F, 'D:\record.txt');
  Append(F);
  WriteLn(F, '======================================');
  WriteLn(F, 'Tanggal = ',label7.Caption);
  WriteLn(F, 'Jam     = ',label8.Caption);
  WriteLn(F, '======================================');

  WriteLn(F, 'Flow  : ',Edit1.Text);
  WriteLn(F, 'Jarak: ',Edit2.Text);
  CloseFile(F);
end;

procedure TForm1.Timer3Timer(Sender: TObject);
var ruang,kulit:double;
    rin,kin:string;
    jumlahdata:integer;

begin
  shape1.Brush.Color:=clgreen;
  shape2.Brush.Color:=clgreen;
  jumlahdata:=chart1.GetMaxValuesCount;
  form1.Caption:=inttostr(jumlahdata);
  //if jumlahdata > 60 then
  //   begin
  //   chart1.Series[0].Clear;
  //   chart1.Series[1].Clear;
  //   Series3.Clear;
  //   Series4.Clear;
  //   end;

  rin:=memo1.Lines[memo1.Lines.count-2];
  kin:=memo1.Lines[memo1.Lines.count-1];

  if rightstr(rin,1)= 'a' then
     begin
     edit1.Text:=leftstr(rin,length(rin)-1);
     ruang:=strtofloat(edit1.text);
     chart1.Series[0].Add(ruang,'',clred) ;
     Series3.Add(ruang,'',clred) ;
     shape1.Brush.Color:=clred;
     end;
  if rightstr(kin,1)='b' then
     begin
     edit2.Text:=leftstr(kin,length(kin)-1);
     kulit:=strtofloat(edit2.text);
     chart1.Series[1].Add(kulit,'',clgreen) ;
     Series4.Add(kulit,'',clgreen) ;
     shape2.Brush.Color:=clgreen;
     end;


end;

end.





f. VIDEO HASILNYA










Membuat Alat Kendali Relay dengan Timer Countdown (ON OFF Relay berdasarkan waktu yang diset)

Membuat Alat Kendali Relay dengan Timer Countdown (ON OFF Relay berdasarkan waktu yang diset)


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan relay berdasarkan input waktu yang kita tentukan sendiri atau setting time, jadi alat ini hanya ON / OFF relay seperti biasa namun relay akan ON sesuai dengan input waktu yang kita inginkan dalam satuan detik, jadi setelah waktu ON relay melebihi dari setting time yang kita tentukan maka relay akan OFF secara otomatis. untuk lebih jelasnya berikut adalah skema dan programnya. 




a. Arduino Uno




b. Relay 5v




c. LCD 20x4 + I2C






d. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
LiquidCrystal_I2C lcd(0x3F, 20, 4); //library i2c lcd

int btok = 8;
int btup = 10;
int btdown = 9;
int btset = 13;

int mode = 1;
int passwd;
int btokx = 0;
int btupx = 0;
int btdownx = 0;
int btsetx = 0;

int relay1 = 3;
int relay2 = 4;
int relay3 = 5;
int relay4 = 6;
int relay5 = 7;
int relay6 = 2;

int x1;
int x2;
int x3;
int x4;
int x5;
int x6;
int x7;
int x8;
int x9;
int x10;
int x11;
int x12;
int x13;
int x14;
int x15;
int x16;
int x17;
int x18;
int x19;
int x20;
int x21;
int x22;
int x23;
int x24;

int relay1p = 1;
int relay2p = 0;
int relay3p = A3;
int relay4p = A2;
int relay5p = A1;
int relay6p = A0;

int relay1px = 0;
int relay2px = 0;
int relay3px = 0;
int relay4px = 0;
int relay5px = 0;
int relay6px = 0;

int timer1;
int timer2;
int timer3;
int timer4;
int timer5;
int timer6;
int timer7;
int timer8;
int timer9;
int timer10;
int timer11;
int timer12;
int timer13;
int timer14;
int timer15;
int timer16;
int timer17;
int timer18;
int timer19;
int timer20;
int timer21;
int timer22;
int timer23;
int timer24;

int timer1x;
int timer2x;
int timer3x;
int timer4x;
int timer5x;
int timer6x;
int timer7x;
int timer8x;
int timer9x;
int timer10x;
int timer11x;
int timer12x;
int timer13x;
int timer14x;
int timer15x;
int timer16x;
int timer17x;
int timer18x;
int timer19x;
int timer20x;
int timer21x;
int timer22x;
int timer23x;
int timer24x;


void setup() {
  lcd.begin(); 
  lcd.noCursor(); 
  lcd.clear(); 

pinMode(btok,INPUT_PULLUP);
pinMode(btup,INPUT_PULLUP);
pinMode(btdown,INPUT_PULLUP);
pinMode(btset,INPUT_PULLUP);

pinMode(relay1p,INPUT_PULLUP);
pinMode(relay2p,INPUT_PULLUP);
pinMode(relay3p,INPUT_PULLUP);
pinMode(relay4p,INPUT_PULLUP);
pinMode(relay5p,INPUT_PULLUP);
pinMode(relay6p,INPUT_PULLUP);

pinMode(relay1,OUTPUT);
pinMode(relay2,OUTPUT);
pinMode(relay3,OUTPUT);
pinMode(relay4,OUTPUT);
pinMode(relay5,OUTPUT);
pinMode(relay6,OUTPUT);

}



void loop() {
lcd.setCursor(0,0); 
lcd.print("MENU PILIHAN");
lcd.setCursor(0,1); 
lcd.print("1.START");
lcd.setCursor(0,2); 
lcd.print("2.SETTING");

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

x1 = 0;
x2 = 0;
x3 = 0;
x4 = 0;
x5 = 0;
x6 = 0;
x7 = 0;
x8 = 0;
x9 = 0;
x10 = 0;
x11 = 0;
x12 = 0;
x13 = 0;
x14 = 0;
x15 = 0;
x16 = 0;
x17 = 0;
x18 = 0;
x19 = 0;
x20 = 0;
x21 = 0;
x22 = 0;
x23 = 0;
x24 = 0;

timer1 = timer1x;
timer2 = timer2x;
timer3 = timer3x;
timer4 = timer4x;
timer5 = timer5x;
timer6 = timer6x;
timer7 = timer7x;
timer8 = timer8x;
timer9 = timer9x;
timer10 = timer10x;
timer11 = timer11x;
timer12 = timer12x;
timer13 = timer13x;
timer14 = timer14x;
timer15 = timer15x;
timer16 = timer16x;
timer17 = timer17x;
timer18 = timer18x;
timer19 = timer19x;
timer20 = timer20x;
timer21 = timer21x;
timer22 = timer22x;
timer23 = timer23x;
timer24 = timer24x;

if(btokx == 0){
lcd.clear();
delay(1000);
mulai();
counter();
btsetx = 1;
}

if(btsetx == 0){
delay(200);
lcd.clear();
passwd = 0;
password();
lcd.clear();
delay(1000);
satu();
lcd.clear();
delay(1000);
dua();
lcd.clear();
delay(1000);
tiga();
lcd.clear();
delay(1000);
empat();
lcd.clear();
delay(1000);
lima();
lcd.clear();
delay(1000);
enam();
lcd.clear();
delay(1000);
tujuh();
lcd.clear();
delay(1000);
delapan();
lcd.clear();
delay(1000);
sembilan();
lcd.clear();
delay(1000);
sepuluh();
lcd.clear();
delay(1000);
sebelas();
lcd.clear();
delay(1000);
duabelas();
lcd.clear();
delay(1000);
tigabelas();
lcd.clear();
delay(1000);
empatbelas();
lcd.clear();
delay(1000);
limabelas();
lcd.clear();
delay(1000);
enambelas();
lcd.clear();
delay(1000);
tujuhbelas();
lcd.clear();
delay(1000);
delapanbelas();
lcd.clear();
delay(1000);
sembilanbelas();
lcd.clear();
delay(1000);
duapuluh();
lcd.clear();
delay(1000);
duapuluhsatu();
lcd.clear();
delay(1000);
duapuluhdua();
lcd.clear();
delay(1000);
duapuluhtiga();
lcd.clear();
delay(1000);
duapuluhempat();
lcd.clear();
}

}




void counter(){

lcd.setCursor(10,3); 
lcd.print("  CUCIAN="); 
lcd.print(mode); 

btdownx = digitalRead(btdown);

if(btdownx == 0){
lcd.clear();
delay(1000);
return;
}

relay1px = digitalRead(relay1p);
relay2px = digitalRead(relay2p);
relay3px = digitalRead(relay3p);
relay4px = digitalRead(relay4p);
relay5px = digitalRead(relay5p);
relay6px = digitalRead(relay6p);


if((relay1px == 0)&&(mode == 1)&&(timer1 > 0)&&(x1 == 0)){
 x1 = 1;
digitalWrite(relay1,HIGH);
}
if(x1 == 1){
lcd.setCursor(0,0); 
lcd.print(timer1); 
lcd.print("          "); 
timer1--;
if(timer1 <= 0){
timer1 = 0;
digitalWrite(relay1,LOW);
}
}

if((relay2px == 0)&&(mode == 1)&&(timer2 > 0)&&(x2 == 0)){
x2 = 1;
digitalWrite(relay2,HIGH);
}
if(x2 == 1){
lcd.setCursor(0,1); 
lcd.print(timer2); 
lcd.print("          "); 
timer2--;
if(timer2 <= 0){
timer2 = 0;
digitalWrite(relay2,LOW);
}
}


if((relay3px == 0)&&(mode == 1)&&(timer3 > 0)&&(x3 == 0)){
x3 = 1;
digitalWrite(relay3,HIGH);
}
if(x3 == 1){
lcd.setCursor(0,2); 
lcd.print(timer3); 
lcd.print("          ");
timer3--;
if(timer3 <= 0){
timer3 = 0;
digitalWrite(relay3,LOW);
}
}



if((relay4px == 0)&&(mode == 1)&&(timer4 > 0)&&(x4 == 0)){
x4 = 1;
digitalWrite(relay4,HIGH);
}
if(x4 == 1){
lcd.setCursor(0,3); 
lcd.print(timer4); 
lcd.print("          ");
timer4--;
if(timer4 <= 0){
timer4 = 0;
digitalWrite(relay4,LOW);
}
}



if((relay5px == 0)&&(mode == 1)&&(timer5 > 0)&&(x5 == 0)){
x5 = 1;
digitalWrite(relay5,HIGH);
}
if(x5 == 1){
lcd.setCursor(10,0); 
lcd.print(timer5); 
lcd.print("          ");
timer5--;
if(timer5 <= 0){
timer5 = 0;
digitalWrite(relay5,LOW);
}
}





if((relay6px == 0)&&(mode == 1)&&(timer6 > 0)&&(x6 == 0)){
x6 = 1;
digitalWrite(relay6,HIGH);
}
if(x6 == 1){
lcd.setCursor(10,1); 
lcd.print(timer6); 
lcd.print("          ");
timer6--;
if(timer6 <= 0){
timer6 = 0;
digitalWrite(relay6,LOW);
}
}
//============================================================

if((relay1px == 0)&&(mode == 2)&&(timer7 > 0)&&(x7 == 0 )){
x7 = 1;
digitalWrite(relay1,HIGH);
}
if(x7 == 1){
lcd.setCursor(0,0); 
lcd.print(timer7); 
lcd.print("          ");
timer7--;
if(timer7 <= 0){
timer7 = 0;
digitalWrite(relay1,LOW);
}
}



if((relay2px == 0)&&(mode == 2)&&(timer8 > 0)&&(x8 == 0)){
x8 = 1;
digitalWrite(relay2,HIGH);
}
if(x8 == 1){
lcd.setCursor(0,1); 
lcd.print(timer8); 
lcd.print("          ");
timer8--;
if(timer8 <= 0){
timer8 = 0;
digitalWrite(relay2,LOW);
}
}




if((relay3px == 0)&&(mode == 2)&&(timer9 > 0)&&(x9 == 0)){
x9 = 1;
digitalWrite(relay3,HIGH);
}
if(x9 == 1){
lcd.setCursor(0,2); 
lcd.print(timer9); 
lcd.print("          ");
timer9--;
if(timer9 <= 0){
timer9 = 0;
digitalWrite(relay3,LOW);
}
}


if((relay4px == 0)&&(mode == 2)&&(timer10 > 0)&&(x10 == 0)){
x10 = 1;
digitalWrite(relay4,HIGH);
}
if(x10 == 1){
lcd.setCursor(0,3); 
lcd.print(timer10); 
lcd.print("          ");
timer10--;
if(timer10 <= 0){
timer10 = 0;
digitalWrite(relay4,LOW);
}
}


if((relay5px == 0)&&(mode == 2)&&(timer11 > 0)&&(x11 == 0)){
x11 = 1;
digitalWrite(relay5,HIGH);
}
if(x11 == 1){
lcd.setCursor(10,0); 
lcd.print(timer11); 
lcd.print("          ");
timer11--;
if(timer11 <= 0){
timer11 = 0;
digitalWrite(relay5,LOW);
}
}


if((relay6px == 0)&&(mode == 2)&&(timer12 > 0)&&(x12 == 0)){
x12 = 1;
digitalWrite(relay6,HIGH);
}
if(x12 == 1){
lcd.setCursor(10,1); 
lcd.print(timer12); 
lcd.print("          ");
timer12--;
if(timer12 <= 0){
timer12 = 0;
digitalWrite(relay6,LOW);
}
}

//====================================================================
if((relay1px == 0)&&(mode == 3)&&(timer13 > 0)&&(x13 == 0)){
x13 = 1;
digitalWrite(relay1,HIGH);
}
if(x13 == 1){
lcd.setCursor(0,0); 
lcd.print(timer13); 
lcd.print("          ");  
timer13--;
if(timer13 <= 0){
timer13 = 0;
digitalWrite(relay1,LOW);
}
}



if((relay2px == 0)&&(mode == 3)&&(timer14 > 0)&&(x14 == 0)){
x14 = 1;
digitalWrite(relay2,HIGH);
}
if(x14 == 1){
lcd.setCursor(0,1); 
lcd.print(timer14); 
lcd.print("          "); 
timer14--;
if(timer14 <= 0){
timer14 = 0;
digitalWrite(relay2,LOW);
}
}


if((relay3px == 0)&&(mode == 3)&&(timer15 > 0)&&(x15 == 0)){
x15 = 1;
digitalWrite(relay3,HIGH);
}
if(x15 == 1){
lcd.setCursor(0,2); 
lcd.print(timer15); 
lcd.print("          ");
timer15--;
if(timer15 <= 0){
timer15 = 0;
digitalWrite(relay3,LOW);
}
}




if((relay4px == 0)&&(mode == 3)&&(timer16 > 0)&&(x16 == 0)){
x16 = 1;
digitalWrite(relay4,HIGH);
}
if(x16 == 1){
lcd.setCursor(0,3); 
lcd.print(timer16); 
lcd.print("          ");
timer16--;
if(timer16 <= 0){
timer16 = 0;
digitalWrite(relay4,LOW);
}
}


if((relay5px == 0)&&(mode == 3)&&(timer17 > 0)&&(x17 == 0)){
x17 = 1;
digitalWrite(relay5,HIGH);
}
if(x17 == 1){
lcd.setCursor(10,0); 
lcd.print(timer17); 
lcd.print("          ");
timer17--;
if(timer17 <= 0){
timer17 = 0;
digitalWrite(relay5,LOW);
}
}

if((relay6px == 0)&&(mode == 3)&&(timer18 > 0)&&(x18 == 0)){
x18 = 1;
digitalWrite(relay6,HIGH);
}
if(x18 == 1){
lcd.setCursor(10,1); 
lcd.print(timer18); 
lcd.print("          ");
timer18--;
if(timer18 <= 0){
timer18 = 0;
digitalWrite(relay6,LOW);
}
}
//==================================================================
if((relay1px == 0)&&(mode == 4)&&(timer19 > 0)&&(x19 == 0)){
x19 = 1; 
digitalWrite(relay1,HIGH);
}
if(x19 == 1){
lcd.setCursor(0,0); 
lcd.print(timer19); 
lcd.print("          ");
timer19--;
if(timer19 <= 0){
timer19 = 0;
digitalWrite(relay1,LOW);
}
}



if((relay2px == 0)&&(mode == 4)&&(timer20 > 0)&&(x20 == 0)){
x20 = 1;
digitalWrite(relay2,HIGH);
}
if(x20 == 1){
lcd.setCursor(0,1); 
lcd.print(timer20); 
lcd.print("          ");
timer20--;
if(timer20 <= 0){
timer20 = 0;
digitalWrite(relay2,LOW);
}
}


if((relay3px == 0)&&(mode == 4)&&(timer21 > 0)&&(x21 == 0)){
x21 = 1;
digitalWrite(relay3,HIGH);
}
if(x21 == 1){
lcd.setCursor(0,2); 
lcd.print(timer21); 
lcd.print("          ");
timer21--;
if(timer21 <= 0){
timer21 = 0;
digitalWrite(relay3,LOW);
}
}


if((relay4px == 0)&&(mode == 4)&&(timer22 > 0)&&(x22 == 0)){
x22 = 1;
digitalWrite(relay4,HIGH);
}
if(x22 == 1){
lcd.setCursor(0,3); 
lcd.print(timer22); 
lcd.print("          ");
timer22--;
if(timer22 <= 0){
timer22 = 0;
digitalWrite(relay4,LOW);
}
}


if((relay5px == 0)&&(mode == 4)&&(timer23 > 0)&&(x23 == 0)){
x23 = 1;
digitalWrite(relay5,HIGH);
}
if(x23 == 1){
lcd.setCursor(10,0); 
lcd.print(timer23); 
lcd.print("          ");
timer23--;
if(timer23 <= 0){
timer23 = 0;
digitalWrite(relay5,LOW);
}
}

if((relay6px == 0)&&(mode == 4)&&(timer24 > 0)&&(x24 == 0)){
x24 = 1;
digitalWrite(relay6,HIGH);
}
if(x24 == 1){
lcd.setCursor(10,1); 
lcd.print(timer24); 
lcd.print("          ");
timer24--;
if(timer24 <= 0){
timer24 = 0;
digitalWrite(relay6,LOW);
}
}


delay(1000);  
counter();
}










void mulai(){
  
  btsetx = digitalRead(btset);
  
  if(btsetx == 0){
  lcd.clear();
  delay(1000);  
  return;
  }

btupx = digitalRead(btup);
btdownx = digitalRead(btdown);

lcd.setCursor(0,0); 
lcd.print("CUCIAN=");
lcd.print(mode);

if(btupx == 0){
  delay(200);
mode++;
}

if(btdownx == 0){
  delay(200);
mode--;
}

if(mode < 1){
mode = 1;
}

if(mode > 4){
mode = 4;
}


if(mode == 1){
lcd.setCursor(0,1); 
lcd.print(timer1);
lcd.print(" ");
lcd.print(timer2);
lcd.print(" ");
lcd.print(timer3);
lcd.print(" ");
lcd.print(timer4);
lcd.print(" ");
lcd.print(timer5);
lcd.print(" ");
lcd.print(timer6);
lcd.print("           ");
}

if(mode == 2){
lcd.setCursor(0,1); 
lcd.print(timer7);
lcd.print(" ");
lcd.print(timer8);
lcd.print(" ");
lcd.print(timer9);
lcd.print(" ");
lcd.print(timer10);
lcd.print(" ");
lcd.print(timer11);
lcd.print(" ");
lcd.print(timer12);
lcd.print("           ");
}

if(mode == 3){
lcd.setCursor(0,1); 
lcd.print(timer13);
lcd.print(" ");
lcd.print(timer14);
lcd.print(" ");
lcd.print(timer15);
lcd.print(" ");
lcd.print(timer16);
lcd.print(" ");
lcd.print(timer17);
lcd.print(" ");
lcd.print(timer18);
lcd.print("           ");
}

if(mode == 4){
lcd.setCursor(0,1); 
lcd.print(timer19);
lcd.print(" ");
lcd.print(timer20);
lcd.print(" ");
lcd.print(timer21);
lcd.print(" ");
lcd.print(timer22);
lcd.print(" ");
lcd.print(timer23);
lcd.print(" ");
lcd.print(timer24);
lcd.print("           ");


mulai();
}


void satu(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 1/1");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer1);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer1++;
}

if(btdownx == 0){
delay(200);
timer1--;
}


if(timer1 < 0){
timer1 = 0;
}

if(btokx == 0){
delay(200);
timer1x = timer1;
return;
}

satu();
}




void dua(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 2/1");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer2);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer2++;
}

if(btdownx == 0){
delay(200);
timer2--;
}

if(timer2 < 0){
timer2 = 0;
}

if(btokx == 0){
delay(200);
timer2x = timer2;
return;
}

dua();
}




void tiga(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 3/1");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer3);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer3++;
}

if(btdownx == 0){
delay(200);
timer3--;
}

if(timer3 < 0){
timer3 = 0;
}

if(btokx == 0){
delay(200);
timer3x = timer3;
return;
}

tiga();
}




void empat(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 4/1");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer4);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer4++;
}

if(btdownx == 0){
delay(200);
timer4--;
}

if(timer4 < 0){
timer4 = 0;
}

if(btokx == 0){
delay(200);
timer4x = timer4;
return;
}

empat();
}





void lima(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 5/1");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer5);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer5++;
}

if(btdownx == 0){
delay(200);
timer5--;
}

if(timer5 < 0){
timer5 = 0;
}

if(btokx == 0){
delay(200);
timer5x = timer5;
return;
}

lima();
}





void enam(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 6/1");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer6);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer6++;
}

if(btdownx == 0){
delay(200);
timer6--;
}

if(timer6 < 0){
timer6 = 0;
}

if(btokx == 0){
delay(200);
timer6x = timer6;
return;
}

enam();
}


//================================================================================


void tujuh(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 1/2");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer7);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer7++;
}

if(btdownx == 0){
delay(200);
timer7--;
}

if(timer7 < 0){
timer7 = 0;
}

if(btokx == 0){
delay(200);
timer7x = timer7;
return;
}

tujuh();
}




void delapan(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 2/2");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer8);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer8++;
}

if(btdownx == 0){
delay(200);
timer8--;
}

if(timer8 < 0){
timer8 = 0;
}

if(btokx == 0){
delay(200);
timer8x = timer8;
return;
}

delapan();
}




void sembilan(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 3/2");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer9);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer9++;
}

if(btdownx == 0){
delay(200);
timer9--;
}

if(timer9 < 0){
timer9 = 0;
}

if(btokx == 0){
delay(200);
timer9x = timer9;
return;
}

sembilan();
}




void sepuluh(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 4/2");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer10);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer10++;
}

if(btdownx == 0){
delay(200);
timer10--;
}

if(timer10 < 0){
timer10 = 0;
}

if(btokx == 0){
delay(200);
timer10x = timer10;
return;
}

sepuluh();
}





void sebelas(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 5/2");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer11);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer11++;
}

if(btdownx == 0){
delay(200);
timer11--;
}

if(timer11 < 0){
timer11 = 0;
}

if(btokx == 0){
delay(200);
timer11x = timer11;
return;
}

sebelas();
}





void duabelas(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 6/2");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer12);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer12++;
}

if(btdownx == 0){
delay(200);
timer12--;
}

if(timer12 < 0){
timer12 = 0;
}

if(btokx == 0){
delay(200);
timer12x = timer12;
return;
}

duabelas();
}

//===========================================================================



void tigabelas(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 1/3");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer13);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer13++;
}

if(btdownx == 0){
delay(200);
timer13--;
}

if(timer13 < 0){
timer13 = 0;
}

if(btokx == 0){
delay(200);
timer13x = timer13;
return;
}

tigabelas();
}




void empatbelas(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 2/3");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer14);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer14++;
}

if(btdownx == 0){
delay(200);
timer14--;
}

if(timer14 < 0){
timer14 = 0;
}

if(btokx == 0){
delay(200);
timer14x = timer14;
return;
}

empatbelas();
}




void limabelas(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 3/3");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer15);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer15++;
}

if(btdownx == 0){
delay(200);
timer15--;
}

if(timer15 < 0){
timer15 = 0;
}

if(btokx == 0){
delay(200);
timer15x = timer15;
return;
}

limabelas();
}




void enambelas(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 4/3");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer16);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer16++;
}

if(btdownx == 0){
delay(200);
timer16--;
}

if(timer16 < 0){
timer16 = 0;
}

if(btokx == 0){
delay(200);
timer16x = timer16;
return;
}

enambelas();
}





void tujuhbelas(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 5/3");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer17);
lcd.print("        ");

if(btupx == 0){
delay(200);
timer17++;
}

if(btdownx == 0){
delay(200);
timer17--;
}

if(timer17 < 0){
timer17 = 0;
}

if(btokx == 0){
delay(200);
timer17x = timer17;
return;
}

tujuhbelas();
}





void delapanbelas(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 6/3");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer18);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer18++;
}

if(btdownx == 0){
delay(200);
timer18--;
}

if(timer18 < 0){
timer18 = 0;
}

if(btokx == 0){
delay(200);
timer18x = timer18;
return;
}

delapanbelas();
}

//===========================================================================




void sembilanbelas(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 1/4");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer19);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer19++;
}

if(btdownx == 0){
delay(200);
timer19--;
}

if(timer19 < 0){
timer19 = 0;
}

if(btokx == 0){
delay(200);
timer19x = timer19;
return;
}

sembilanbelas();
}




void duapuluh(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 2/4");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer20);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer20++;
}

if(btdownx == 0){
delay(200);
timer20--;
}

if(timer20 < 0){
timer20 = 0;
}

if(btokx == 0){
delay(200);
timer20x = timer20;
return;
}

duapuluh();
}




void duapuluhsatu(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 3/4");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer21);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer21++;
}

if(btdownx == 0){
delay(200);
timer21--;
}

if(timer21 < 0){
timer21 = 0;
}

if(btokx == 0){
delay(200);
timer21x = timer21;
return;
}

duapuluhsatu();
}




void duapuluhdua(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 4/4");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer22);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer22++;
}

if(btdownx == 0){
delay(200);
timer22--;
}

if(timer22 < 0){
timer22 = 0;
}

if(btokx == 0){
delay(200);
timer22x = timer22;
return;
}

duapuluhdua();
}





void duapuluhtiga(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 5/4");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer23);
lcd.print("        ");

if(btupx == 0){
delay(200);
timer23++;
}

if(btdownx == 0){
delay(200);
timer23--;
}

if(timer23 < 0){
timer23 = 0;
}

if(btokx == 0){
delay(200);
timer23x = timer23;
return;
}

duapuluhtiga();
}





void duapuluhempat(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("SET TIMER RELAY 6/4");
lcd.setCursor(0,1); 
lcd.print("Detik: ");
lcd.print(timer24);
lcd.print("        ");


if(btupx == 0){
delay(200);
timer24++;
}

if(btdownx == 0){
delay(200);
timer24--;
}

if(timer24 < 0){
timer24 = 0;
}

if(btokx == 0){
delay(200);
timer24x = timer24;
return;
}

duapuluhempat();
}

//===========================================================================



void password(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0); 
lcd.print("PASSWORD= "); 
lcd.print(passwd);
lcd.print("        ");


if(btupx == 0){
delay(200);
passwd++;
}

if(btdownx == 0){
delay(200);
passwd--;
}

if(passwd < 0){
passwd = 0;
}

if((btokx == 0)&&(passwd == 125)){
delay(200);
return;
}

password();
}








e. VIDEO HASILNYA