Membaca Sensor Water Flow Dengan Arduino

Super Admin 24-11-2020 3,106 Tutorial

Membaca Sensor Water Flow Dengan Arduino

Berikut spesifikasi sensor yang saya gunakan untuk mengukur kecepatan air

Features:

  • Model: YF-S201
  • Sensor Type: Hall effect
  • Working Voltage: 5 to 18V DC (min tested working voltage 4.5V)
  • Max current draw: 15mA @ 5V
  • Output Type: 5V TTL
  • Working Flow Rate: 1 to 30 Liters/Minute
  • Working Temperature range: -25 to +80â„Æ’
  • Working Humidity Range: 35%-80% RH
  • Accuracy: ±10%
  • Maximum water pressure: 2.0 MPa
  • Output duty cycle: 50% +-10%
  • Output rise time: 0.04us
  • Output fall time: 0.18us
  • Flow rate pulse characteristics: Frequency (Hz) = 7.5 * Flow rate (L/min)
  • Pulses per Liter: 450
  • Durability: minimum 300,000 cycles
  • Cable length: 15cm
  • 1/2" nominal pipe connections, 0.78" outer diameter, 1/2" of thread
  • Size: 2.5" x 1.4" x 1.4"

Connection details:

  • Red wire : +5V
  • Black wire : GND
  • Yellow wire : PWM output.

Documents

YF-S201 Datasheet
Example Arduino Code

Contoh Source Code :

/*
YF� S201 Water Flow Sensor
Water Flow Sensor output processed to read in litres/hour
Adaptation Courtesy: www.hobbytronics.co.uk
*/
volatile int flow_frequency; // Measures flow sensor pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowsensor = 2; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interrupt function
{
   flow_frequency++;
}

void setup()
{
   pinMode(flowsensor, INPUT);
   digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
   Serial.begin(9600);
   attachInterrupt(0, flow, RISING); // Setup Interrupt
   sei(); // Enable interrupts
   currentTime = millis();
   cloopTime = currentTime;
}
void loop ()
{
   currentTime = millis();
   // Every second, calculate and print litres/hour
   if(currentTime >= (cloopTime + 1000))
   {
      cloopTime = currentTime; // Updates cloopTime
      // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
      l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
      flow_frequency = 0; // Reset Counter
      Serial.print(l_hour, DEC); // Print litres/hour
      Serial.println(" L/hour");
   }
}

Menggunakan LCD :

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int X;
int Y;
float TIME = 0;
float FREQUENCY = 0;
float WATER = 0;
float TOTAL = 0;
float LS = 0;
const int input = A0;
void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(“Water Flow Meter�);
  lcd.setCursor(0, 1);
  lcd.print(“* ***************�);
  delay(2000);
  pinMode(input, INPUT);
}
void loop() {
  X = pulseIn(input, HIGH);
  Y = pulseIn(input, LOW);
  TIME = X + Y;
  FREQUENCY = 1000000 / TIME;
  WATER = FREQUENCY / 7.5;
  LS = WATER / 60;
  if (FREQUENCY >= 0) {
    if (isinf(FREQUENCY)) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(“VOL. : 0.00�);
      lcd.setCursor(0, 1);
      lcd.print(“TOTAL :�);
      lcd.print(TOTAL);
      lcd.print(� L�);
    } else {
      TOTAL = TOTAL + LS;
      Serial.println(FREQUENCY);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(“VOL. : “);
      lcd.print(WATER);
      lcd.print(� L / M�);
      lcd.setCursor(0, 1);
      lcd.print(“TOTAL :�);
      lcd.print(TOTAL);
      lcd.print(� L�);
    }
  }
  delay(1000);
}

 

Top Post
Lowongan Kerja