Selamat Sore… :)
Kali ini saya akan membagikan sedikit pengetahuan tentang
komunikasi serial sederhana, dimana kita akan mengkomunikasikan mikrokontroler
(Arduino) dengan Komputer menggunakan software Microsoft Visual Basic 6.0.Pada proyek
ini kita membutuhkan beberapa peralatan, yaitu :
- Arduino (dalam proyek ini saya menggunakan arduino nano).
- 5 buah led untuk indicator komunikasi serial ke arduino
- kabel jumper secukupnya.
Adapun untuk proses pengerjaannya sbb:
- Siapkan Alat dan bahan
- rangkaian seperti gambar di bawah ini:
char t;
void setup()
{
for(int i=2;i<=6;i++)
{
pinMode(i,OUTPUT);
digitalWrite(i,LOW);
}
Serial.begin(9600);
}
void loop()
{
while(Serial.available()>0)
{
t=Serial.read();
}
switch(t)
{
case 'a': digitalWrite(2,HIGH);break;
case 'b': digitalWrite(3,HIGH);break;
case 'c': digitalWrite(4,HIGH);break;
case 'd': digitalWrite(5,HIGH);break;
case 'e': digitalWrite(6,HIGH);break;
case 'v': digitalWrite(2,LOW);break;
case 'w': digitalWrite(3,LOW);break;
case 'x': digitalWrite(4,LOW);break;
case 'y': digitalWrite(5,LOW);break;
case 'z': digitalWrite(6,LOW);break;
}
}
11. Aturlah Propertiesnya Seperti berikut ini
Dim port As Integer
Private Sub Check1_Click()
If Check1.Value = 1 Then
Shape1.FillColor = vbRed
MSComm1.Output = "a" & vbCrLf
Else
Shape1.FillColor = &H40&
MSComm1.Output = "v" & vbCrLf
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then
Shape2.FillColor = vbRed
MSComm1.Output = "b" & vbCrLf
Else
Shape2.FillColor = &H40&
MSComm1.Output = "w" & vbCrLf
End If
End Sub
Private Sub Check3_Click()
If Check3.Value = 1 Then
Shape3.FillColor = vbRed
MSComm1.Output = "c" & vbCrLf
Else
Shape3.FillColor = &H40&
MSComm1.Output = "x" & vbCrLf
End If
End Sub
Private Sub Check4_Click()
If Check4.Value = 1 Then
Shape4.FillColor = vbRed
MSComm1.Output = "d" & vbCrLf
Else
Shape4.FillColor = &H40&
MSComm1.Output = "y" & vbCrLf
End If
End Sub
Private Sub Check5_Click()
If Check5.Value = 1 Then
Shape5.FillColor = vbRed
MSComm1.Output = "e" & vbCrLf
Else
Shape5.FillColor = &H40&
MSComm1.Output = "z" & vbCrLf
End If
End Sub
Private Sub cmdconnect_Click()
MSComm1.CommPort = Val(Combo1.Text)
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
MsgBox "Koneksi Berhasil !", vbInformation, "Sukses"
Frame1.Enabled = True
Combo1.Enabled = False
cmdconnect.Enabled = False
End Sub
Private Sub cmdexit_Click()
End
End Sub
Private Sub Form_Load()
For port = 1 To 20
Combo1.AddItem port
Next port
Frame1.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
14. masukkan communication port number dan tekan sambung.
Demikian tutorial sederhana ini, mudah2an bisa dimengerti. silahkan dikembangkan lai bagi yang ingin meningkatkan ilmunya...:)
kalau mau download semua program vb6 dan arduino dapat dibuka disini
Terima Kasih.....:D