Kontrol Suhu Ruangan Menggunakan Atmega16 Dan Interface VB6

dapet ide menjelang pagi, seusai melaksanakan sahur, yaitu control suhu ruangan, control suhu ruangan ini berfungsi untuk mengatur suhu ruangan dan disini yang saya maksud adalah ruangan penyimpan makanan, dimana suhu harus tetap stabil, agar makanan tetap awet dan tidak cepat basi,, #saya juga bingung dengan hal ini, kenapa puasa-puasa pikirannya masalah makanan,hehe

berikut screenshootnya :

 
1. seperti biasa yang pertama kita lakukan adalah membuat skema/smulasi di proteus, dan berikut skemanya
setelah merancang skema jangan lupa, seperti biasa setting mikrokontroler dan compimnya, bisa di lihat di bab Membuat Program Led Atmega16 Dengan Interface VB6  setelah itu buka bascom dan copy script di bawah ini:

'=====================
$regfile = "m16def.dat"
$crystal = 8000000
$baud = 9600

Enable Interrupts
Enable Urxc
On Urxc , Inserial


Config Timer1 = Pwm , Prescale = 1024 , Pwm = 10 , _
Compare A Pwm = Clear Down , Compare B Pwm = Clear Down

Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc

Dim Adc1 As Word , Adc2 As Single , Adc3 As Integer

Do
Adc1 = Getadc(0)
Adc2 = Adc1 / 1023
Adc3 = Adc2 * 500
Adc3 = Adc3 Mod 100
Print Chr(adc3)
Waitms 500
Loop

Dim In_s As String * 5
Dim Temp As String * 5
Dim Out_s As Integer

Inserial:
Input In_s
Temp = In_s
In_s = Left(temp , 1)
Out_s = Len(temp) - 1
Temp = Right(temp , Out_s)
Out_s = Val(temp)
Out_s = Out_s * 10

Select Case In_s
Case "!"
Pwm1a = Out_s
Case "@"
Pwm1b = Out_s
Case "#"
Pwm1a = Out_s
Pwm1b = Out_s
End Select

Return
'=====================

2. buka aplikasi vb6 dan buat form-formnya seperti gambar di bawah ini, saya menggunakan 2 form dan 1 module


Form 1 :
ComponentNameCaptionEnabledValueOther
Label1
0truetrueFont = ds-digital
Label2
Warningtruefalsecolor = red
Label3
Max Suhutruetrue
Label4
'Ctruetrue
Label5
Fantruetrue
Label6
Fan 1truetrue
Label7
Fan 2truetrue
Frame1FStatusStatusfalsetrue
Frame2FSetSettingfalsetrue
Frame3FAutoAutofalsetrue
Frame4FManualManualfalsetrue
Text1

truetrue
Option1
Autotruetrue
Option2
Manualtruetrue
Command1
Oktruetrue
Command2
Canceltruetrue
Command3
Ontruetrue
Command4
Offtruetrue
Command5
Ontruetrue
Command6
Offtruetrue
Slider1FanA
truetrueVulue : Max=100 Min=0, Small Change=10
Slider2FanM1
falsetrueVulue : Max=100 Min=0, Small Change=10
Slider3FanM2
falsetrueVulue : Max=100 Min=0, Small Change=10
Timer1

false
Interval = 1
Timer2

false
Interval =300
Timer3

false
Interval = 2000
Msomm1

true

MenueditorComConnecttruetrue

Form 2:
ComponentNameCaptionEnabledValueOther
Label1
Com Port :truetrue
Combo1

truetrue
Command1
Applytruetrue
Command2
Canceltruetrue


berikut script-scriptnya

Form 1 :
'=====================
 Private Sub Com_Click()
If Com.Caption = "Connect" Then
    Me.Enabled = False
    Form2.Visible = True
Else
    MSComm1.Output = "#0" & Chr(13)
    MSComm1.PortOpen = False
    Com.Caption = "Connect"
    FSet.Enabled = False
    Timer1.Enabled = False
    Timer2.Enabled = False
    Timer3.Enabled = False
    Command1.Enabled = True
    Command2.Enabled = True
    Command3.Enabled = True
    Command4.Enabled = True
    Command5.Enabled = True
    Command6.Enabled = True
    Text1.Enabled = True
    FanA.Enabled = True
    FanM1.Enabled = False
    FanM2.Enabled = False
    Label2.Visible = False
    Label1.Caption = "0'C"
    FSet.Enabled = False
    FAuto.Enabled = False
    FManual.Enabled = False
End If
End Sub

Private Sub Command1_Click()
Timer3.Enabled = True
Text1.Enabled = False
FanA.Enabled = False
Command1.Enabled = False
End Sub

