Translate

Visual basic 6 (VB 6) + Database Ms. Access Kendali Arduino

Visual basic 6 (VB 6) + Database Ms. Access Kendali Arduino


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah interface dengan menggunakan visual basic 6 (VB 6) dengan fitur yang bisa mengendalikan arduino berdasarkan data yang ada pada database. jika orang tersebut sudah terdaftar maka akan bisa menghidupkan led pada arduino namun jika belum terdaftar maka tidak akan bisa menghidupkan led pada arduino. led pada arduino bisa diganti relay sehingga bisa mengendalikan solenoid door lock atau perangkat yang lain. untuk lebih jelasnya berikut koding dan komponennya.



a. Arduino Uno





b. Program Arduno IDE

#include <SPI.h>
#include <MFRC522.h>

String ok_rfid_1="2227e534";           // Kartu utama RFID Card
String ok_rfid_2="b9532dce";
String ok_rfid_3="123456ty";
String ok_rfid_4="4546ghgh";
String ok_rfid_5="1sd56hn4";
String ok_rfid_6="167bhb56";

int x = 1;
int datain;
int cacah = 1;

int led = A0;

void setup() {
    Serial.begin(9600);         

    pinMode(led, OUTPUT);
    digitalWrite(led,HIGH);
}


void loop() {

if (Serial.available() > 0)
{
datain = Serial.parseInt();

if(datain == 2){
cacah++;
datain = 0;
}

if(datain == 1){
digitalWrite(led,LOW);
delay(3000);
digitalWrite(led,HIGH);
}

if(cacah > 6){
  cacah = 1;
  } 

}

if(cacah == 1){
Serial.println(ok_rfid_1);
}

if(cacah == 2){
Serial.println(ok_rfid_2);
}

if(cacah == 3){
Serial.println(ok_rfid_3);
}

if(cacah == 4){
Serial.println(ok_rfid_4);
}

if(cacah == 5){
Serial.println(ok_rfid_5);
}

if(cacah == 6){
Serial.println(ok_rfid_6);
}

delay(1000);
  
}




c. Program Interface VB 6



'===== Main Form ========
Dim Conn1 As ADODB.Connection
Dim Cmd1 As ADODB.Command
Dim Param1 As ADODB.Parameter
Dim Rs1 As ADODB.Recordset


Private Sub cbdelete_Click()
Dim SQl As String
    
    Call dbConnect
    
    SQl = "DELETE FROM Table1 WHERE Kode = '" & tbkode.Text & "'"
    
    Dim Rs As Recordset
    Set Rs = New ADODB.Recordset
    Rs.Open SQl, Conn, adOpenDynamic, adLockOptimistic
    
    tbkode.Text = ""
    tbnama.Text = ""
    tbstatus.Text = ""
    tbalamat.Text = ""
    
End Sub

Private Sub cbinsert_Click()
Dim SQl As String
    
   Call dbConnect
    If pass.Text = "1234" Then
    SQl = "INSERT INTO Table1 VALUES('" & tbkode.Text & "','" & tbnama.Text & "','" & tbstatus.Text & "','" & tbalamat.Text & "')"
    
    Dim Rs As Recordset
    Set Rs = New ADODB.Recordset
    Rs.Open SQl, Conn, adOpenDynamic
    tbkode.Text = ""
    tbnama.Text = ""
    tbstatus.Text = ""
    tbalamat.Text = ""
    pass.Text = ""
    End If
    
End Sub

Private Sub cbselect_Click()
Dim SQl As String
    
    Call dbConnect
    
    SQl = "Select * from Table1  where Kode = '" & tbkode.Text & "'"
    
    Dim Rs As Recordset
    Set Rs = New ADODB.Recordset
    Rs.Open SQl, Conn, adOpenDynamic, adLockOptimistic
    
    If Not Rs.EOF Then
        Text1.Text = Rs!Nama
        Text2.Text = Rs!Status
        Text3.Text = Rs!Alamat
    End If
End Sub

Private Sub cmdConnect_Click()
Dim port As Integer
On Error GoTo errcode

If MSComm1.PortOpen = False Then
    MSComm1.CommPort = Combo1.ListIndex + 1
    MSComm1.RThreshold = 1
    MSComm1.InputLen = 0
    MSComm1.Settings = Combo2.List(Combo2.ListIndex) & ",N,8,1"
    MSComm1.PortOpen = True
cmdConnect.Enabled = False
cmdDisconnect.Enabled = True
End If
 
Exit Sub

errcode:
    MsgBox "Port Salah !", vbOKOnly, "Peringatan"
    Combo1.SetFocus


End Sub

Private Sub cmdDisconnect_Click()
If MSComm1.PortOpen = True Then
    MSComm1.PortOpen = False
End If
cmdConnect.Enabled = True
cmdDisconnect.Enabled = False

End Sub

Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Command2_Click()

If Text1.Text <> "" And Text2.Text <> "" And Text3.Text <> "" Then
MSComm1.Output = "1" + Chr(13)

Text1.Text = ""
Text2.Text = ""
Text3.Text = ""

End If

End Sub

Private Sub Command3_Click()
MSComm1.Output = "2" + Chr(13)
End Sub

Private Sub Form_Load()
Dim i As Byte
For i = 1 To 16
Combo1.AddItem (i)
Next i
With Combo2
        .AddItem "2400"
        .AddItem "4800"
        .AddItem "9600"
        .AddItem "19200"
        .AddItem "38400"
        .AddItem "56600"
        
End With
Timer2.Enabled = False
cmdConnect.Enabled = True
cmdDisconnect.Enabled = False
End Sub

Private Sub Timer1_Timer()
Adodc2.Refresh

If Text1.Text <> "" Then
Command2.Enabled = True
End If

If Text1.Text = "" Then
Command2.Enabled = False
End If

End Sub


Private Sub Timer2_Timer()
MSComm1_OnComm
End Sub

Private Sub Timer3_Timer()
Dim data As String
Dim jumlah As String

        Dim buffer As String
        If MSComm1.InBufferCount > 0 Then
            'tbkode.Text = ""
            'tbnama.Text = ""
            'tbstatus.Text = ""
            'tbalamat.Text = ""
          
        buffer = MSComm1.Input
        data = Mid$(buffer, 1, 8)
        'jumlah = Mid$(buffer, 15, 1)
        
        tbkode.Text = data
        'Text1.Text = jumlah
        
              
        End If
End Sub



'======= Module =====
Public Conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public SQl As String
Public i As Byte

Public Sub dbConnect()
Set Conn = New ADODB.Connection
Conn.ConnectionString = strConn
Conn.Open
End Sub

Public Function strConn() As String
Set Conn = New ADODB.Connection
Set Rs = New ADODB.Recordset
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Acer\Desktop\Kodingku\interface\Database1.mdb;Persist Security Info=False"

End Function




d. VIDEO HASILNYA







No comments:

Post a Comment