Translate

Monitor Tekanan Pressure dan Flow Air Fitur PID Sebagai Stabilisator Aliran Air

Monitor Tekanan Pressure  dan Flow Air Fitur PID Sebagai Stabilisator Aliran Air


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tekanan air dan flow aliran air yang mana jumlahnya tiap-tiap sensor berjumlah 4 buah. alat  ini memiliki fitur yaitu pid yang digunakan untuk menstabilkan aliran air sehingga aliran bisa dikendalikan dengan pemantauan melalui sensor tekanan. 



a. Gambar Sistem Keseluruhan




b. Program Arduno IDE

#include "Wire.h"
#include <Servo.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);

Servo myservo;
//=====================================================
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;

//====================================================

byte sensorInterrupt1 = 1;  // 1 = digital pin 3
byte sensorPin1       = 3;
float calibrationFactor1 = 4.5;
volatile byte pulseCount1; 
unsigned int frac1;
float flowRate1;
unsigned int flowMilliLitres1;
float totalMilliLitres1;
unsigned long oldTime1;

//======================================================

byte sensorInterrupt2 = 4;  // 4 = digital pin 19
byte sensorPin2       = 19;
float calibrationFactor2 = 4.5;
volatile byte pulseCount2; 
unsigned int frac2;
float flowRate2;
unsigned int flowMilliLitres2;
float totalMilliLitres2;
unsigned long oldTime2;

//==========================================================
byte sensorInterrupt3 = 5;  // 5 = digital pin 18
byte sensorPin3       = 18;
float calibrationFactor3 = 4.5;
volatile byte pulseCount3; 
unsigned int frac3;
float flowRate3;
unsigned int flowMilliLitres3;
float totalMilliLitres3;
unsigned long oldTime3;

int dataadc1;
int x1;
float v1;
float kpa1;

int dataadc2;
int x2;
float v2;
float kpa2;

int dataadc3;
int x3;
float v3;
float kpa3;

int dataadc4;
int x4;
float v4;
float kpa4;

float kp = 1.15;
float ki = 0.67;
float kd = 0.15;

float p,i,d,pid;
float error,errorx,sumerr;
float sp = 10.0; //setpoint tekanan 10 psi

float pressure_pascal1;
float pressure_bar1;

float pressure_pascal2;
float pressure_bar2;

float pressure_pascal3;
float pressure_bar3;

float pressure_pascal4;
float pressure_bar4;

float psi1;
float psi2;
float psi3;
float psi4;
float rasio;
int relay = 4;
int buzzer = 5;

//pwm servo buka = 0 dan tutup maksimal = 60 

void setup() {

  pinMode(relay, OUTPUT);
  pinMode(buzzer, OUTPUT);
  digitalWrite(relay,LOW);
  digitalWrite(buzzer,HIGH);
  
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

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

  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

  pinMode(sensorPin1, INPUT);
  digitalWrite(sensorPin1, HIGH);

  pulseCount1        = 0;
  flowRate1          = 0.0;
  flowMilliLitres1   = 0;
  totalMilliLitres1  = 0;
  oldTime1           = 0;

  attachInterrupt(sensorInterrupt1, pulseCounter1, FALLING);
   
  pinMode(sensorPin2, INPUT);
  digitalWrite(sensorPin2, HIGH);

  pulseCount2        = 0;
  flowRate2          = 0.0;
  flowMilliLitres2   = 0;
  totalMilliLitres2  = 0;
  oldTime2           = 0;

  attachInterrupt(sensorInterrupt2, pulseCounter2, FALLING);
 
  pinMode(sensorPin3, INPUT);
  digitalWrite(sensorPin3, HIGH);

  pulseCount3        = 0;
  flowRate3         = 0.0;
  flowMilliLitres3   = 0;
  totalMilliLitres3  = 0;
  oldTime3           = 0;

  attachInterrupt(sensorInterrupt3, pulseCounter3, FALLING);
 
  Serial.begin(9600); 
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  myservo.attach(9);
  myservo.write(100);
}


