Lampiran 1
Listing program dari seluruh sistem .
/*****************************************************
This program was produced by the CodeWizardAVR V2.04.9 Evaluation Automatic Program Generator
© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com
Project : Version :
Date : 11/04/2016
Author : Freeware, for evaluation and non-commercial use only
Company : Comments:
Chip type : ATmega8 Program type : Application AVR Core Clock frequency: 4,000000 MHz Memory model : Small
External RAM size : 0 Data Stack size : 256
#include <mega8.h> #include <stdio.h> #include <delay.h>
unsigned int Level;
void Read_Sensor(void) //rutin baca sensor ping { PORTB.1 = 1; // timing the return pulse
TCCR1B=0x00; // stop timer
Level = TCNT1; // save timer value to variable h
if ( Level < 1000 ) {Level = (Level*10)/25;} //utk menghilangkan efek penggenapan
if ( Level >= 1000) {Level = (Level/25)*10;} }
// Input/Output Ports initialization // Port B initialization
PORTB=0x01; DDRB=0x02;
// Port C initialization PORTC=0x30;
DDRC=0x00;
// Port D initialization PORTD=0x00;
DDRD=0x80;
// USART initialization // USART Baud Rate: 9600 UCSRA=0x00;
UCSRB=0x18; UCSRC=0x86; UBRRH=0x00; UBRRL=0x19;
{ Read_Sensor();
printf("%i",Level);
delay_ms(1000); //tunda 10 mili detik
if ( Level < 100) {PORTD.7 = 1;delay_ms(500);PORTD.7 = 0;}
} }
Lampiran 2
Listing program visual basic untuk menampilkan grafik level air dan alarm pada PC
Dim Yd1(0 To 10000), j, Level As Integer Dim TIMES(0 To 1000) As String
Dim f As String
Dim oXL As Excel.Application
Private Declare Function sndPlaySound Lib "Winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uflags As Long) As Long
Private Const snd_sync = &H0 Private Const snd_Async = &H1 Private Const snd_loop = &H8
Private Sub A_Click()
sndPlaySound vbNullString, snd_Async End Sub
Timer1.Enabled = False
Set oXL = New Excel.Application Set oxlbook = oXL.Workbooks.Add
FileName = "C:\Data\" + Text4 + ".xls"
oxlbook.Worksheets(1).Range("A1") = " Time "
oxlbook.Worksheets(1).Range("B1") = " Level sungai (cm) "
oxlbook.SaveAs FileName
For i = 2 To j
oxlbook.Worksheets(1).Range("A" & i) = TIMES(i) oxlbook.Worksheets(1).Range("B" & i) = Yd1(i) Next i
On Error GoTo 1
oxlbook.SaveAs FileName oxlbook.Close
1:
End Sub
Private Sub Command2_Click() Timer1.Enabled = True
End Sub
Private Sub Command4_Click()
sndPlaySound vbNullString, snd_Async Unload Me
End Sub
Private Sub Form_Load() MSComm1.PortOpen = True End Sub
Private Sub Timer1_Timer() x = MSComm1.Input
If x <> "" Then Picture1.Height = 6600 - Picture1.Top
End If
If Level > 40 Then
End If
End Sub
Private Sub Timer2_Timer() Text3 = Time
If Level > 0 Then Yd1(j) = Level TIMES(j) = Text3
Lampiran 3 Gambar Alat
1. Sensor HC-SR04 5. Buzzer
2. Modul RS485 6. Tabung Air
3. Kabel Penghubung
7. Rangkaiaan
4. Adaptor
Lampiran 4
L
PB 6 (XTAL1/TOSC1) PB 7 (XTAL2/TOSC2) PD 5 (T1)
PD 6 (AIN0) PD 7 (AIN1)
PB 0 (IC P1)