Translate

Membuat Alat Monitor Water Flow Meter / Flow rate dan Water Level / Jarak HC-srf04 Bascom AVR interface Delphi 7

Membuat Alat Monitor Water Flow Meter / Flow rate dan Water Level / Jarak HC-srf04 Bascom AVR interface Delphi 7


              Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk mengukur ketinggian air dan juga mengukur kecepatan aliran air menggunakan mikrokontroller, alat ini dapat menampilkan data di LCD dan interface grafik pada laptop / komputer dengan software DELPHI 7. untuk lebih jelasnya berikut adalah skema dan programnya.



a. Minimum System ATmega16




b. Sensor Jarak HC-SFR04




c. Sensor Water Flow / Flow Rate




d. PL232 Modul






e. Program Bascom AVR

$regfile = "m16def.dat"
$crystal = 12000000
$baud = 9600

'Konfigurasi LCD
Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.1 , Db4 = Portc.2
Config Lcdpin = Pin , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Lcd = 16 * 2

Config Timer0 = Timer , Prescale = 256

Cls
Cursor Off


Config Portb.2 = Output
Config Pinb.1 = Input

Declare Sub Cek_jarak

Dim Data_jarak As Word
Dim Data_jarak_olah As Word
Dim Data_jarak_fix As Word

Triger1 Alias Portb.2
Pecho1 Alias Pinb.1


Ch Alias Pind.2

Config Pind.2 = Output

Config Ch = Input

Config Int0 = Falling
Const Debouncetime = 1

Dim Wtime As Byte
Dim Encounter As Integer
Dim Q As Integer

Set Ch

On Int0 Getencoder

Cls

Wtime = 100
Encounter = 0

Enable Interrupts
Enable Int0




Mulai:
Cls
Cursor Off

Do
Call Cek_jarak
  Data_jarak = Data_jarak
  Data_jarak_olah = Data_jarak * 100
  Data_jarak_fix = Data_jarak_olah / 256


Upperline
Lcd "Jarak= " ; Data_jarak_fix ; " cm      "

 Q = Encounter * 60
 Q = Q / 8.1
 Q = Q * 1

 Set Portd.6
  Waitms Wtime
  Lowerline
  Lcd "Flow= " ; Q ; "                  "
  Reset Portd.6
  Waitms Wtime

Waitms 200

Print Q ; "a"
Print Data_jarak_fix ; "b"

Encounter = 0

Waitms 1000
Loop


Sub Cek_jarak:
Reset Triger1
Waitus 10
Set Triger1
Waitus 20
Reset Triger1

Tcnt0 = 0
Bitwait Pecho1 , Set
Start Timer0

Do
If Pecho1 = 0 Then
Data_jarak = Tcnt0
Stop Timer0
Exit Do
End If

If Tifr.0 = 1 Then
Stop Timer0
Tifr.0 = 1
Data_jarak = &HFF
Exit Do
End If
Loop
Stop Timer0
Waitms 15
End Sub



Getencoder:
  Waitms Debouncetime
  If Ch = 0 Then
     Incr Encounter
  End If
  Gifr = 64
Return

End





f. Program Delphi 7



unit TA;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,strutils, TeeProcs, TeEngine, Chart, CPort, mmsystem,
  Series, Buttons;

type
  TForm1 = class(TForm)
    ComPort1: TComPort;
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Chart1: TChart;
    Shape1: TShape;
    Shape2: TShape;
    GroupBox2: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    Label7: TLabel;
    Label8: TLabel;
    BitBtn1: TBitBtn;
    Series1: TFastLineSeries;
    Series2: TFastLineSeries;
    Chart2: TChart;
    Series3: TFastLineSeries;
    Chart3: TChart;
    Series4: TFastLineSeries;
    Timer2: TTimer;
    Timer3: TTimer;
    procedure ComPort1RxChar(Sender: TObject; Count: Integer);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Timer3Timer(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var buff:string;
begin
comport1.ReadStr(buff,count);
memo1.Text:=memo1.Text+buff;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
comport1.ShowSetupDialog;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Timer2.Enabled := True;
Timer3.Enabled := True;
if button2.Caption='Connect' then
   begin
   button2.Caption:='Disconnect';
   comport1.Open;
   end
else if button2.Caption='Disconnect' then
   begin
   button2.Caption:='Connect';
   comport1.Close;
   end;

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Edit1.Color:=clwhite;
Edit2.Color:=clwhite;
edit1.text:='';
edit2.text:='';
memo1.Text:='';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ThousandSeparator:=',';
DecimalSeparator:='.';
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
label7.Caption:='Date  '+ FormatdateTime('d/mm/yyyy',Date);
label8.Caption:='Time  '+ FormatDateTime('hh:nn:ss',Time);
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
var
  F: TextFile;
begin
  AssignFile(F, 'D:\record.txt');
  Append(F);
  WriteLn(F, '======================================');
  WriteLn(F, 'Tanggal = ',label7.Caption);
  WriteLn(F, 'Jam     = ',label8.Caption);
  WriteLn(F, '======================================');

  WriteLn(F, 'Flow  : ',Edit1.Text);
  WriteLn(F, 'Jarak: ',Edit2.Text);
  CloseFile(F);
end;

procedure TForm1.Timer3Timer(Sender: TObject);
var ruang,kulit:double;
    rin,kin:string;
    jumlahdata:integer;

begin
  shape1.Brush.Color:=clgreen;
  shape2.Brush.Color:=clgreen;
  jumlahdata:=chart1.GetMaxValuesCount;
  form1.Caption:=inttostr(jumlahdata);
  //if jumlahdata > 60 then
  //   begin
  //   chart1.Series[0].Clear;
  //   chart1.Series[1].Clear;
  //   Series3.Clear;
  //   Series4.Clear;
  //   end;

  rin:=memo1.Lines[memo1.Lines.count-2];
  kin:=memo1.Lines[memo1.Lines.count-1];

  if rightstr(rin,1)= 'a' then
     begin
     edit1.Text:=leftstr(rin,length(rin)-1);
     ruang:=strtofloat(edit1.text);
     chart1.Series[0].Add(ruang,'',clred) ;
     Series3.Add(ruang,'',clred) ;
     shape1.Brush.Color:=clred;
     end;
  if rightstr(kin,1)='b' then
     begin
     edit2.Text:=leftstr(kin,length(kin)-1);
     kulit:=strtofloat(edit2.text);
     chart1.Series[1].Add(kulit,'',clgreen) ;
     Series4.Add(kulit,'',clgreen) ;
     shape2.Brush.Color:=clgreen;
     end;


end;

end.





f. VIDEO HASILNYA










No comments:

Post a Comment