Program pada Mikrokontroller
$regfile = "m8535.dat" $crystal = 8000000
$baud = 9600 Dim Ctr As Byte
Dim Dataword As Word Dim Command As Byte Dim Dis As String * 20 Dim Calc As Single Dim Calc2 As Single Dim Rhlinear As Single Dim Rhlintemp As Single Dim Tempc As Single Dim Tempf As Single
Deflcdchar 0 , 14 , 17 , 17 , 14 , 32 , 32 , 32 , 32 ' replace ? with number (0-7)
Dim Putrn As Integer Dim Hit As Integer 'Dim I As Integer
Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0
Config Lcd = 16 * 2
Config Timer0 = Counter , Edge = Rising Config Timer1 = Timer , Prescale = 1024 On Timer1 Label2
Const C1 = -4 'Konstanta untuk konversi data SHT-11 ke nilai
Const C2 = 0.0405 'nyata sebenarnya (rumus menurut datasheet)
Const C3 = -0.0000028 Const T1c = .01
Const T2 = .00008 Const T1f = .018
Sck Alias Portc.1 Dataout Alias Portc.0 Datain Alias Pinc.0 Redled Alias Portc.2
Declare Sub Calc_crc(byval X As Byte) Declare Sub Getit()
Ddrc = &B11111111 'mengaktifkan internal pullup
Config Pinc.0 = Output 'sck Config Pinc.1 = Output 'datain
'mereset komunikasi serial terlebih dahulu Set Dataout For Ctr = 1 To 12 Set Sck Waitus 2 Reset Sck Waitus 2 Next Ctr Enable Interrupts Enable Timer1 Start Timer1 Tcnt0 = 0 Hit = 0
Do 'prosedur penampilan suhu dan temperatur terus-menerus
Cls
Putrn = Tcnt0
Command = &B00000011 Z1(1) = 3
Call Getit 'Get the temperature, puts result in "dataword" for us
Tempf = T1f * Dataword Tempf = Tempf - 40
Tempc = T1c * Dataword 'get celcius for later calculations and for "the rest of the world"
Tempc = Tempc - 40
Print "Suhu = " ; Dis ; "C"
Locate 1 , 1 : Lcd "Suhu = " ; Dis ; " " ; Chr(0) ; "C" Wait 1
Command = &B00000101 Z1(1) = 5
Call Getit 'get the humidity
Calc = C2 * Dataword
Calc2 = Dataword * Dataword 'that "2" in the datasheet sure looked like a footnote for a couple days, nope it means "squared"!
Calc2 = C3 * Calc2 Calc = Calc + C1
Rhlinear = Calc + Calc2
'Dis = Fusing(rhlinear , "##.##")
'Print "Humidity adjusted for linear = " ; Dis Calc = T2 * Dataword
Calc = Calc + T1c Calc2 = Tempc - 25 Calc = Calc2 * Calc
Rhlintemp = Calc + Rhlinear
Dis = Fusing(rhlintemp , "##.##") Print "Humid:" ; Dis ; "%"
Locate 2 , 0 : Lcd "Hum = " ; Dis ; " %RH" Wait 1
Loop Label2: Cls
Lcd "Kec Angin:" ; Putrn ; " ptr" Print "Kec Angin : " ; Putrn ; " ptr" Wait 1 Hit = Hit + 1 If Hit = 8 Then Tcnt0 = 0 Hit = 0 For I = 0 To 10 Cls
Lcd "Kec Angin: " ; Putrn ; " rpm" Print "Kec Angin : " ; Putrn ; " rpm" Waitms 100
End If
Start Timer1 Return
Sub Getit()
Local Datavalue As Word Local Databyte As Byte
'start with "transmission start" Set Sck Reset Dataout Reset Sck Set Sck Set Dataout Reset Sck
'now send the command
Shiftout Dataout , Sck , Command , 1
Ddrd = &B11111101 'datain is now input
Config Pinc.0 = Input 'datain Set Sck 'click one more off
Reset Sck
Waitus 10 'no idea why, but it doesn't work without it!
Bitwait Pinc.0 , Reset 'wait for the chip to have data ready
Shiftin Datain , Sck , Databyte , 1 'get the MSB
Datavalue = Databyte Z1(2) = Databyte Ddrd = &B11111111
Config Pinc.0 = Output
Reset Dataout 'this is the tricky part- Lot's of hair pulling- have to tick the ack!
Set Sck Reset Sck
Ddrd = &B11111101 'datain is now input Config Pinc.0 = Input
Shiftin Datain , Sck , Databyte , 1 'get the LSB
Z1(3) = Databyte
Shift Datavalue , Left , 8
Datavalue = Datavalue Or Databyte 'don't tick the clock or ack
since we don't need the CRC value, leave it hanging!
Dataword = Datavalue Ddrd = &B11111111
Config Pinc.0 = Output Reset Dataout
Set Sck Reset Sck
Ddrd = &B11111101 'datain is now input
Config Pinc.0 = Input
Shiftin Datain , Sck , Databyte , 1
Ddrd = &B11111111
Config Pinc.0 = Output Set Dataout
Set Sck Reset Sck End Sub End
PEROGRAM VISUAL BASIC UNTUK TAMPILAN PC
Private Sub cmd_close_Click() Unload Me
End Sub
Private Sub cmd_start_Click() Timer2.Enabled = True
End Sub
Private Sub cmd_stop_Click() Timer2.Enabled = False
End Sub
Private Sub Form_Load() Frame1.BackColor = &HFFFFFF Timer2.Enabled = False Timer1.Enabled = True MSComm1.PortOpen = True MSComm1.DTREnable = True MSComm1.RTSEnable = True Adodc1.Refresh End Sub
Private Sub Label1_Change() If Label1.Caption <> "" Then Label2.Caption = Label1.Caption End If
End Sub
Private Sub Label2_Change() a = Left(Label2.Caption, 1) If a = "S" Then Label3.Caption = Label2.Caption End If If a = "H" Then Label4.Caption = Label2.Caption End If
If a = "K" Then
Label6.Caption = Label2.Caption End If
End Sub
Private Sub Label6_Change()
a = Left(Right(Label6.Caption, 3), 1) If a = "m" Then Label8.Caption = Left(Right(Label6.Caption, 7), 2) w = Val(Label8.Caption)/ 60 v = w * 0.04 * 0.2512 Label13 = v End If End Sub
Private Sub Timer1_Timer() a = MSComm1.Input
Label1.Caption = a Label5.Caption = Now End Sub
Private Sub Timer2_Timer() Adodc1.Recordset.AddNew Adodc1.Recordset.Fields("waktu").Value = Label5.Caption Adodc1.Recordset.Fields("suhu").Value = Left(Label3.Caption, 14) Adodc1.Recordset.Fields("kelembaban").Value = Left(Label4.Caption, 12) Adodc1.Recordset.Fields("kecepatan_angin").Value = Left(Label6.Caption, 16) Adodc1.Recordset.Update Adodc1.Refresh End Sub
Data Hasil Pengukuran yang dihasilkan dari Sistem dan BMKG
Table1 Waktu (11/26/2010 ) Suhu dari SHT (oC) Kelembaban dari SHT (%) Kec.angin dari sistem(m/s) Suhu dari BMKG(o C) Kelembaban dari BMKG(%) Kec.angin dari BMKG (m/s) 6:00 23.50 88.07 1.87 24.6 99 2 7:00 25.03 88.03 1.95 25.8 98.5 2 8:00 28.22 88.03 4.74 28.2 89.5 3 9:00 28.80 68.00 5.11 29.6 65.5 5 10:00 29.89 60.06 5.18 30.2 59 5 11:00 28.18 82.11 6.00 27.3 82 6 12:00 27.65 88.08 6.18 27.4 87.5 6 13:00 28.30 78.17 5.09 28 78.5 5 14:00 27.84 78.14 5.99 27.6 78.5 6 15:00 27.84 81.00 4.07 27.7 80 4 16:00 27.84 81.28 4.98 27.6 81 5 17:00 26.58 82.12 4.99 26.7 82 5 18:00 25.75 87.60 3.00 25.8 89 3 19:00 25.22 88.98 1.98 25.1 94 2 20:00 25.23 90.25 1.98 25.1 96.5 2 21:00 25.20 91.17 3.01 25.1 96.5 3 22:00 24.83 95.35 1.99 24.4 97 2 23:00 24.45 95.69 1.86 23.9 97.5 2 00:00 24.18 95.94 1.89 23.5 98.5 2 01:00 24.05 95.97 1.93 23.4 98.5 2 02:00 23.89 95.98 1.97 23 99 2 03:00 23.43 96.00 1.97 23.1 99 2 04:00 23.65 96. 1.90 23.2 99.5 2 05:00 23.89 96.23 1.20 23.2 99.5 1 06:00 23.5 96.28 2.02 23.4 99.5 2Data Hasil Pengukuran yang dihasilkan dari Sistem dan BMKG
Table1 Waktu (11/22/2010 ) Suhu dari SHT (oC) Kelembaban dari SHT (%) Kec.angin dari sistem (m/s) Suhu dari BMKG (oC) Kelembaban dari BMKG(%) Kec.angin dari BMKG(m/s) 23:00 26.50 82.88 3.17 25.6 84 3 00:00 26.03 83.03 3.15 24.7 87 3 1:00 25.22 85.37 3.15 24.3 91 3 2:00 24.80 88.00 2.0 23.7 94.5 2 3:00 24.59 88.26 2.41 23.5 96.5 2 4:00 24.18 88.43 1.25 23.2 98 1 5:00 24.65 88.48 2.00 23.4 98.5 2 6:00 25.30 88.49 2.23 24.1 98.5 2 7:00 27.84 85.20 2.24 27.8 93 2 8:00 28.84 73.12 2.30 29.6 67 2 9:00 28.89 73.01 3.11 29.9 64 3 10:00 28.90 68.96 4.88 29.9 65.5 5 11:00 31.14 67.52 5.43 30.5 64.5 6 12:00 31.68 66.98 5.40 30.8 62.5 6 13:00 32.23 67.25 5.48 31 63.5 6 14:00 30.10 70.17 5.49 29.9 68 6 15:00 28.83 73.35 5.25 27.5 73 6 16:00 28.45 75.69 5.11 26.3 79 5 17:00 24.18 82.94 4.89 25.5 83.5 5 18:00 24.05 83.76 2.65 24.8 89 3 19:00 23.89 86.43 1.00 24.5 93 1 20:00 23.43 88.18 1.89 24.8 95.5 2 21:00 24.65 88.37 1.89 25.1 96 2 22:00 25.89 86.59 2.25 25 94.5 3 23:00 23.5 88.38 2.25 24.8 96.5 2 0:00 23.67 88.30 2.28 24.9 96 2Pengujian Sistem Alat untuk Menentukan Kestabilan
Data yang di Ukur.
Pemilik : Ellis Naria Pakpahan
Nama Alat : Prototipe Stasiun Cuaca Mini Berbasis Mikrokontroller ATmega8535
Tanggal Pengukuran : 19 November 2010
Lokasi pengukuran : Lapangan BMKG Sampali Waktu (11/19/2010) suhu ('C) kelembaban (%) kec_angin (m/s) 9:35 28 76 0 9:40 28.82 76 0 9:45 28.82 68.5 0 9:50 28.8 71 0 9:55 28.8 68.5 0 10:00 29.5 68.5 0.03768 10:05 29.15 76.33 0.03768 10:10 29.15 76.21 0.03768 10:15 29.13 76.21 0.03768 10:20 29.15 76.2 0.03768 10:25 29.5 76.11 2.93066 10:30 29.9 76.18 2.93066 10:35 29.6 68.83 2.93066 10:40 28.6 68.75 2.93066 10:45 29.91 68.5 2.93066 10:50 30.64 68.56 3.34933 10:55 30.89 66.94 3.34933 11:05 31.25 66.78 3.34933 11:10 30.73 66.73 3.34933 11:15 30.64 66.71 3.34933 11:20 30.5 66.78 4.18666 11:25 30.5 66.65 4.18666 11:30 30.64 66.65 8.37333 11:35 30.64 66.68 8.37333 11:40 30.6 66.65 8.37333
Grafik Perbandingan dari Data dapat di lihat pada Gambar dibawah ini.
Hasil Pengukuran terhadap Waktu
0
10
20
30
40
50
60
70
80
90
9:
35
9:
45
9:
55
10:
05
10:
15
10:
25
10:
35
10:
45
10:
55
11:
10
11:
20
11:
30
11:
40
waktu
pe
nguk
ur
an
suhu('C) kelembaban (%) kec.angin (m/s)Gambar 1. Grafik dari hasil pengukuran untuk menentukan Kestabilan data.
Perbandingan Pengukuran Suhu terhadap waktu
(26/11/2010)
0
5
10
15
20
25
30
35
6:
00
8:
00
10:
00
12:
00
14:
00
16:
00
18:
00
20:
00
22:
00
0:
00
2:
00
4:
00
waktu
suhu(
'C
)
Suhu dariSHT('C) Suhu dari BMG('C)Gambar 2. Grafik Perbandingan Hasil Pengukuran Data Suhu antara SHT11
dengan Suhu dari BMG.
Perbandingan Pengukuran kelembaban terhadap waktu
(26/11/2010)
0
20
40
60
80
100
120
6:
00
8:
00
10
:00
12
:00
14
:00
16
:00
18
:00
20
:00
22
:00 0:
00
2:
00
4:
00
waktu
kel
em
b
ab
an
(
%
)
Kelembaban dari SHT(%) Kelembaban dari BMG(%)Gambar 3. Grafik Perbandingan Hasil Pengukuran Data Kelembaban antara
SHT11 dengan Kelembaban dari BMG.
Perbandingan Pengukuran Kec.Angin terhadap Waktu
(26/11/2010)
0 1 2 3 4 5 6 7 6:00 8:00 10:00 12:00 14:00 16:00 18:00 20:00 22:00 0:00 2:00 4:00 waktu K ec .A n g in (m /s ) Kec.Angin dari sistem alat (m/s) Kec.Angin dari Anemometer (m/s)Gambar 4. Grafik Perbandingan Hasil Pengukuran Data Kec.Angin antara
Fotodioda dengan Kec.Angin dari BMG.
SCK Da ta AT m eg a8 535