void loop() {
 
if((millis() - oldTime) > 1000)    // Only process counters once per second
  {
    detachInterrupt(sensorInterrupt);
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    oldTime = millis();
    flowMilliLitres = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres;
    pulseCount = 0;
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  }

    if((millis() - oldTime1) > 1000)    // Only process counters once per second
  {
    detachInterrupt(sensorInterrupt1);
    flowRate1 = ((1000.0 / (millis() - oldTime1)) * pulseCount1) / calibrationFactor1;
    oldTime1 = millis();
    flowMilliLitres1 = (flowRate1 / 60) * 1000;
    totalMilliLitres1 += flowMilliLitres1;
    pulseCount1 = 0;
    attachInterrupt(sensorInterrupt1, pulseCounter1, FALLING);
  }
 
 if((millis() - oldTime2) > 1000)    // Only process counters once per second
  {

    detachInterrupt(sensorInterrupt2);
    flowRate2 = ((1000.0 / (millis() - oldTime2)) * pulseCount2) / calibrationFactor2;
    oldTime2 = millis();
    flowMilliLitres2 = (flowRate2 / 60) * 1000;
    totalMilliLitres2 += flowMilliLitres2;
    pulseCount2 = 0;
    attachInterrupt(sensorInterrupt2, pulseCounter2, FALLING);
  }

   if((millis() - oldTime3) > 1000)    // Only process counters once per second
  {
    detachInterrupt(sensorInterrupt3);
    flowRate3 = ((1000.0 / (millis() - oldTime3)) * pulseCount3) / calibrationFactor3;
    oldTime3 = millis();
    flowMilliLitres3 = (flowRate3 / 60) * 1000;
    totalMilliLitres3 += flowMilliLitres3;
    pulseCount3 = 0;
    attachInterrupt(sensorInterrupt3, pulseCounter3, FALLING);
  }

rasio = (flowRate - flowRate1) / flowRate;
rasio = rasio * 100.0;

if(rasio >= 20){
  digitalWrite(relay,HIGH);
  digitalWrite(buzzer,LOW);  
}
else{
  digitalWrite(relay,LOW);
  digitalWrite(buzzer,HIGH);
}


  x1 = analogRead(A0);
  v1 = x1*(5.0/1023.0);
  psi1 = 250 * (v1/5.0);
  psi1 = psi1 - 25;

  x2 = analogRead(A1);
  v2 = x2*(5.0/1023.0);
  psi2 = 250 * (v2/5.0);
  psi2 = psi2 - 25;
     
  x3 = analogRead(A2);
  v3 = x3*(5.0/1023.0);
  psi3 = 250 * (v3/5.0);
  psi3 = psi3 - 25;
       
  x4 = analogRead(A3);
  v4 = x4*(5.0/1023.0);
  psi4 = 250 * (v4/5.0);
  psi4 = psi4 - 25;

if(psi1 < 0){
  psi1 = 0;
}
if(psi2 < 0){
  psi2 = 0;
}
if(psi3 < 0){
  psi3 = 0;
}
if(psi4 < 0){
  psi4 = 0;
}

  error = sp - psi2;
  p = error * kp;
  sumerr = error + errorx;
  i = ki * sumerr;
  d = kd * (error - errorx) ;
  pid = p + i + d;
  pid = 60 - pid;
  
  if(pid < 0){
  pid = 0;
  }
 
  if(pid > 60){
  pid = 60;
  }

  myservo.write(pid);
       
  lcd.setCursor(0,0);
  lcd.print("FP1=");
  lcd.print(flowRate,1);
  lcd.print("/");
  lcd.print(psi1,1);
  lcd.print(" ");
  lcd.print(rasio,1);
  lcd.print("%     ");
  
  lcd.setCursor(0,1);
  lcd.print("FP2=");
  lcd.print(flowRate1,1);
  lcd.print("/");
  lcd.print(psi2,1);
  lcd.print(" ");
  lcd.print(pid,1);
  lcd.print("      ");

  lcd.setCursor(0,2);
  lcd.print("FP3=");
  lcd.print(flowRate2,1);
  lcd.print("/");
  lcd.print(psi3,1);
  lcd.print("  ");
  
  lcd.setCursor(0,3);
  lcd.print("FP4=");
  lcd.print(flowRate3,1);
  lcd.print("/");
  lcd.print(psi4,1);
  lcd.print("  ");


errorx = error;
  
delay(200);
}


void pulseCounter()
{
  pulseCount++;
}

void pulseCounter1()
{
  pulseCount1++;
}

void pulseCounter2()
{
  pulseCount2++;
}

void pulseCounter3()
{
  pulseCount3++;
}




c. VIDEO HASILNYA





No comments:

Post a Comment