Example Code for Arduino-Liquid Flow Measurement

The article presents a comprehensive guide on measuring liquid flow using Arduino, featuring example code, hardware preparation, a wiring diagram, and a setup with a water flow sensor to print collected flow values.

Hardware Preparation

Software Preparation

Wiring Diagram

Connection

Sample Code

volatile double waterFlow;
void setup() {
  Serial.begin(9600);  //baudrate
  waterFlow = 0;
  attachInterrupt(1, pulse, RISING);  //DIGITAL Pin 3: Interrupt 0
}
void loop() {
  Serial.print("waterFlow:");
  Serial.print(waterFlow);
  Serial.println("   L");
  delay(500);
}

void pulse()   //measure the quantity of square wave
{
  waterFlow += 1.0 / 540.0; // 1L=540 pulses
}

Result

Print the collected water flow value.

Was this article helpful?

TOP