Translate

Arduino Timbangan Digital dan Water Flow Interface Grafik Delphi 7

Arduino Timbangan Digital dan Water Flow Interface Grafik Delphi 7


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang berfungsi sebagai pengukur berat atau timbangan digital dan juga alat ini dapat mengukur flow aliran air dengan menggunakan sensor water flow. Arduino yang digunakan adalah arduino uno sebagai pemprosesan data. interface yang digunakan adalah software Delphi 7. untuk lebih jelasnya berikut adalah program dan daftar komponenya.



a. Arduino Uno




b. Loadcell + HX711




c. Sensor Water Flow






d. Program Arduino IDE

#include <Wire.h>
#include "HX711.h"

// HX711.DOUT    - pin #8
// HX711.PD_SCK    - pin #9

HX711 scale(8, 9);        // parameter "gain" is ommited; the default value 128 is used by the library

float tera = 0;
float berat;
float fix;
byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 2;

float calibrationFactor = 4.5;

volatile byte pulseCount;

unsigned int frac;
float flowRate;
unsigned int flowMilliLitres;
float totalMilliLitres;

unsigned long oldTime;

float kalmasaa;
float kalflow;

void setup() {

  Serial.begin(9600);
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;

  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

  scale.set_scale(2280.f);                      // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();                        // reset the scale to 0

}

void loop() {

//  if((millis() - oldTime) > 1000) 
//  {

    detachInterrupt(sensorInterrupt);
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    oldTime = millis();
    flowMilliLitres = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres;
     
    unsigned int frac;
   
    //Serial.print("Flow rate: ");
    //Serial.print(int(flowRate));  /
    //Serial.print(".");            
    frac = (flowRate - int(flowRate)) * 10;
    //Serial.print(frac, DEC) ;     
    //Serial.print("L/min");
    //Serial.print("  Current Liquid Flowing: ");   
    //Serial.print(flowMilliLitres);
    //Serial.print("mL/Sec");

    //Serial.print("  Output Liquid Quantity: ");

    //kalibrasi
    kalmassa = (berat - 3.1115) / 1.1535;
    kalflow = (totalMilliLitres - 3.1115) / 1.1535;
    
    //Serial.print(kalmassa),Serial.println("a");   
    Serial.print(berat),Serial.println("a"); 
    //Serial.print(kalflow),Serial.println("b");
    Serial.print(totalMilliLitres),Serial.println("b");
    
    pulseCount = 0;
   
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
 // }
   
   berat = scale.get_units(10) * -1;
   //fix = ((berat + 1.523) / 0.223) - tera ;

 if (fix < 0 ) {
  fix = 0;
  }

  //scale.power_down();                   
  //delay(500);
  //scale.power_up();
  delay(1000);

}

void pulseCounter()
{
  pulseCount++;
}




e. Program Interface 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;
    Chart2: TChart;
    Series1: TFastLineSeries;
    Series2: TFastLineSeries;
    Label5: TLabel;
    Timer2: TTimer;
    Timer3: TTimer;
    
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Memo1Change(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(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.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.Memo1Change(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 =10000 then
//     begin
//     Series1.Clear;
//     Series2.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);
     Series1.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);
     Series2.Add(kulit,'',clgreen) ;
     shape2.Brush.Color:=clred;
     end;


end;

procedure TForm1.Edit1Change(Sender: TObject);
var ruang:double;
begin
ruang:=strtofloat(edit1.text);


end;

procedure TForm1.Edit2Change(Sender: TObject);
var kulit:double;
begin
kulit:=strtofloat(edit2.text);

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 x:double;
    y:double;

begin
x:=strtofloat(edit1.text);
y:=strtofloat(edit2.text);


end;

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


end.





f. VIDEO HASILNYA









No comments:

Post a Comment