Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk monitor suhu menggunakan sensor DHT11, alat ini dilengkapi dengan buzzer sebagai indikator ketika suhu telah melewati batas dari suhu yang disetting. alat ini dilengkapi dengan 2 buah indikator yatu led dan buzzer. untuk setting batas suhu menggunakan tombol. kemudian ada komunikasi serial RS232 untuk mengirimkan kata-kata WARNING saat suhu melebihi batas. untuk leih jelasnya berikut adalah skema dan programnya.
a. Minimum System ATMega8
b. Sensor DHT11
c. Program Bascom AVR
$regfile = "m8def.dat"
$crystal = 12000000
$baud = 9600
'--------------------------
Config Lcdpin = Pin , Rs = Portd.7 , E = Portb.1 , Db4 = Portb.2
Config Lcdpin = Pin , Db5 = Portb.3 , Db6 = Portb.4 , Db7 = Portb.5
Config Lcd = 16 * 2
Cursor Off
Cls
'led
Ddrc.4 = 1
Ddrc.5 = 1
'buzzer
Ddrd.6 = 1
'pushbutton
Ddrd.4 = 0
Ddrd.3 = 0
Ddrd.2 = 0
Ddrd.5 = 0
'aktif low pushbutton
Portd.4 = 1
Portd.3 = 1
Portd.2 = 1
Portd.5 = 1
Pbset Alias Pind.4
Pbdown Alias Pind.3
Pbup Alias Pind.2
Pbok Alias Pind.5
Declare Sub Get_th(t As Byte , H As Byte)
Config Serialin = Buffered , Size = 128
Config Serialout = Buffered , Size = 128
Dht_put Alias Portb.0
Dht_get Alias Pinb.0
Dht_io_set Alias Ddrb.0
Dim T As Byte
Dim H As Byte
Dim Crc As Byte
Dim Mybyte As Byte
Dim Sensor_data As String * 40
Dim Tmp_str8 As String * 8
Dim Count As Byte
Enable Interrupts
Set Dht_io_set
Set Dht_put
Dim Nilai As Integer
Portc.4 = 0
Portc.5 = 0
Portd.6 = 1
Utama:
Do
Waitms 1500
Call Get_th(t , H)
Upperline
Lcd "SUHU: " ; T ; " C "
Lowerline
Lcd "BATAS: " ; Nilai ; " C "
If Pbset = 0 Then
Waitms 200
Cls
Wait 1
Goto Setting
End If
If Nilai > 0 And T > Nilai Then
Portc.4 = 0
Portc.5 = 1
Portd.6 = 0
Print "bahaya"
End If
If Nilai > 0 And T <= Nilai Then
Portc.4 = 1
Portc.5 = 0
Portd.6 = 1
End If
Loop
Sub Get_th(t As Byte , H As Byte)
Count = 0
Sensor_data = ""
Set Dht_io_set
Reset Dht_put
Waitms 25
Set Dht_put
Waitus 40
Reset Dht_io_set
Waitus 40
If Dht_get = 1 Then
H = 1
Exit Sub
End If
Waitus 80
If Dht_get = 0 Then
H = 2
Exit Sub
End If
While Dht_get = 1 : Wend
Do
While Dht_get = 0 : Wend
Waitus 30
If Dht_get = 1 Then
Sensor_data = Sensor_data + "1"
While Dht_get = 1 : Wend
Else
Sensor_data = Sensor_data + "0"
End If
Incr Count
Loop Until Count = 40
Set Dht_io_set
Set Dht_put
Tmp_str8 = Left(sensor_data , 8)
H = Binval(tmp_str8)
Tmp_str8 = Mid(sensor_data , 17 , 8)
T = Binval(tmp_str8)
Tmp_str8 = Right(sensor_data , 8)
Crc = Binval(tmp_str8)
Mybyte = T + H
If Mybyte <> Crc Then
H = 3
End If
End Sub
Setting:
Do
Upperline
Lcd "SET BATAS"
Lowerline
Lcd "Suhu= " ; Nilai ; " "
If Pbup = 0 Then
Waitms 200
Incr Nilai
End If
If Pbdown = 0 Then
Waitms 200
Decr Nilai
End If
If Pbok = 0 Then
Waitms 200
Cls
Wait 1
Goto Utama
End If
Loop
$crystal = 12000000
$baud = 9600
'--------------------------
Config Lcdpin = Pin , Rs = Portd.7 , E = Portb.1 , Db4 = Portb.2
Config Lcdpin = Pin , Db5 = Portb.3 , Db6 = Portb.4 , Db7 = Portb.5
Config Lcd = 16 * 2
Cursor Off
Cls
'led
Ddrc.4 = 1
Ddrc.5 = 1
'buzzer
Ddrd.6 = 1
'pushbutton
Ddrd.4 = 0
Ddrd.3 = 0
Ddrd.2 = 0
Ddrd.5 = 0
'aktif low pushbutton
Portd.4 = 1
Portd.3 = 1
Portd.2 = 1
Portd.5 = 1
Pbset Alias Pind.4
Pbdown Alias Pind.3
Pbup Alias Pind.2
Pbok Alias Pind.5
Declare Sub Get_th(t As Byte , H As Byte)
Config Serialin = Buffered , Size = 128
Config Serialout = Buffered , Size = 128
Dht_put Alias Portb.0
Dht_get Alias Pinb.0
Dht_io_set Alias Ddrb.0
Dim T As Byte
Dim H As Byte
Dim Crc As Byte
Dim Mybyte As Byte
Dim Sensor_data As String * 40
Dim Tmp_str8 As String * 8
Dim Count As Byte
Enable Interrupts
Set Dht_io_set
Set Dht_put
Dim Nilai As Integer
Portc.4 = 0
Portc.5 = 0
Portd.6 = 1
Utama:
Do
Waitms 1500
Call Get_th(t , H)
Upperline
Lcd "SUHU: " ; T ; " C "
Lowerline
Lcd "BATAS: " ; Nilai ; " C "
If Pbset = 0 Then
Waitms 200
Cls
Wait 1
Goto Setting
End If
If Nilai > 0 And T > Nilai Then
Portc.4 = 0
Portc.5 = 1
Portd.6 = 0
Print "bahaya"
End If
If Nilai > 0 And T <= Nilai Then
Portc.4 = 1
Portc.5 = 0
Portd.6 = 1
End If
Loop
Sub Get_th(t As Byte , H As Byte)
Count = 0
Sensor_data = ""
Set Dht_io_set
Reset Dht_put
Waitms 25
Set Dht_put
Waitus 40
Reset Dht_io_set
Waitus 40
If Dht_get = 1 Then
H = 1
Exit Sub
End If
Waitus 80
If Dht_get = 0 Then
H = 2
Exit Sub
End If
While Dht_get = 1 : Wend
Do
While Dht_get = 0 : Wend
Waitus 30
If Dht_get = 1 Then
Sensor_data = Sensor_data + "1"
While Dht_get = 1 : Wend
Else
Sensor_data = Sensor_data + "0"
End If
Incr Count
Loop Until Count = 40
Set Dht_io_set
Set Dht_put
Tmp_str8 = Left(sensor_data , 8)
H = Binval(tmp_str8)
Tmp_str8 = Mid(sensor_data , 17 , 8)
T = Binval(tmp_str8)
Tmp_str8 = Right(sensor_data , 8)
Crc = Binval(tmp_str8)
Mybyte = T + H
If Mybyte <> Crc Then
H = 3
End If
End Sub
Setting:
Do
Upperline
Lcd "SET BATAS"
Lowerline
Lcd "Suhu= " ; Nilai ; " "
If Pbup = 0 Then
Waitms 200
Incr Nilai
End If
If Pbdown = 0 Then
Waitms 200
Decr Nilai
End If
If Pbok = 0 Then
Waitms 200
Cls
Wait 1
Goto Utama
End If
Loop
d.VIDEO HASILNYA
No comments:
Post a Comment