Translate

Membuat Alat Monitor Flow Air dan Suhu (Temperature) DS18B20 Menggunakan Android dan ARDUINO

Membuat Alat Monitor Flow Air dan Suhu (Temperature) DS18B20 Menggunakan Android dan ARDUINO


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat untuk monitoring flow air atau kecepatan air menggunakan flow sensor dan suhu menggunakan sensor DS18B20, alat ini akan mengirimkan 3 buah data ke HP Android kemudian akan menampilkannya di layar HP Android, data yang dikirimkan oleh Arduino ke Android adalah data Suhu / temperature, data sensor flow atau kecepatan aliran kemudian sudut servo sehingga pada tamplan akan tampil 3 buah data tersebut. untuk lebih jelasnya berikut adalah skema dan programnya.




a. Arduino UNO





b. Sensor Flow 





c. Sensor Suhu DS18B20






d. Motor Servo






e. Bluetooth HC-05






f. Program Arduino IDE

#include <OneWire.h>
#include <Servo.h>

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

byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 2;

float calibrationFactor = 4.5;

int buzzer = 3;
int suhu;
int derajat;

volatile byte pulseCount;

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

unsigned long oldTime;

Servo myservo; 

void setup(void) {
  myservo.attach(9);
  Serial.begin(9600);
  pinMode(sensorPin, INPUT);
  pinMode(buzzer,OUTPUT);
  digitalWrite(sensorPin, HIGH);
  digitalWrite(buzzer, HIGH);

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

  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

}

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;
  }

  for( i = 0; i < 8; i++) {

  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      return;
  }

  switch (addr[0]) {
    case 0x10:
      type_s = 1;
      break;
    case 0x28:
      type_s = 0;
      break;
    case 0x22:
      type_s = 0;
      break;
    default:
      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

  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) {
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    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

  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  suhu = celsius;
 
 
  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
    //Serial.print("Flow rate: ");
    //Serial.print(int(flowRate));  // Print the integer part of the variable
    //Serial.print(".");             // Print the decimal point
    // Determine the fractional part. The 10 multiplier gives us 1 decimal place.
    frac = (flowRate - int(flowRate)) * 10;
    //Serial.print(frac, DEC) ;      // Print the fractional part of the variable
    //Serial.print("L/min");
    // Print the number of litres flowed in this second
    //Serial.print("Flow: ");             // Output separator
    //Serial.print(flowMilliLitres);
    //Serial.println(" mL/Sec");

   // Serial.print("Hasil|");             // Output separator
   // Serial.print(suhu);
   // Serial.print("|");
   // Serial.print(flowMilliLitres);
   // Serial.print("|");
   // Serial.print(derajat);
   
    // 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);
  }
 
    Serial.print(derajat);
    Serial.print("|");       
    Serial.print(suhu);
    Serial.print("|");
    Serial.print(flowMilliLitres);
    Serial.print("|");

  
    delay(300);
   
if((suhu >= 0 )&&(suhu <= 27)){
myservo.write(70);
derajat = 45;
}
if((suhu > 27 )&&(suhu <= 40)){
myservo.write(100);
derajat = 60;
}
if((suhu > 40 )&&(suhu <= 60)){
myservo.write(150);
derajat = 90;
}

if(suhu >= 60){
 digitalWrite(buzzer,LOW);
}
if(suhu < 60){
 digitalWrite(buzzer,HIGH);
}

}



void pulseCounter()
{
  pulseCount++;
}




g. Untuk Mengirim dua saja menggunakan proram ini




h. Program Android








i. Gambar Hasilnya





j. VIDEO HASILNYA









No comments:

Post a Comment