Translate

Membuat Alat Monitor PH Cairan Menggunakan ARDUINO dan Interface Grafik Delphi 7

Membuat Alat Monitor PH Cairan Menggunakan ARDUINO dan Interface Grafik Delphi 7


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk mengetahui PH suatu cairan, alat ini menggunakan mikrokontroller ARDUINO dan sensor yang dipakai adalah sensor PH module yang sudah include sensor suhu DS18b20. pada alat ini terdapat dua buah tombol untuk kalibrasi. alat ini menggunakan ADC ekseternal 12 bit sehingga range sensor akan lebih besar. untuk kalibrator digunakan buffer PH 4, PH 7 dan PH 10. untuk lebih jelasnya berikut adalah skema dan programnya. untuk cara kalibrasi sensor PH berikut link-nya.
 




a. Arduino UNO





b. Sensor PH + Sensor Suhu DS18B20






c. Modul ADc 12 bit ADS1015







d. Program Arduino IDE

#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include <LiquidCrystal.h>
#include <OneWire.h>

OneWire  ds(10);  // on pin 10 (a 4.7K resistor is necessary)

LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
Adafruit_ADS1115 ads1115;

int kal7x;
int kal10x;
float volt0, sensorph, offsetph, ph1, ph2, selisih7, selisih10;


void setup(void)
{
 
  pinMode(2,INPUT);
  digitalWrite(2,HIGH);
  pinMode(3,INPUT);
  digitalWrite(3,HIGH);
 
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.noCursor();
 
  ads1115.begin();
  ads1115.setGain(GAIN_ONE); 
 
}

void loop(void)
{

  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
 
  if ( !ds.search(addr)) {
    ds.reset_search();
    delay(250);
    return;
  }
 

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
 
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
 
  present = ds.reset();
  ds.select(addr);   
  ds.write(0xBE);         // Read Scratchpad

  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  }

  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
 
  celsius = (float)raw / 16.0;
 // fahrenheit = celsius * 1.8 + 32.0;
  
  int16_t adc0, adc1, adc2; // input ADC

  adc0 = ads1115.readADC_SingleEnded(0);
  volt0 = (adc0 * 0.125);

  ph1 = (((volt0/1000.0) - 4.4645) / -0.2063);
 
  if((ph1 >= 6.0)&&(ph1 <= 8.0)){
  ph1 = selisih7 + ph1;
  lcd.setCursor(11, 0);
  lcd.print(selisih7);
  }
 
  if((ph1 >= 9.0)&&(ph1 <= 11.0)){
  ph1 = selisih10 + ph1; 
  lcd.setCursor(11, 1);
  lcd.print(selisih10); 
  }
 
  lcd.setCursor(0, 0);
  lcd.print("PH= ");
  lcd.print(ph1); 
   
  lcd.setCursor(0, 1);
  lcd.print("T= ");
  lcd.print(celsius);

  kal7x = digitalRead(2);
  kal10x = digitalRead(3);

  if(kal7x == 0){
  delay(200); 
  selisih7 = 7 - ph1;     
  }
 
  if(kal10x == 0){
  delay(200);
  selisih10 = 10 - ph1; 
  } 
 
  Serial.print(ph1),Serial.println ('a');
  Serial.print(celsius),Serial.println ('b');

  delay(1000);
 
}





e. Program Delphi 7 Interface



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, 'PH  : ',Edit1.Text);
  WriteLn(F, 'Suhu: ',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