Translate

Monitor Kecepatan Aliran Air / Udara (Air Flow Speed Meter / Water Flow Speed Meter)

Monitor Kecepatan Aliran Air / Udara (Air Flow Speed Meter / Water Flow Speed Meter)


             Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat untuk monitor kecepatan aliran udara atau air dengan menggunakan sensor water flow. alat ini menggunakan interface lcd 16x2 dan arduino nano sebagai mikrokontrollernya. untuk lebih jelasnya berikut adalah program dan komponennya.




a. Arduino Nano




b. Sensor Water Flow 




c. LCD + I2C






d. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2); 

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;

int btok = 3;
int btup = 4;
int btdown = 5;
int btset = 6;

int btokx,btupx,btdownx,btsetx;

int led1 = 7;
int led2 = 8;
float nilaiset;

void setup()
{

pinMode(btok,INPUT_PULLUP);;  
pinMode(btset,INPUT_PULLUP);;  
pinMode(btup,INPUT_PULLUP);;  
pinMode(btdown,INPUT_PULLUP);;  

pinMode(led1,OUTPUT);;  
pinMode(led2,OUTPUT);;  
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);

lcd.begin();   
lcd.noCursor();
lcd.clear();

 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)    // Only process counters once per second
  {

    detachInterrupt(sensorInterrupt);
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    oldTime = millis();
    flowMilliLitres = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres;
      
    // Print the flow rate for this second in litres / minute
    lcd.setCursor(0,0);
    lcd.print("S: ");
    lcd.print(int(flowRate));  // Print the integer part of the variable
    lcd.print(".");             // Print the decimal point
    // Determine the fractional part. The 10 multiplier gives us 1 decimal place.
    frac = (flowRate - int(flowRate)) * 10;
    lcd.print(frac, DEC) ;      // Print the fractional part of the variable
    lcd.print(" L/min    ");
    // Print the number of litres flowed in this second
    //Serial.print("  Current Liquid Flowing: ");             // Output separator
    //Serial.print(flowMilliLitres);
    //Serial.print("mL/Sec");

    // Print the cumulative total of litres flowed since starting
    //Serial.print("  Output Liquid Quantity: ");             // Output separator
    //Serial.print(totalMilliLitres);
    //Serial.println("mL");

    // Reset the pulse counter so we can start incrementing again
    pulseCount = 0;
   
    // Enable the interrupt again now that we've finished sending output
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  }
  
  
  if(flowRate < nilaiset){
  digitalWrite(led1,LOW);
  digitalWrite(led2,HIGH);
  }
  
  if(flowRate > nilaiset){
  digitalWrite(led1,HIGH);
  digitalWrite(led2,LOW);
  }
  
  if(flowRate < 0){
   flowRate = 0;
  }
  
  if(frac < 0){
   frac = 0;
  }


btsetx = digitalRead(btset);

if(btsetx == 0){
delay(1000);
lcd.clear();
setting();
}

lcd.setCursor(0,1);
lcd.print("SET= ");
lcd.print(nilaiset);   
   
}


void pulseCounter()
{
  pulseCount++;
}


void setting(){

btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);

lcd.setCursor(0,0);
lcd.print("Set Nilai: ");
lcd.setCursor(0,1);    
lcd.print(nilaiset);
lcd.print("      ");

if(btupx == 0){
delay(1000);  
nilaiset = nilaiset + 0.5;
}

if(btdownx == 0){
delay(1000);
nilaiset = nilaiset - 0.5;
}  
  
if(nilaiset < 0){
nilaiset = 0;
}
  
if(btokx == 0){
delay(1000);
lcd.clear();
return;
}

setting();
}




e. VIDEO HASILNYA







No comments:

Post a Comment