Translate

Membuat Alat Monitor FLOW dan Tekanan Udara via WIFI Ethernet Webserver dan Interface Delphi 7 datalogger

Membuat Alat Monitor FLOW dan Tekanan Udara via WIFI Ethernet Webserver dan Interface Delphi 7 datalogger ARDUINO


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang berfungsi untuk memonitor flow dan tekanan udara menggunakan sensor water flow sensor dan MPX5700 DP. alat ini bisa dimonitor menggunakan LCD 16x2 dan WIFI, jadi bisa menggunakan komputer atau handphone untuk memonitornya. yang terkahir yaitu alat ini terdapat interface Delphi 7 untuk datalogger atau penyimpanan data secara realtime. untuk lebih jelasnya berikut adalah komponen dan programnya.




a. Arduino Uno 





b. Flow Sensor




c. Sensor Tekanan Udara MPX5700 DP




d. Router



 
e. Lcd 16x2 + I2C







f. Program Arduino IDE

 #include "Wire.h"
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <Ethernet.h>

LiquidCrystal_I2C lcd(0x3F, 16,2);

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,99);

EthernetServer server(80);

int x;
float v;
float kpa;

int xx;
float vx;
float kpax;

byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 2;
byte sensorInterruptx = 1;  // 0 = digital pin 2
byte sensorPinx       = 3;

float calibrationFactor = 4.5;

volatile byte pulseCount;

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

unsigned long oldTime;


float calibrationFactorx = 4.5;

volatile byte pulseCountx;

unsigned int fracx;
float flowRatex;
unsigned int flowMilliLitresx;
float totalMilliLitresx;

unsigned long oldTimex;



String readString;

void setup() {
  lcd.begin();
  lcd.clear();
  lcd.noCursor();

   Serial.begin(9600);
   while (!Serial) {
  }

  Ethernet.begin(mac, ip);
  server.begin();
  //Serial.print("server is at ");
  //Serial.println(Ethernet.localIP());
 
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

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

  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

}

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: ");        
    Serial.print(totalMilliLitres);
    Serial.println("mL");
*/

    pulseCount = 0;
 
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  }
 
 
 
    if((millis() - oldTimex) > 1000)
  {

    detachInterrupt(sensorInterruptx);
    flowRatex = ((1000.0 / (millis() - oldTimex)) * pulseCountx) / calibrationFactorx;
    oldTimex = millis();
    flowMilliLitresx = (flowRatex / 60) * 1000;
    totalMilliLitresx += flowMilliLitresx;

/*   
    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: ");        
    Serial.print(totalMilliLitres);
    Serial.println("mL");
*/

    pulseCountx = 0;
 
    attachInterrupt(sensorInterruptx, pulseCounterx, FALLING);
  }



  x = analogRead(A0);
  v = x*(5.0/1023.0);
  kpa = ((v/5.0)-0.04)/0.0012858;
 
  xx = analogRead(A1);
  vx = xx*(5.0/1023.0);
  kpax = ((vx/5.0)-0.04)/0.0012858;

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

  if(kpax < 0){
  kpax = 0;
  }
 
  lcd.setCursor(0, 0);
  lcd.print("Kpa=");
  lcd.print(kpa);
  lcd.print("/");
  lcd.print(kpax);
  lcd.print("         ");
 
  lcd.setCursor(0, 1);
  lcd.print("ml/s=");
  lcd.print(flowMilliLitres);
  lcd.print(" / ");
  lcd.print(flowMilliLitresx);
  lcd.print("        ");
 
  Serial.print(kpa),Serial.println('a');
  Serial.print(kpax),Serial.println('b');
  Serial.print(flowMilliLitres),Serial.println('c');
  Serial.print(flowMilliLitresx),Serial.println('d');
 
  delay(1000);


   EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
     if (readString.length() < 100) {

          //store characters to string
          readString += c;
          //Serial.print(c);
        }
        if (c == '\n' && currentLineIsBlank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println("Refresh: 1");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println(" ");
          client.println("<title> Monitor Flow Dan Pressure </title> ");   
          client.println("<body bgcolor = #000000>");   
          client.println("<center>");
            client.println("<font color = yellow><center><h1>Monitor Flow dan Pressure</h1></center><br></font>");
            client.println("<font color = #FFFFFF>");
            client.println("<h2>");
            client.println("Pressure 1 = ");
            client.print(kpa);
            client.println("<br />");
            client.println("Pressure 2 = ");
            client.print(kpax);
            client.println("<br />");
            client.println("Flow 1 = ");
            client.print(flowMilliLitres);
            client.println("<br />");
            client.println("Flow 2 = ");
            client.print(flowMilliLitresx);
            client.println("<br />");
            client.println("</h2>");    
          client.println("</font>");

          client.println("</center>");
          client.println("</body>");
          client.println("</html>");
          
          break;     
        }  
        if (c == '\n') {
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    delay(1);
    client.stop();
    Serial.println("client disonnected");
  }

}


void pulseCounter()
{
  pulseCount++;
}

void pulseCounterx()
{
  pulseCountx++;
}






g. 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;
    GroupBox2: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    Label7: TLabel;
    Label8: TLabel;
    BitBtn1: TBitBtn;
    Timer2: TTimer;
    Timer3: TTimer;
    Edit3: TEdit;
    Edit4: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    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;
Edit3.Color:=clwhite;
Edit4.Color:=clwhite;
edit1.text:='';
edit2.text:='';
edit3.text:='';
edit4.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:\result.txt');
  Append(F);
  Write(F,'Flow1=',Edit1.Text);
  Write(F,' m/s  ');
  Write(F,'Flow2=',Edit2.Text);
  Write(F,' m/s  ');
  Write(F,'Press1=',Edit3.Text);
  Write(F,' kpa  ');
  Write(F,'Press2=',Edit4.Text);
  WriteLn(F,' kpa  ');
  CloseFile(F);
end;

procedure TForm1.Timer3Timer(Sender: TObject);
var satu,dua,tiga,empat,lima,enam:double;
    rin,kin,vin,din,lin,hin:string;
    jumlahdata:integer;

begin
  form1.Caption:=inttostr(jumlahdata);

  hin:=memo1.Lines[memo1.Lines.count-6];
  lin:=memo1.Lines[memo1.Lines.count-5];
  din:=memo1.Lines[memo1.Lines.count-4];
  vin:=memo1.Lines[memo1.Lines.count-3];
  rin:=memo1.Lines[memo1.Lines.count-2];
  kin:=memo1.Lines[memo1.Lines.count-1];

  if rightstr(din,1)= 'a' then
     begin
     edit1.Text:=leftstr(hin,length(hin)-1);
     end;
  if rightstr(vin,1)='b' then
     begin
     edit2.Text:=leftstr(lin,length(lin)-1);
     end;
  if rightstr(rin,1)='c' then
     begin
     edit3.Text:=leftstr(din,length(din)-1);
     end;
  if rightstr(kin,1)='d' then
     begin
     edit4.Text:=leftstr(vin,length(vin)-1);
     end;
  if rightstr(kin,1)='e' then
     begin
     //edit5.Text:=leftstr(lin,length(vin)-1);
     end;
  if rightstr(kin,1)='f' then
     begin
     //edit6.Text:=leftstr(hin,length(vin)-1);
     end;


end;

end.
 





h. VIDEO HASILNYA







No comments:

Post a Comment