CCCPaste

**Flow Data** rev_01

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: **Flow Data**
	- Source Code NOT compiled for: Arduino Uno
	- Source Code created on: 2025-02-12 15:00:52

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Utilize the YF-S201 flow sensor to measure liquid */
	/* flow, with real-time readings */
/****** END SYSTEM REQUIREMENTS *****/

/* START CODE */

/****** DEFINITION OF LIBRARIES *****/
#include     // https://github.com/hafidhh/FlowSensor-Arduino
#include  // Include the necessary libraries

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t Caudalimetro_YF_S201_OUT_PIN_D2 = 2; // Corrected pin name to use underscores

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Create an instance of the FlowSensor class
FlowSensor flowSensor(1, Caudalimetro_YF_S201_OUT_PIN_D2); // Assuming type 1 for YF-S201

void setup(void)
{
    // put your setup code here, to run once:
    pinMode(Caudalimetro_YF_S201_OUT_PIN_D2, INPUT);
    
    // Initialize the serial monitor
    Serial.begin(9600); // This line should be inside the setup function

    // Initialize the flow sensor
    flowSensor.begin(countPulses); // Pass the function to count pulses
}

// Function to count pulses from the flow sensor
void countPulses()
{
    flowSensor.count(); // Increment pulse count
}

void loop(void)
{
    // put your main code here, to run repeatedly:
    
    // Read flow rate and volume
    flowSensor.read(); // Read the sensor data

    // Print flow rate and volume to the serial monitor
    Serial.print("Flow Rate (L/min): ");
    Serial.println(flowSensor.getFlowRate_m()); // Get flow rate in liters per minute
    Serial.print("Total Volume (L): ");
    Serial.println(flowSensor.getVolume()); // Get total volume in liters

    // Add a delay to prevent spamming the serial monitor
    delay(1000); // This line is compatible
}

/* END CODE */