SlideShare a Scribd company logo
1 of 7
LAMPIRAN
1. Kodingan pada Arduino
const int buttonPin1 = 14;
// the number of the pushbutton
pin
const int buttonPin2 = 15;
// the number of the pushbutton
pin
const int buttonPin3 = 16;
// the number of the pushbutton
pin
const int buttonPin4 = 17;
// the number of the pushbutton
pin
const int buttonPin5 = 18;
// the number of the pushbutton
pin
const int ledPin1 = 12; //
the number of the LED pin
const int ledPin2 = 11; //
const int ledPin3 = 10; //
the number of the LED pin
const int ledPin4 = 9; //
// variables will change:
int sensor1 = 0; //
variable for reading the
pushbutton status
int sensor2 = 0; //
variable for reading the
pushbutton status
int sensor3 = 0; //
variable for reading the
pushbutton status
int sensor4 = 0; //
variable for reading the
pushbutton status
int sensor_ir = 0; //
variable for reading the
pushbutton status
int AWAL=0;
int REAL=0;
int k1=0;
int k2=0;
int k3=0;
int k4=0;
void setup() {
Serial.begin(9600);
// initialize the LED pin as
an output:
pinMode(ledPin1,
OUTPUT);
pinMode(ledPin2,
OUTPUT);
pinMode(ledPin3,
OUTPUT);
pinMode(ledPin4,
OUTPUT);
// initialize the pushbutton
pin as an input:
pinMode(buttonPin1,
INPUT);
pinMode(buttonPin2,
INPUT);
pinMode(buttonPin3,
INPUT);
pinMode(buttonPin4,
INPUT);
pinMode(buttonPin5,
INPUT);
//inputString.reserve(200);
}
void loop(){
sensor1 =
digitalRead(buttonPin1);
sensor2 =
digitalRead(buttonPin2);
sensor3 =
digitalRead(buttonPin3);
sensor4 =
digitalRead(buttonPin4);
sensor_ir =
digitalRead(buttonPin5);
if (sensor4 == HIGH){
REAL=4;
if(k4==0){
if(AWAL>=4){
AWAL=4;
Serial.println("D");
digitalWrite(ledPin1,
HIGH);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
HIGH);
digitalWrite(ledPin4,
LOW);
delay(250);
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
LOW);
}
else{
AWAL=4;
Serial.println("d");
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
HIGH);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
HIGH);
delay(200);
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
LOW);
Serial.println('d');
}
k4=1;
k3=0;
k2=0;
k1=0;
}
}//SENSOR4
//===================
========================
========================
else if (sensor3 == HIGH){
REAL=3;
if(k3==0){
if(AWAL>=3){
AWAL=3;
Serial.println('C');
digitalWrite(ledPin1,
HIGH);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
HIGH);
digitalWrite(ledPin4,
LOW);
delay(250);
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
LOW);
}
else{
AWAL=3;
Serial.println('c');
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
HIGH);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
HIGH);
delay(200);
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
LOW);
}
k4=0;
k3=1;
k2=0;
k1=0;
}
}//SENSOR3
//===================
========================
========================
else if (sensor2 == HIGH){
REAL=2;
if(k2==0){
if(AWAL>=2){
AWAL=2;
Serial.println('B');
digitalWrite(ledPin1,
HIGH);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
HIGH);
digitalWrite(ledPin4,
LOW);
delay(250);
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
LOW);
}
else{
AWAL=2;
Serial.println('b');
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
HIGH);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
HIGH);
delay(200);
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
LOW);
}
k4=0;
k3=0;
k2=1;
k1=0;
}
}//SENSOR2
//===================
========================
========================
else if (sensor1 == HIGH){
REAL=1;
if(k1==0){
if(AWAL>=1){
AWAL=1;
Serial.println('A');
digitalWrite(ledPin1,
HIGH);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
HIGH);
digitalWrite(ledPin4,
LOW);
delay(250);
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
LOW);
}
else{
AWAL=1;
Serial.println('a');
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
HIGH);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
HIGH);
delay(200);
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
LOW);
}
k4=0;
k3=0;
k2=0;
k1=1;
}
}//SENSOR1
else if (sensor1 == LOW){
if(k1==1){
AWAL=0;
Serial.println('A');
digitalWrite(ledPin1,
HIGH);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
HIGH);
digitalWrite(ledPin4,
LOW);
delay(200);
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
LOW);
k1=0;
}
}
//===================
========================
========================
else{
digitalWrite(ledPin1,
LOW);
digitalWrite(ledPin2,
LOW);
digitalWrite(ledPin3,
LOW);
digitalWrite(ledPin4,
LOW);
delay(200);
}
}//LOOP
2. Kodingan pada Visual Basic
Dim status As Boolean
Dim mydata1 As String
Dim mydata2 As String
Private Sub Form_Click()
Call baca
End Sub
Private Sub Form_Load()
status = False
mydata1 = "A"
mydata2 = "a"
End Sub
Private Sub ljam_Click()
Call baca
End Sub
Sub baca()
Dim com As String
On Error GoTo salah
If status = False Then
com =
InputBox("Masukkan Port Arduino", "Input
COM", "4")
If MSComm.PortOpen =
False Then
MSComm.CommPort =
Val(com)
MSComm.PortOpen =
True
MsgBox "koneksi
berhasil....", vbInformation + vbOKOnly,
"sukses"
End If
tmr.Enabled = True
status = True
Me.WindowState = 1
Else
Dim dis As String
dis = MsgBox("anda ingin
menutup koneksi?", vbQuestion + vbYesNo,
"Diskoneksi")
If dis = vbYes Then
If MSComm.PortOpen =
True Then
MSComm.PortOpen =
False
End If
tmr.Enabled = False
status = False
MsgBox "DisKoneksi
Berhasil", vbInformation + vbOKOnly,
"Diskonek"
End If
End If
Exit Sub
salah:
MsgBox "Koneksi
Gagal...cek koneksi port name Anda",
vbInformation + vbOKOnly, "Cek COMM"
End Sub
Private Sub tmr_Timer()
Dim buff As Variant
Dim jam, mnt, detik As
String
jam = Format(Time, "hh")
mnt = Format(Time, "mm")
dtk = Format(Time, "ss")
If Len(jam) < 2 Then
jam = "0" & jam
End If
If Len(mnt) < 2 Then
mnt = "0" & mnt
End If
If Len(dtk) < 2 Then
dtk = "0" & dtk
End If
ljam.Caption = jam & ":" &
mnt & ":" & dtk & " WIB"
ljam.ForeColor =
QBColor(Rnd * 13)
If MSComm.PortOpen =
True Then
buff = MSComm.Input
buff = Trim(buff)
mydata1 = buff
If mydata1 = mydata2
Then
'diam saja
Else
Me.Caption = ".:" &
mydata1 & ":."
myata2 = mydata1
If InStr(buff, "A") > 0
Then
simpan ("A")
ElseIf InStr(buff, "a") >
0 Then
simpan ("a")
ElseIf InStr(buff, "B")
> 0 Then
simpan ("B")
ElseIf InStr(buff, "b") >
0 Then
simpan ("b")
ElseIf InStr(buff, "C")
> 0 Then
simpan ("C")
ElseIf InStr(buff, "c") >
0 Then
simpan ("c")
ElseIf InStr(buff, "D")
> 0 Then
simpan ("D")
ElseIf InStr(buff, "d") >
0 Then
simpan ("d")
End If
End If
End If
End Sub
Sub simpan(ByVal data As
String)
Dim artidata, ket As String
If data = "A" Then
artidata = "Siaga 4"
ket = "Arah Turun"
ElseIf data = "a" Then
artidata = "Siaga 4"
ket = "Arah Naik"
ElseIf data = "B" Then
artidata = "Siaga 3"
ket = "Arah Turun"
ElseIf data = "b" Then
artidata = "Siaga 3"
ket = "Arah Naik"
ElseIf data = "C" Then
artidata = "Siaga 2"
ket = "Arah Turun"
ElseIf data = "c" Then
artidata = "Siaga 2"
ket = "Arah Naik"
ElseIf data = "D" Then
artidata = "Siaga 1"
ket = "Arah Turun"
ElseIf data = "d" Then
artidata = "Siaga 1"
ket = "Arah Naik"
End If
adoproses.RecordSource =
"select * from tb_pintu1"
adoproses.Refresh
With adoproses.Recordset
.AddNew
!inisial = data
!siaga = artidata
!tanggal = Format(Date,
"yyyy-mm-dd")
!jam = Format(Time,
"hh:mm:ss")
!keterangan = ket
.Update
End With
adoproses.Refresh
adoproses2.RecordSource =
"select * from tb_pintu2"
adoproses2.Refresh
With adoproses2.Recordset
.AddNew
!inisial = data
!siaga = artidata
!tanggal = Format(Date,
"yyyy-mm-dd")
!jam = Format(Time,
"hh:mm:ss")
!keterangan = ket
.Update
End With
adoproses2.Refresh
End Sub

More Related Content

What's hot

Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象
勇浩 赖
 
Reverse Engineering: C++ "for" operator
Reverse Engineering: C++ "for" operatorReverse Engineering: C++ "for" operator
Reverse Engineering: C++ "for" operator
erithion
 

What's hot (11)

Workshop Swift
Workshop Swift Workshop Swift
Workshop Swift
 
C++: The Cathedral and the Bizarre
C++: The Cathedral and the BizarreC++: The Cathedral and the Bizarre
C++: The Cathedral and the Bizarre
 
Sine Wave Generator with controllable frequency displayed on a seven segment ...
Sine Wave Generator with controllable frequency displayed on a seven segment ...Sine Wave Generator with controllable frequency displayed on a seven segment ...
Sine Wave Generator with controllable frequency displayed on a seven segment ...
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象
 
Алексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhereАлексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhere
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
 
Endless fun with Arduino and Eventmachine
Endless fun with Arduino and EventmachineEndless fun with Arduino and Eventmachine
Endless fun with Arduino and Eventmachine
 
Reverse Engineering: C++ "for" operator
Reverse Engineering: C++ "for" operatorReverse Engineering: C++ "for" operator
Reverse Engineering: C++ "for" operator
 
Embedding perl
Embedding perlEmbedding perl
Embedding perl
 
The evolution of asynchronous JavaScript
The evolution of asynchronous JavaScriptThe evolution of asynchronous JavaScript
The evolution of asynchronous JavaScript
 
bash
bashbash
bash
 

Similar to Lampiran

Yolygambas
YolygambasYolygambas
Yolygambas
rosyp
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
akaptur
 

Similar to Lampiran (20)

Ch4
Ch4Ch4
Ch4
 
Arduino workshop
Arduino workshopArduino workshop
Arduino workshop
 
C++ Programming - 4th Study
C++ Programming - 4th StudyC++ Programming - 4th Study
C++ Programming - 4th Study
 
Handling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUsHandling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUs
 
深入淺出C語言
深入淺出C語言深入淺出C語言
深入淺出C語言
 
Introduction to Kotlin.pptx
Introduction to Kotlin.pptxIntroduction to Kotlin.pptx
Introduction to Kotlin.pptx
 
01 Introduction to Kotlin - Programming in Kotlin.pptx
01 Introduction to Kotlin - Programming in Kotlin.pptx01 Introduction to Kotlin - Programming in Kotlin.pptx
01 Introduction to Kotlin - Programming in Kotlin.pptx
 
Intro to c programming
Intro to c programmingIntro to c programming
Intro to c programming
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
 
Gambas
Gambas Gambas
Gambas
 
Arduino cic3
Arduino cic3Arduino cic3
Arduino cic3
 
Calculadora
CalculadoraCalculadora
Calculadora
 
Safe int
Safe intSafe int
Safe int
 
Yolygambas
YolygambasYolygambas
Yolygambas
 
Yolygambas
YolygambasYolygambas
Yolygambas
 
Yolygambas
YolygambasYolygambas
Yolygambas
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
 
Burrowing through go! the book
Burrowing through go! the bookBurrowing through go! the book
Burrowing through go! the book
 
Programming ATmega microcontroller using Embedded C
Programming ATmega microcontroller using Embedded CProgramming ATmega microcontroller using Embedded C
Programming ATmega microcontroller using Embedded C
 

Recently uploaded

DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 

Recently uploaded (20)

NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 

Lampiran

  • 1. LAMPIRAN 1. Kodingan pada Arduino const int buttonPin1 = 14; // the number of the pushbutton pin const int buttonPin2 = 15; // the number of the pushbutton pin const int buttonPin3 = 16; // the number of the pushbutton pin const int buttonPin4 = 17; // the number of the pushbutton pin const int buttonPin5 = 18; // the number of the pushbutton pin const int ledPin1 = 12; // the number of the LED pin const int ledPin2 = 11; // const int ledPin3 = 10; // the number of the LED pin const int ledPin4 = 9; // // variables will change: int sensor1 = 0; // variable for reading the pushbutton status int sensor2 = 0; // variable for reading the pushbutton status int sensor3 = 0; // variable for reading the pushbutton status int sensor4 = 0; // variable for reading the pushbutton status int sensor_ir = 0; // variable for reading the pushbutton status int AWAL=0; int REAL=0; int k1=0; int k2=0; int k3=0; int k4=0; void setup() { Serial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); pinMode(ledPin4, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin1, INPUT); pinMode(buttonPin2, INPUT); pinMode(buttonPin3, INPUT); pinMode(buttonPin4, INPUT); pinMode(buttonPin5, INPUT); //inputString.reserve(200); } void loop(){ sensor1 = digitalRead(buttonPin1); sensor2 = digitalRead(buttonPin2); sensor3 = digitalRead(buttonPin3); sensor4 = digitalRead(buttonPin4); sensor_ir = digitalRead(buttonPin5);
  • 2. if (sensor4 == HIGH){ REAL=4; if(k4==0){ if(AWAL>=4){ AWAL=4; Serial.println("D"); digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, HIGH); digitalWrite(ledPin4, LOW); delay(250); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); } else{ AWAL=4; Serial.println("d"); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, HIGH); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, HIGH); delay(200); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); Serial.println('d'); } k4=1; k3=0; k2=0; k1=0; } }//SENSOR4 //=================== ======================== ======================== else if (sensor3 == HIGH){ REAL=3; if(k3==0){ if(AWAL>=3){ AWAL=3; Serial.println('C'); digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, HIGH); digitalWrite(ledPin4, LOW); delay(250); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); } else{ AWAL=3; Serial.println('c'); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, HIGH);
  • 3. digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, HIGH); delay(200); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); } k4=0; k3=1; k2=0; k1=0; } }//SENSOR3 //=================== ======================== ======================== else if (sensor2 == HIGH){ REAL=2; if(k2==0){ if(AWAL>=2){ AWAL=2; Serial.println('B'); digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, HIGH); digitalWrite(ledPin4, LOW); delay(250); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); } else{ AWAL=2; Serial.println('b'); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, HIGH); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, HIGH); delay(200); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); } k4=0; k3=0; k2=1; k1=0; } }//SENSOR2 //=================== ======================== ======================== else if (sensor1 == HIGH){ REAL=1; if(k1==0){ if(AWAL>=1){ AWAL=1; Serial.println('A'); digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, HIGH);
  • 4. digitalWrite(ledPin4, LOW); delay(250); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); } else{ AWAL=1; Serial.println('a'); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, HIGH); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, HIGH); delay(200); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); } k4=0; k3=0; k2=0; k1=1; } }//SENSOR1 else if (sensor1 == LOW){ if(k1==1){ AWAL=0; Serial.println('A'); digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, HIGH); digitalWrite(ledPin4, LOW); delay(200); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); k1=0; } } //=================== ======================== ======================== else{ digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); delay(200); } }//LOOP 2. Kodingan pada Visual Basic Dim status As Boolean Dim mydata1 As String Dim mydata2 As String
  • 5. Private Sub Form_Click() Call baca End Sub Private Sub Form_Load() status = False mydata1 = "A" mydata2 = "a" End Sub Private Sub ljam_Click() Call baca End Sub Sub baca() Dim com As String On Error GoTo salah If status = False Then com = InputBox("Masukkan Port Arduino", "Input COM", "4") If MSComm.PortOpen = False Then MSComm.CommPort = Val(com) MSComm.PortOpen = True MsgBox "koneksi berhasil....", vbInformation + vbOKOnly, "sukses" End If tmr.Enabled = True status = True Me.WindowState = 1 Else Dim dis As String dis = MsgBox("anda ingin menutup koneksi?", vbQuestion + vbYesNo, "Diskoneksi") If dis = vbYes Then If MSComm.PortOpen = True Then MSComm.PortOpen = False End If tmr.Enabled = False status = False MsgBox "DisKoneksi Berhasil", vbInformation + vbOKOnly, "Diskonek" End If End If Exit Sub salah: MsgBox "Koneksi Gagal...cek koneksi port name Anda", vbInformation + vbOKOnly, "Cek COMM" End Sub Private Sub tmr_Timer() Dim buff As Variant Dim jam, mnt, detik As String jam = Format(Time, "hh")
  • 6. mnt = Format(Time, "mm") dtk = Format(Time, "ss") If Len(jam) < 2 Then jam = "0" & jam End If If Len(mnt) < 2 Then mnt = "0" & mnt End If If Len(dtk) < 2 Then dtk = "0" & dtk End If ljam.Caption = jam & ":" & mnt & ":" & dtk & " WIB" ljam.ForeColor = QBColor(Rnd * 13) If MSComm.PortOpen = True Then buff = MSComm.Input buff = Trim(buff) mydata1 = buff If mydata1 = mydata2 Then 'diam saja Else Me.Caption = ".:" & mydata1 & ":." myata2 = mydata1 If InStr(buff, "A") > 0 Then simpan ("A") ElseIf InStr(buff, "a") > 0 Then simpan ("a") ElseIf InStr(buff, "B") > 0 Then simpan ("B") ElseIf InStr(buff, "b") > 0 Then simpan ("b") ElseIf InStr(buff, "C") > 0 Then simpan ("C") ElseIf InStr(buff, "c") > 0 Then simpan ("c") ElseIf InStr(buff, "D") > 0 Then simpan ("D") ElseIf InStr(buff, "d") > 0 Then simpan ("d") End If End If End If End Sub Sub simpan(ByVal data As String) Dim artidata, ket As String If data = "A" Then artidata = "Siaga 4" ket = "Arah Turun" ElseIf data = "a" Then artidata = "Siaga 4"
  • 7. ket = "Arah Naik" ElseIf data = "B" Then artidata = "Siaga 3" ket = "Arah Turun" ElseIf data = "b" Then artidata = "Siaga 3" ket = "Arah Naik" ElseIf data = "C" Then artidata = "Siaga 2" ket = "Arah Turun" ElseIf data = "c" Then artidata = "Siaga 2" ket = "Arah Naik" ElseIf data = "D" Then artidata = "Siaga 1" ket = "Arah Turun" ElseIf data = "d" Then artidata = "Siaga 1" ket = "Arah Naik" End If adoproses.RecordSource = "select * from tb_pintu1" adoproses.Refresh With adoproses.Recordset .AddNew !inisial = data !siaga = artidata !tanggal = Format(Date, "yyyy-mm-dd") !jam = Format(Time, "hh:mm:ss") !keterangan = ket .Update End With adoproses.Refresh adoproses2.RecordSource = "select * from tb_pintu2" adoproses2.Refresh With adoproses2.Recordset .AddNew !inisial = data !siaga = artidata !tanggal = Format(Date, "yyyy-mm-dd") !jam = Format(Time, "hh:mm:ss") !keterangan = ket .Update End With adoproses2.Refresh End Sub