Private Sub Command2_Click()
Text1.Enabled = True
FanA.Enabled = True
FSet.Enabled = True
Timer3.Enabled = False
Command1.Enabled = True
End Sub

Private Sub Command3_Click()
FSet.Enabled = False
FanM1.Enabled = True
End Sub
Private Sub Command4_Click()
On Error Resume Next
FanM1.Enabled = False
MSComm1.Output = "!0" & Chr(13)
If FanM1.Enabled = False And FanM2.Enabled = False Then FSet.Enabled = True
End Sub
Private Sub Command5_Click()
FSet.Enabled = False
FanM2.Enabled = True
End Sub
Private Sub Command6_Click()
On Error Resume Next
FanM2.Enabled = False
MSComm1.Output = "@0" & Chr(13)
If FanM1.Enabled = False And FanM2.Enabled = False Then FSet.Enabled = True
End Sub

Private Sub FanM1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
On Error Resume Next
MSComm1.Output = "!" & FanM1.Value & Chr(13)
End Sub

Private Sub FanM2_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
On Error Resume Next
MSComm1.Output = "@" & FanM2.Value & Chr(13)
End Sub

Private Sub Form_Load()
Label1.Caption = "0'C"
Text1.MaxLength = 3
End Sub

Private Sub Option1_Click()
FAuto.Enabled = True
FManual.Enabled = False
Timer3.Enabled = True
End Sub
Private Sub Option2_Click()
FAuto.Enabled = False
FManual.Enabled = True
Timer3.Enabled = False
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = 8 Then Exit Sub
If KeyAscii = 13 Then FanA.SetFocus

If Len(Text1.Text) = 0 And KeyAscii = 48 Then KeyAscii = 13

If KeyAscii < 48 Or KeyAscii > 57 Then
    KeyAscii = 13
End If

End Sub

Private Sub Text1_LostFocus()
On Error GoTo err
If Text1.Text > 100 Then
    MessageBox Me.hwnd, "Error!! Batas Suhu Max 100" & Chr(176) & "C", "Created By Ganang", vbCritical
    Text1.SetFocus
End If
err:
End Sub

Private Sub Timer1_Timer()
On Error Resume Next

Dim Temp As String

Temp = Asc(MSComm1.Input)
If Temp <> "" Then
    Label1.Caption = Temp & "'C"
End If

End Sub

Private Sub Timer2_Timer()
Dim Temps As Integer
Temps = Abs(Left(Label1.Caption, Len(Label1.Caption) - 2))

If Left(Label1.Caption, Len(Label1.Caption) - 2) > 60 Then
    If Label2.Visible = True Then
        Label2.Visible = False
    Else
        Label2.Visible = True
    End If
Else
    Label2.Visible = False
End If

End Sub

Private Sub Timer3_Timer()
On Error Resume Next

If Left(Label1.Caption, Len(Label1.Caption) - 2) > Trim(Text1.Text) Then
    MSComm1.Output = "#" & FanA.Value & Chr(13)
Else
    MSComm1.Output = "#0" & Chr(13)
End If

End Sub
'=====================

 Form2 :
'=====================
Private Function Com() As String
On Error GoTo err

With Form1
.MSComm1.CommPort = Right(Trim(Combo1.Text), 1)
.MSComm1.PortOpen = True
.FSet.Enabled = True
.Timer1.Enabled = True
.Timer2.Enabled = True
.Com.Caption = "Disconnect"
End With
Exit Function

err:
Com = "err"
MessageBox Me.hwnd, "Error!! Tidak Dapat Terhubung", "Created By ganang", vbCritical
End Function

Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    If Com = "err" Then Exit Sub
    Unload Me
End If
End Sub

Private Sub Command1_Click()
If Com = "err" Then Exit Sub
Unload Me
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
Dim i As Byte

Combo1.Clear
For i = 1 To 15
    Combo1.AddItem "Com " & i
Next i
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Form1.Enabled = True
    Form1.Show
End Sub
'=====================

Module :
'=====================
 Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
'=====================

Setelah selesai semua koneksikan mikrokotroler dan vb6 dengan vspe, bab ini sudah di bahas pada Membuat Program Led Atmega16 Dengan Interface VB6 ,


@catatan : masih ada sedikit bug saat simulasi

moga bermanfaat bagi agan-agan yang ingin mencobanya,
moga berhasil mencobanya..


Download http://adf.ly/1ZL0or
kontak saya ganyang.angkara@yahoo.com
password ganyang-angkara.blogspot.com

*..sesama blogger harus saling menghargai, jika agan-agan ingin mengcopas harap cantumkan alamat urlnya, Terimakasih..*